Required api level 26 unity ошибка

I’m trying to test a game on my Galaxy Note 9. It works with Unity Remote but I can’t get it to build to test it as an App. I’m getting this weird error «Required API level 26» when I try to build it.

I reinstalled Android Studio
Researched online
Checked Unity Android path
Messed with Player Settings to see if something was missed

View post on imgur.com

Unity should build the game.

I’m trying to test a game on my Galaxy Note 9. It works with Unity Remote but I can’t get it to build to test it as an App. I’m getting this weird error «Required API level 26» when I try to build it.

I reinstalled Android Studio
Researched online
Checked Unity Android path
Messed with Player Settings to see if something was missed

View post on imgur.com

Unity should build the game.

2 Answers

Go to Android Studio >SDK manager and update your SDK. It will go away.

I had the same problem. Restoring «Library» folder in project folder helped to resolve the issue.

Questions : Unity Android build error — required API level

2023-06-01T10:00:59+00:00 2023-06-01T10:00:59+00:00

685

I’m trying to test a game on my Galaxy Note 9. It works with Unity Remote but I can’t get it to build to test it as an App. I’m getting this weird error «Required API level 26» when I try to build it.

I reinstalled Android Studio
Researched online
Checked Unity Android path
Messed with Player Settings to see if something was missed

View post on imgur.com

Unity should build the game.

Total Answers 2

27

Answers 1 : of Unity Android build error — required API level

Go to Android Studio >SDK manager and update your SDK. It will go away.

2023-06-01T10:00:59+00:00 2023-06-01T10:00:59+00:00Answer Link

mRahman

3

Answers 2 : of Unity Android build error — required API level

I had the same problem. Restoring «Library» folder in project folder helped to resolve the issue.

2023-06-01T10:00:59+00:00 2023-06-01T10:00:59+00:00Answer Link

joy

The «Call requires API level 26 (current min is 25)» error in Android occurs when your code calls an API or method that requires a higher Android version than the minimum version specified in your project’s build.gradle file. This error is shown by the Android Studio lint tool to indicate that you are using APIs that are not available in older versions of Android, which can lead to compatibility issues for users running older versions of the operating system. To fix this error, you need to either increase the minimum API level of your project or modify your code to use alternatives for the unsupported APIs.

Method 1: Update minSdkVersion in build.gradle file

To fix the «Call requires API level 26 (current min is 25)» error in Android, you can update the minSdkVersion in the build.gradle file. Here are the steps to do it:

  1. Open your project in Android Studio.
  2. In the Project view, navigate to the app folder and open the build.gradle file.
  3. Find the line that sets the minSdkVersion. It should look like this:
  1. Change the value to 26:
  1. Sync your project with Gradle by clicking on the Sync Now button in the toolbar.

That’s it! Your app should now compile without the «Call requires API level 26» error.

Here’s an example of a build.gradle file with the updated minSdkVersion:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.myapp"
        minSdkVersion 26
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Note that you may also need to update the targetSdkVersion and compileSdkVersion to match the new minSdkVersion.

Method 2: Use Support Library APIs

To fix «Call requires API level 26 (current min is 25)» error in Android using «Use Support Library APIs», follow these steps:

Step 1: Add Support Library to Gradle

Add the following line to your app’s build.gradle file:

implementation 'com.android.support:support-v4:26.0.0'

Step 2: Import the Support Library

Add the following import statement to your Java file:

import android.support.v4.content.ContextCompat;

Step 3: Use Support Library APIs

Replace any code that requires API level 26 with the corresponding Support Library API. For example, to request permissions at runtime, use the following code:

if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
        != PackageManager.PERMISSION_GRANTED) {
    // Permission is not granted, request it
    ActivityCompat.requestPermissions(this,
            new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
            MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
}

Here, ContextCompat.checkSelfPermission() and ActivityCompat.requestPermissions() are Support Library APIs that can be used instead of the corresponding APIs that require API level 26.

Step 4: Build and Run

Build and run your app to verify that the error has been fixed.

That’s it! By using Support Library APIs, you can ensure that your app is compatible with older versions of Android while still using the latest features.

Method 3: Use Conditional Execution

To fix the «Call requires API level 26 (current min is 25)» error in Android using conditional execution, you can use the following code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    // Call the API that requires API level 26 or higher
} else {
    // Call the API that is compatible with API level 25 or lower
}

In this code, we are using the Build.VERSION.SDK_INT variable to check the current API level of the device. If the API level is 26 or higher, we can call the API that requires API level 26 or higher. Otherwise, we can call the API that is compatible with API level 25 or lower.

Here’s an example of how you can use this code to set the text color of a TextView based on the API level:

TextView textView = findViewById(R.id.text_view);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    textView.setTextColor(Color.RED);
} else {
    textView.setTextColor(getResources().getColor(R.color.colorAccent));
}

In this example, we are setting the text color of a TextView to red if the API level is 26 or higher, and to the accent color defined in the resources if the API level is 25 or lower.

