skip to Main Content

I upgrade existing android project to API level 31. I use Java as the language. I changed the build.gradle

compileSdkVersion 31
defaultConfig {
    applicationId 'com.app.app'
    minSdkVersion 16
    targetSdkVersion 31
    versionCode 91
    versionName '4.0.1'
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}

But I couldn’t debug the app using an AVD or a real device. I am getting this error.

> Task :app:mergeProjectDexDebug
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
AGPBI: {"kind":"warning","text":"An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"}
An API level of 31 is not supported by this compiler. Please use an API level of 30 or earlier

I think I need to update the compiler, How can I do that?

2

Answers


  1. Try adding this to your build.gradle file:

    android {
      ...
      compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
      }
      kotlinOptions {
        jvmTarget = '1.8'
      }
    }
    
    Login or Signup to reply.
  2. It seems that D8 is not available for the gradle version you used.
    But change gradle version might be a big deal. Especially for maintaining old project.
    And it seems that D8 is used to reduce APK file size. And it’s just warning, not error.
    So, the reasonable action might be … ignore the message. 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search