Android 11 应用崩溃,显示“您应用的 AndroidManifest.xml 中的元数据标签值不正确。期望值为 12451000,但发现值为 4323000”。

8
我的应用在 Android 11 设备上崩溃,并显示以下错误消息:"The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 12451000 but found 4323000"。我已经意识到这样的问题并已经在清单文件中定义了正确的值,如下所示:
 <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

如果我遵循google_play_services_version,我可以找到期望的值。
<integer name="google_play_services_version">12451000</integer>

借助Firebase分析功能,我确认这只发生在Android 11设备上。 受影响的终端用户设备

从各种SO帖子中,我尝试了以下方法:

1- 将所有使用的Play服务和Firebase依赖项更新为最新可用版本。

2- 使用工具:替换为构建清理过程,在元数据标签中如下设置,适用于应用程序模块和wear模块:

<meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version"
        tools:replace="android:value" />

3- 检查所有使用的第三方库/SDK的清单文件,查找 @integer/google_play_services_version,但所有文件都被重定向到预期值,即12451000。

以下是 build.gradle 文件: A- build.gradle {:app}-

apply from: '../release-config.gradle'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'android-release-plugin'
apply plugin: 'testfairy'
apply from: '../sonar.gradle'
apply from: '../jacoco.gradle'
// Add the Firebase Crashlytics plugin.
apply plugin: 'com.google.firebase.crashlytics'

android.testOptions {
 unitTests.all {
    jacoco {
        includeNoLocationClasses = true
    }
}
unitTests.returnDefaultValues = true
}
tasks.sonarqube.dependsOn jacocoTestReport


android {
compileSdkVersion 30
buildToolsVersion '29.0.2'
ndkVersion "16.1.4479499"

kapt {
    javacOptions {
        option("-Adagger.gradle.incremental")
        option("-Adagger.formatGeneratedSource=disabled")
    }
}

dexOptions {
    javaMaxHeapSize "4g"
}

defaultConfig {
    applicationId "com.xx”
    minSdkVersion 23
    targetSdkVersion 30
    multiDexEnabled true
    testInstrumentationRunner 
    "androidx.test.runner.AndroidJUnitRunner"

    buildConfigField "String", "SERVER_BASE", ‘”————“’
    buildConfigField "String", "LOCUSLABS_ACCOUNT_ID", ‘”——“’
    buildConfigField "String", "GCM_SENDER_ID", ‘”———“’
    buildConfigField "String", "GRAB_ID", ‘”———“’
    buildConfigField "String", "GCT_CONVERSION_ID", ‘”———“’
    buildConfigField "String", "GCT_LABEL", ‘”———“’
    buildConfigField "String", "GCT_VALUE", ‘”——“’
}

signingConfigs {

}

buildTypes {
    debug {
        versionNameSuffix "(Debuggable)"
        debuggable true
        zipAlignEnabled true
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
        'proguard-rules.pro'
    }
    release {
        shrinkResources true
        signingConfig signingConfigs.release
        zipAlignEnabled true
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
      'proguard-rules.pro'
        debuggable false
    }
}

flavorDimensions 'environment'

productFlavors {
    dev {
        applicationIdSuffix ".dev"
        buildConfigField "String", "SERVER_BASE", ‘”——————‘

        def internalVersion = 
         releaseConfig.getAppVersion().internalVersion
        resValue "string", "app_name", "xx (Test) ${internalVersion}"
    }

    stage {
        applicationIdSuffix ".stage"
        buildConfigField "String", "SERVER_BASE", ‘”—————“’—

        def internalVersion = 
        releaseConfig.getAppVersion().internalVersion
        resValue "string", "app_name", "xx (Stage) ${internalVersion}"
    }

    prod {
        buildConfigField "String", "SERVER_BASE", ‘”———“’——
        buildConfigField "String", "LOCUSLABS_ACCOUNT_ID", ‘”———“’
        buildConfigField "String", "GCM_SENDER_ID", ‘”——“’
        buildConfigField "String", "GRAB_ID", ‘”——“’
        buildConfigField "String", "GCT_CONVERSION_ID", ‘”———“’
        buildConfigField "String", "GCT_LABEL", ‘”———“’
    }
}

 packagingOptions {
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/ASL2.0'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/**rxjava.properties**'
}

lintOptions {
    abortOnError false
}

testfairyConfig {
    apiKey “———————“
}

testOptions {
    unitTests.returnDefaultValues = true
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

androidExtensions {
    experimental = true
}
}

def powermock_version = "2.0.2"
def daggerVersion = "2.16"
def leak_canary_version = "2.0-beta-1"

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':common')
implementation('com.facebook.android:facebook-android-sdk:5.15.3') {
    exclude group: 'com.android.support'
}
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation "androidx.constraintlayout:constraintlayout:2.0.2"
implementation "com.google.android.gms:play-services-base:17.4.0"
implementation "com.google.android.gms:play-services-location:17.1.0"
implementation "com.google.android.gms:play-services-maps:17.0.0"
implementation "com.google.android.gms:play-services-vision:20.1.2"
implementation "com.google.android.gms:play-services-wearable:17.0.0"
implementation 'androidx.core:core:1.3.2'
implementation 'com.romandanylyk:pageindicatorview:1.0.3'
implementation 'com.getbase:floatingactionbutton:1.10.1'
implementation 'com.wdullaer:materialdatetimepicker:4.2.3'

