20

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?

Lakpriya Senevirathna
  • 2,488
  • 2
  • 17
  • 35

2 Answers2

16

Try adding this to your build.gradle file:

android {
  ...
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
  kotlinOptions {
    jvmTarget = '1.8'
  }
}
hir0ak1
  • 199
  • 1
  • 7
  • 1
    For any one who faced this issue , you need to upgrade your gradle(graddle-wrapper-propertise) , in my case i upgrade from 6.7.1 to 6.9 – mazen amr Aug 22 '22 at 11:53
  • Nice. I found that someone had set the jvmtarget in three different build.gradle files to `JavaVersion.VERSION_1_8`. Resetting it to the numeric string seems to have resolved the issue. – Sinc Jan 25 '23 at 19:44
10

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. :)

Orange
  • 349
  • 3
  • 13