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
Try adding this to your build.gradle file:
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. 🙂