// need by grab sdk
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
implementation('com.squareup.retrofit2:retrofit:2.5.0') {
    // exclude Retrofit’s OkHttp peer-dependency module and define 
   your own module import
    exclude module: 'okhttp'
}
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'

implementation 'com.google.zxing:core:3.3.3'
implementation 'io.reactivex.rxjava2:rxjava:2.1.10'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'com.airbnb.android:lottie:2.5.5'
implementation 'me.grantland:autofittextview:0.2.1'


implementation 'org.greenrobot:eventbus:3.1.1'
implementation 'com.github.bumptech.glide:glide:4.11.0'
kapt 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'org.kamranzafar:jtar:2.2'
implementation 'org.tukaani:xz:1.5'
implementation 'io.reactivex:rxjava:1.3.0'
implementation 'io.reactivex:rxandroid:1.2.1'
implementation(name: 'locuslabs-android-sdk-2.3.10', ext: 'aar') {
    transitive = true
}
 implementation 'com.facebook.soloader:soloader:0.9.0'
implementation 'com.facebook.litho:litho-core:0.38.0'
implementation 'com.facebook.litho:litho-widget:0.38.0'
compileOnly 'com.facebook.litho:litho-annotations:0.38.0'
kapt 'com.facebook.litho:litho-processor:0.38.0'

// Firebase Dependencies
implementation "com.google.firebase:firebase-messaging:20.3.0"
// Add the Firebase Crashlytics SDK.
implementation 'com.google.firebase:firebase-crashlytics:17.2.2'
// Add the Firebase SDK for Google Analytics
implementation 'com.google.firebase:firebase-analytics:17.6.0'
implementation "com.google.firebase:firebase-core:17.5.1"

// Grab Dependencies
implementation(name: 'grab-framework-1.1.33', ext: 'aar')
implementation 'com.braintreepayments.api:braintree:2.16.0'
implementation 'com.android.volley:volley:1.1.1'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
implementation 'de.hdodenhof:circleimageview:2.0.0'
implementation 'org.kamranzafar:jtar:2.2'
implementation group: 'com.googlecode.libphonenumber', name: 
'libphonenumber', version: '8.4.1'
implementation 'io.card:android-sdk:5.5.1'
api 'com.wunderlist:sliding-layer:1.2.5'

// Background Process
implementation 'com.evernote:android-job:1.4.2'

// Dagger
implementation "com.google.dagger:dagger-android:$daggerVersion"
implementation "com.google.dagger:dagger-android-support:$daggerVersion"
kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
kapt "com.google.dagger:dagger-compiler:$daggerVersion"

// Paging
implementation 'androidx.paging:paging-runtime:2.1.2'

// Lifecycle
implementation "androidx.lifecycle:lifecycle-runtime:2.2.0"
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
kapt "androidx.lifecycle:lifecycle-compiler:2.2.0"

// Utils
implementation 'com.jakewharton.timber:timber:4.7.1'

//For updating styles attributes dynamically
implementation 'com.airbnb.android:paris:1.7.1'

// A memory leak detection library.
debugImplementation "com.squareup.leakcanary:leakcanary-android:${leak_canary_version}"
implementation "com.squareup.leakcanary:leakcanary-object-watcher-android:${leak_canary_version}"
implementation 'com.intuit.sdp:sdp-android:1.0.6'

wearApp project(':wearable')

//Test
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.23.0'

testImplementation "org.powermock:powermock-module-junit4:${powermock_version}"
testImplementation "org.powermock:powermock-module-junit4-rule:${powermock_version}"
testImplementation "org.powermock:powermock-api-mockito2:${powermock_version}"
testImplementation "org.powermock:powermock-classloading-xstream:${powermock_version}"

androidTestImplementation('androidx.test.espresso:espresso-core:3.3.0') {
    exclude group: 'com.google.code.findbugs'
    exclude group: 'com.android.support', module: 'support-annotations'
}

androidTestImplementation('androidx.test:runner:1.3.0') {
    exclude group: 'com.android.support', module: 'support-annotations'
}
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation ("com.github.tomeees:scrollpicker:1.7.4")

 }

 apply plugin: 'com.google.gms.google-services'

B- 顶层 build.gradle 文件:

