数ヶ月ぶりにAndroid Studioでアプリのビルドを走らせたら大量にエラーが出て動かなかったので解決方法をメモ
エラーメッセージ詳細
実際のエラーメッセージは以下のような感じ。
Execution failed for task ':app:checkDebugAarMetadata'.
> Multiple task action failures occurred:
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.appcompat:appcompat:1.4.1.
AAR metadata file: C:\Users\■■■■\.gradle\caches\transforms-2\files-2.1\21c3ecf98e280316449ae27cb17f9a1a\appcompat-1.4.1\META-INF\com\android\build\gradle\aar-metadata.properties.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.appcompat:appcompat-resources:1.4.1.
AAR metadata file: C:\Users\■■■■\.gradle\caches\transforms-2\files-2.1\29eb1277873f8d6c55982bb6830f296b\jetified-appcompat-resources-1.4.1\META-INF\com\android\build\gradle\aar-metadata.properties.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.emoji2:emoji2-views-helper:1.0.0.
AAR metadata file: C:\Users\■■■■\.gradle\caches\transforms-2\files-2.1\3450f576bbbb5c124422a09a8929654b\jetified-emoji2-views-helper-1.0.0\META-INF\com\android\build\gradle\aar-metadata.properties.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.emoji2:emoji2:1.0.0.
AAR metadata file: C:\Users\■■■■\.gradle\caches\transforms-2\files-2.1\51c794e8d58f2add1b6e1035ee7c058d\jetified-emoji2-1.0.0\META-INF\com\android\build\gradle\aar-metadata.properties.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.core:core:1.7.0.
AAR metadata file: C:\Users\■■■■\.gradle\caches\transforms-2\files-2.1\9b4bbe17406ebdd5cecd894aeda4ed80\core-1.7.0\META-INF\com\android\build\gradle\aar-metadata.properties.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.lifecycle:lifecycle-process:2.4.0.
AAR metadata file: C:\Users\■■■■\.gradle\caches\transforms-2\files-2.1\e539e26c730ec8f29e3c4a27f918073b\jetified-lifecycle-process-2.4.0\META-INF\com\android\build\gradle\aar-metadata.properties.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.lifecycle:lifecycle-runtime:2.4.0.
AAR metadata file: C:\Users\■■■■\.gradle\caches\transforms-2\files-2.1\ff81fc826eef84982d02d149abc4bcd7\lifecycle-runtime-2.4.0\META-INF\com\android\build\gradle\aar-metadata.properties.
大量に出ているけど、基本的には同じ現象が複数の依存関係にあるAARに発生している模様。
抜き出して一個だけ確認してみる。
The minCompileSdk (31) specified in a
dependency's AAR metadata is greater than this module's compileSdkVersion (android-30).
雑に翻訳すると”依存関係の AAR メタデータで指定された minCompileSdk (31) が、このモジュールの compileSdkVersion (android-30) より大きい”との事なので、手っ取り早くこのモジュールのcompileSdkVersionを31にしてあげることにする。
build.gradlのcompileSdkVersionを31にする
build.gradl(:app)のcompileSdkVersionを31にする。
android {
compileSdkVersion 30 // これを31にする
buildToolsVersion "30.0.1"
defaultConfig {
applicationId "com.◆◆◆◆◆◆.test"
minSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
ここをこう。
compileSdkVersion 30→compileSdkVersion 31
これで保存してもう一度ビルドしたら。”BUILD SUCCESSFUL in 2s”でビルドが通って動いた。
自分のアプリのcompileSdkVersionを変えずに依存関係先のAARを変更したい場合は、dependenciesの依存関係先のAARのバージョンを落としてやればそれでも動く気がするが、めんどくさいので試していない。。。