androidx.core:core:1.15.0-alpha01 依存関係によるビルドエラーの解決
問題の概要
Androidプロジェクトのビルド時に次のエラーが発生する場合があります:
log
Execution failed for task ':app:checkDebugAarMetadata'.
A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
An issue was found when checking AAR metadata:
1. Dependency 'androidx.core:core:1.15.0-alpha01' requires libraries and applications that
depend on it to compile against version 35 or later of the Android APIs.
:app is currently compiled against android-34.
Also, the maximum recommended compile SDK version for Android Gradle
plugin 8.1.1 is 34.
エラーの原因
- ライブラリの互換性問題:
androidx.core:core:1.15.0-alpha01
は Android API 35以上 でコンパイルする必要があります - プロジェクト設定の矛盾: プロジェクトの
compileSdkVersion
が 34 に設定されている(Android Gradle Plugin 8.1.1の推奨上限) - 解決策の試行失敗:
compileSdkVersion
を35に変更 →platforms;android-35
が見つからないエラー- 依存関係を
androidx.core:core:1.13.1
にダウングレード → エラーが解消しない
推奨解決策
方法1: 安定版ライブラリへのダウングレード (最優先推奨)
安定性重視の場合
alpha版ではなく安定版(stable)のライブラリを使用してください
app/build.gradle
ファイルを開くdependencies
ブロックを修正
gradle
dependencies {
// 変更前(問題の原因)
// implementation("androidx.core:core-ktx:1.15.0")
// 変更後(安定版を使用)
implementation("androidx.core:core-ktx:1.13.1")
}
Android Studio新規プロジェクトテンプレートの場合
gradle
dependencies {
// 変更前
// implementation(libs.androidx.core.ktx)
// 変更後
implementation(libs.androidx.core.ktx.v1131)
}
補足事項
- AndroidX Core公式リリースノート から安定版を選択
core
とcore-ktx
のバージョンを一致させる
方法2: compileSdkVersion のアップグレード (API 35環境がある場合)
前提条件
Android SDK Managerで Android 15 (API 35) がインストールされている必要があります
app/build.gradle
を開くandroid
ブロックを修正:
gradle
android {
namespace = "com.example.app"
compileSdk = 35 // 34から変更
}
build.gradle
ファイルのAndroid Gradle Pluginバージョンを最新化:
gradle
plugins {
// Android Gradle Plugin 8.1.1 →
id 'com.android.application' version '8.4.0' apply false
}
根本原因の特定と追加対策
依存関係の強制指定 (一時的対策)
特定ライブラリのバージョンを強制的に上書き:
gradle
// app/build.gradle 最上部に追加
configurations.all {
resolutionStrategy {
force "androidx.core:core:1.13.1"
force "androidx.core:core-ktx:1.13.1"
}
}
サードパーティライブラリの問題診断
依存関係ツリーの調査
問題のライブラリを依存しているモジュールを特定:
bash
./gradlew app:dependencyInsight \
--configuration compileClasspath \
--dependency androidx.core:core
不安定な依存関係の回避
:app
から +
を使った動的バージョン指定を排除:
gradle
dependencies {
// 非推奨: プリリリース版が混入するリスク
// implementation 'com.example.library:+'
// 推奨: 固定バージョンを指定
implementation 'com.example.library:1.2.0'
}
よくある失敗事例と注意点
非推奨の回避策
gradle
// 警告: Google Play投稿が不可
targetSdk = 32 // minSdk要件を満たせない可能性
// 警告: プレビューSDKは不安定
compileSdkPreview "VanillaIceCream" // API 35プレビュー
ハイブリッド環境(React Native等)での対策
- パッケージマネージャで問題ライブラリを特定:
bash
npm list react-native-screen-brightness
- 代替モジュールに置換:
bash
npm uninstall @adrianso/react-native-device-brightness
npm install react-native-brightness-override
環境確認ポイント
- Android Studio → SDK Manager でAPI 35がインストール済みか確認
- File > Project Structure でCompile/Target SDKを再チェック
ベストプラクティス
- アルファ版依存の回避:
alpha
,beta
,rc
タグが付いたライブラリは安定期で導入
- バージョン整合性チェック:gradle
// build.gradle (トップレベル) dependencyUpdates { checkForGradleUpdate = true outputFormatter = "plain" }
- 漸進的アップグレード:
compileSdk
→targetSdk
→ 依存ライブラリの順で更新