buildscript {
ext.kotlin_version = '1.3.72'

repositories {       
    maven { url 'https://plugins.gradle.org/m2/' }
    maven { url "http://www.bugsense.com/gradle/" }
    mavenLocal()
    jcenter()
    google()
    }

    dependencies {
    classpath 'com.android.tools.build:gradle:4.0.2'
    classpath 'com.dminc.gradle:android-release-plugin:1.1.0.6'
    classpath 'com.testfairy.plugins.gradle:testfairy:2.0'
    classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.2'
    classpath 'com.google.gms:google-services:4.3.4'
    classpath 'com.google.firebase:firebase-crashlytics-gradle:2.3.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

    }

     allprojects {
     repositories {
     flatDir { dirs 'libs' }
     mavenLocal()
     mavenCentral()
     google()
     }
     }

我正在从我的启动屏幕(luncher活动)检查Play服务的可用性。我甚至尝试使用try-catch捕获抛出的异常,并成功地捕获到它,但应用程序仍然崩溃:

    public static int checkPlayServices(Context activity) {
     int retValue;

    try {
        int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(activity);
        Timber.tag(TAG).d(  "This device is supported with api version%s",
                                                            GoogleApiAvailability.getInstance().getClientVersion(activity));

        if (resultCode != ConnectionResult.SUCCESS) {
            if (GoogleApiAvailability.getInstance().isUserResolvableError(resultCode)) {
                retValue = PLAY_STORE_RESOLVABLE_ERROR;
                Timber.tag(TAG).d( "This device is supported but can be resolved.");
            } else {
                Timber.tag(TAG).d(  "This device is not supported and cannot be resolved.");
                retValue = PLAY_STORE_UN_SUPPORT;
            }
        } else {
            retValue = PLAY_STORE_AVAILABLE;
        }
    } catch (java.lang.IllegalStateException e) {
        Timber.tag(TAG).d( "This device Throws Illegal state Exception. Probably caused by google_play_services_version");
        Timber.tag(TAG).e( e.getMessage());
        retValue = PLAY_STORE_VERSION_ERROR;
    } catch (java.lang.Exception e) {
        Timber.tag(TAG).d(  "This device Throws Exception. Exact Reason is unknown");
        Timber.tag(TAG).e(  e.getMessage());
        retValue = PLAY_STORE_ERROR;
    }
    return retValue;
}

我已经能够捕获异常,但应用仍然会崩溃,这让我想到可能是其他SDK的依赖关系导致了此异常。我检查了所有第三方SDK,并发现另外两个SDK(Facebook和Braintree支付)也在检查Google Play服务。

_ 我已删除这两个SDK,但仍然出现崩溃。

注意:此崩溃仅发生在所有版本的Android 11设备/模拟器上。

现在我没有尝试的选项了。任何线索都将非常有帮助。

提前感谢。


我也遇到了同样的问题。你找到任何解决办法了吗? - Himanshu
@Himanshu 还没有。 - Adarsh Yadav
这个问题出现在哪种类型的应用程序中,调试版还是发布版? - Harkal
@Harkal 两种类型。 - Adarsh Yadav
1
我也遇到了问题,发布后分析 APK 后得到正确的值。 - Himanshu
显示剩余3条评论
3个回答

2

问题已经得到解决。

只需改变 meta 标签的顺序。版本标签应始终排在第一位。

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="@string/google_api_key"
            tools:replace="android:value" />

尝试了,但没有运气。 - Adarsh Yadav

1

是的!我找到了解决方案。 问题出在库文件上:

implementation "com.google.firebase:firebase-core:17.5.1"

只需要替换为
implementation 'com.google.firebase:firebase-core:16.0.3'

以上库加载了“地下室库”,最终我们有两个“地下室”库。 第一个由“play services”库加载,第二个由“firebase-core”加载。

更多信息请点击以下网址: 库com.google.android.gms:play-services-basement被各种其他库请求在[[15.0.1,15.0.1]],但解析为11.8.0

以及这个

https://github.com/evollu/react-native-fcm/issues/1026

如果这个答案没有帮助到您,那么请阅读有关Gradle和强制使用位于'com.google.firebase:firebase-core:16.0.3' 之内的库的内容,如下所示:
implementation ("com.google.firebase:firebase-core:16.0.3") {
        force = true
    }

注意: "force" 方法已经过时,您需要使用新的功能


听起来像是一个解决方案。我在一些日志中看到了“地下室图书馆”。我一定会尝试一下,并很快更新给你。谢谢。 - Adarsh Yadav
@AdarshYadav 是的,在修复之前,我阅读了更多关于Google Sensei崩溃的信息,但它们并没有帮助我。最终,我找到了上面的链接并进行了修复,所以如果我的解决方案有效,请标记为解决方案。 谢谢! - Rustam

1
如果您已经放置了标签,那么大多数情况下的答案在于使用兼容的库版本组合和更新弃用方法。
您在build.gradle中提到了以下内容:

implementation('com.facebook.android:facebook-android-sdk:5.15.3')

我在使用Android 11及以上版本的Facebook SDK时遇到了一个可能的原因,即使用已弃用的方法activateApp会导致上述问题。

请将方法AppEventsLogger.activateApp(this);更新为:

AppEventsLogger.activateApp(getApplication());

请告诉我们它是否对您有用。

你是说如果我改变activateApp的调用,就可以解决Play服务崩溃的问题吗?我问这个问题是因为我在Crashlytics中看到了这个崩溃,但我无法在我的设备上重现它,所以我必须进行更改,将其部署到生产环境中并查看是否有效。 - Vitor Ramos
1
是的,对我来说进行那个更改是值得的。 - Sahil
我已经进行了修改,它将在接下来的几天投入生产,我会在这里更新评论。 - Vitor Ramos

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接