Note that you can use this technique to conditionally execute any code that requires a specific API level. Just replace the API call in the first example with your own code, and adjust the conditions as necessary.

That’s it! With this technique, you can ensure that your app is compatible with a wide range of Android devices, while still taking advantage of the latest APIs when available.

Method 4: Replace Unsupported APIs with Alternatives

To fix the «Call requires API level 26 (current min is 25)» error in Android, you can use the «Replace Unsupported APIs with Alternatives» approach. This approach involves replacing the unsupported APIs with alternative methods that are available in the minimum API level of your app.

Here are the steps to implement this approach:

  1. Identify the unsupported API calls in your code.

  2. Look for alternative methods that are available in the minimum API level of your app. You can use the Android documentation to find alternative methods.

  3. Replace the unsupported API calls with the alternative methods.

  4. Test your app to ensure that it works as expected.

Here are some examples of how to replace unsupported APIs with alternatives:

Example 1: Replace the use of the getDrawable(int) method with the ContextCompat.getDrawable(Context, int) method.

// Unsupported API call
Drawable drawable = getResources().getDrawable(R.drawable.my_image);

// Alternative method
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.my_image);

Example 2: Replace the use of the setDisplayHomeAsUpEnabled(boolean) method with the ActionBar.setDisplayHomeAsUpEnabled(boolean) method.

// Unsupported API call
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

// Alternative method
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Example 3: Replace the use of the setTextAlignment(int) method with the ViewCompat.setTextAlignment(View, int) method.

// Unsupported API call
textView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);

// Alternative method
ViewCompat.setTextAlignment(textView, View.TEXT_ALIGNMENT_CENTER);

By following these steps and using alternative methods, you can fix the «Call requires API level 26 (current min is 25)» error in your Android app.

Solution 1

You need to use https://github.com/JakeWharton/ThreeTenABP to be able using LocalDateTime with Android API < 26.

Add the dependencies to your project (please follow the project README):

implementation 'com.jakewharton.threetenabp:threetenabp:1.2.1'

Then change your LocalDateTime import from:

import java.time.LocalDateTime;

to:

import org.threeten.bp.LocalDateTime;

Update:

The library mentioned above is no longer the best way as mentioned in JakeWharton/ThreeTenABP README:

Attention: Development on this library is winding down. Please consider switching to Android Gradle plugin 4.0, java.time.*, and its core library desugaring feature in the coming months.

To use LocalDateTime in older API levels, use the desugaring feature from Gradle plugin 4.0:
https://developer.android.com/studio/write/java8-support#library-desugaring

Solution 2

The best way to use LocalDateTime on a lower versions of Android is by desugaring (you must have Android Gradle plugin version 4.0 or higher). Just add the below lines to your app module gradle file:

enter image description here

Finally, add the ff. dependency to your dependencies block:

coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10'

Solution 3

You can use ThreeTenBP. But for android it is recommended to use Jake Wharton’s ThreeTenABP.

Why not use ThreeTenBP?

Similar to the problems with using Joda-Time on Android, the threetenbp uses a JAR resource for loading timezone information. This is an extremely inefficient mechanism on Android.

This library places the timezone information as a standard Android asset and provides a custom loader for parsing it efficiently.

Why not use Joda-Time?

Joda-Time has a very large API which brings with it a very large binary size and large method count. The creator of both JSR-310 and Joda-Time has also said that while Joda-Time isn’t broken, it does have design flaws.

If you are using Joda-Time already, there’s little reason to switch unless its size or method count is relevant to you. For new projects, however, this library offers the standard APIs in Java 8 as a much smaller package in not only binary size and method count, but also in API size.

These explanations came from Jake Wharton’s ThreeTenABP.

Solution 4

To use LocalDateTime on lower versions of Android is by desugaring (you must have Android Gradle plugin version 4.0 or higher) enable java8 and use the code below in your app.gradle

android {
    defaultConfig {
        // Required when setting minSdkVersion to 20 or lower
        multiDexEnabled = true
    }

    compileOptions {
        // Flag to enable support for the new language APIs
        coreLibraryDesugaringEnabled = true // <- this flag is required

        // Sets Java compatibility to Java 8
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    // For Kotlin projects
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {
    coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5") // <- this dependency is required
}

Supporting docs

Comments

  • I know this question may be duplicated but I didn’t find any answer for my problem, I’m using LocalDateTime in my Android app that requires API 26 and my device’s API is 25.

    What can I do? Your help will be very appreciated.

    • It is quite obvious that you can’t use newer features on older devices. You have to either implement this feature by yourself, or find a library that provides similar functionality

  • I just followed the link you gave me but the error is always there :(

Recents

Понравилась статья? Поделить с друзьями:
  • Require string битрикс ошибка
  • Require administrator privileges ошибка
  • Requesting shsh 3utools ошибка
  • Request timed out ошибка icmp 11010
  • Request mespilock failed ошибка