迁移Play Core Java/Kotlin库时遭遇元数据冲突错误求助
收到Google Play Console团队警告:应用targetSdkVersion升级到34+后,旧版PlayCore SDK会导致崩溃,需进行更新。按照官方迁移指南升级Play Core库、修改代码并更新导入后,构建时出现元数据冲突错误:
错误:
Attribute meta-data#com.google.android.play.core.assetpacks.versionCode@value value=(20202) from AndroidManifest.xml:54:13-34
is also present at [com.google.android.play:core:1.9.1] AndroidManifest.xml:17:85-106 value=(10901).
Suggestion: add 'tools:replace="android:value"' toelement at AndroidManifest.xml to override.
自身build.gradle中并未直接引入com.google.android.play:core:1.9.1,尝试在AndroidManifest.xml的<meta-data>元素添加tools:replace="android:value",且移除了com.google.android.play:core-ktx:1.10.3,但问题仍未解决。
附build.gradle代码参考
模块级build.gradle:
apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 34 defaultConfig { applicationId '' minSdkVersion 28 targetSdkVersion 34 multiDexEnabled true versionCode 00 versionName "" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.debug } } flavorDimensions "default" productFlavors { staging { applicationId '' } production { applicationId '' } } compileOptions { coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } buildFeatures { viewBinding true } lint { abortOnError false } } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.security:security-crypto:1.0.0' implementation 'com.google.android.gms:play-services-gcm:17.0.0' implementation 'com.google.android.material:material:1.6.0' implementation("com.google.android.play:asset-delivery:2.2.2"){ exclude group: 'com.google.android.play', module: 'core' } implementation("com.google.android.play:feature-delivery:2.1.0"){ exclude group: 'com.google.android.play', module: 'core' } implementation("com.google.android.play:review:2.0.1"){ exclude group: 'com.google.android.play', module: 'core' } implementation 'com.squareup.okhttp3:okhttp:4.9.3' implementation 'com.jakewharton.timber:timber:5.0.1' implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' implementation 'com.madgag.spongycastle:core:1.58.0.0' implementation 'com.mikhaellopez:circularprogressbar:3.0.3' implementation 'com.daimajia.swipelayout:library:1.2.0@aar' implementation 'com.afollestad.material-dialogs:core:0.9.6.0' // TODO Upgrade to com.afollestad.material-dialogs:core:2.0.0-alpha07 implementation 'ca.antonious:materialdaypicker:0.5.0' implementation 'no.nordicsemi.android.support.v18:scanner:1.6.0' implementation 'com.github.franmontiel:AttributionPresenter:1.0.1' implementation 'com.karumi:dexter:6.2.3' implementation 'me.zhanghai.android.materialprogressbar:library:1.6.1' implementation 'com.aurelhubert:ahbottomnavigation:2.3.4' implementation 'no.nordicsemi.android:dfu:2.0.3' implementation 'org.greenrobot:eventbus:3.3.1' implementation 'com.amplifyframework:core:1.35.5' implementation 'com.amplifyframework:aws-auth-cognito:1.35.5' implementation 'com.mixpanel.android:mixpanel-android:6.2.2' implementation 'com.bugsee:bugsee-android:2.1.3' implementation 'pub.devrel:easypermissions:3.0.0' implementation platform('com.google.firebase:firebase-bom:28.0.1') implementation 'com.google.firebase:firebase-analytics' implementation 'com.google.firebase:firebase-messaging' coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' testImplementation 'junit:junit:4.13.2' //androidTestImplementation 'androidx.annotation:annotation:1.1.0-rc01' androidTestImplementation 'androidx.test:runner:1.4.0' androidTestImplementation 'androidx.test:rules:1.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-intents:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0' implementation 'androidx.test.espresso:espresso-idling-resource:3.4.0' androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.4.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation("androidx.biometric:biometric:1.1.0") } apply plugin: 'com.google.gms.google-services' repositories { mavenCentral() }
根级build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext.kotlin_version = '1.5.21' repositories { google() mavenCentral() jcenter() maven { url "https://jitpack.io" } } dependencies { classpath 'com.android.tools.build:gradle:7.2.1' classpath 'com.google.gms:google-services:4.3.10' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() mavenCentral() jcenter() maven { url 'https://jitpack.io' } maven { url 'https://dl.bintray.com/amulyakhare/maven' } } } task clean(type: Delete) { delete rootProject.buildDir }
定位旧版依赖来源:执行Gradle命令查看依赖树,找出间接引入
com.google.android.play:core:1.9.1的依赖:# Mac/Linux ./gradlew app:dependencies # Windows gradlew.bat app:dependencies在输出中搜索
com.google.android.play:core:1.9.1,找到对应的父依赖后,直接在该依赖上添加exclude规则。全局排除旧版Play Core:如果不想逐个排查依赖,可在模块级build.gradle的
dependencies块上方添加全局排除规则,强制移除所有间接引入的旧版core库:configurations.all { exclude group: 'com.google.android.play', module: 'core' }正确配置Manifest的tools:replace:确保AndroidManifest.xml的根标签已引入tools命名空间,且meta-data元素正确添加替换规则:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="你的应用包名"> <application ...> <meta-data android:name="com.google.android.play.core.assetpacks.versionCode" android:value="20202" tools:replace="android:value" /> <!-- 其他组件 --> </application> </manifest>清理缓存并重构建:执行清理命令清除Gradle缓存,避免旧配置残留:
# Mac/Linux ./gradlew clean build # Windows gradlew.bat clean build统一Play Core组件版本:确保所有Play Core拆分库(asset-delivery、feature-delivery、review)使用兼容的最新版本,避免版本差异导致的冲突。
内容的提问来源于stack exchange,提问作者Atta ul Jalil

