【问题标题】:Android gradle build failed with an exception when include firebase and gms service包含 firebase 和 gms 服务时,Android gradle 构建失败并出现异常
【发布时间】:2019-09-18 08:05:56
【问题描述】:

我刚刚创建了一个空的 android 项目,同时包含了项目所需的依赖项,只有当我添加 com.google.firebasecom.google.android.gms 时才会出现错误,它会在下面生成错误。

/Users/macbookair/Desktop/ANDROID/APPTEST/app/src/main/AndroidManifest.xml:22:18-91 错误:属性 application@appComponentFactory 值=(android.support.v4.app.CoreComponentFactory)来自 [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 也出现在 [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 值=(androidx.core.app.CoreComponentFactory)。建议:加 'tools:replace="android:appComponentFactory"' 到元素 在 AndroidManifest.xml:5:5-21:19 处覆盖。

请任何人帮助我,我已经尝试了很长时间来修复此错误。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.fexample.android.appz"
        minSdkVersion 18
        targetSdkVersion 28
        versionCode 2
        versionName "2.0"
        testInstrumentationRunner "android.support.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
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation 'org.apache.httpcomponents:httpcore:4.4.10'
    implementation 'com.squareup.okhttp3:okhttp:3.13.1'
    implementation 'com.facebook.android:facebook-login:4.41.0'

     //If I uncomment the below line it will trigger error
    //implementation 'com.google.android.gms:play-services-safetynet:17.0.0'
    //implementation 'com.google.android.gms:play-services-auth:17.0.0'
    //implementation 'com.google.firebase:firebase-core:17.2.0'
    //implementation 'com.google.firebase:firebase-messaging:20.0.0'

}
android {
    useLibrary 'org.apache.http.legacy'
}
apply plugin: 'com.google.gms.google-services'

android { sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/public'] } } }

从下面的截图来看,implementation 'com.android.support:appcompat-v7:28.0.0' 也有一个错误,但是当我构建 apk 时它创建成功,我认为不好。

使用 groupId com.android.support 和 androidx.* 的依赖项不能 合而为一 IdeMavenCoordinates{myGroupId='com.android.support', myArtifactId='support-fragment', myVersion='28.0.0', myPacking='aar', myClassifier='null'} 和 IdeMavenCoordinates{myGroupId='androidx.swiperefreshlayout', myArtifactId='swiperefreshlayout', myVersion='1.0.0', myPacking='aar', myClassifier='null'}

【问题讨论】:

    标签: java android android-gradle-plugin google-cloud-messaging


    【解决方案1】:

    我建议您尝试以下方法之一:

    1) 迁移整个项目以使用androidx 库,您可以在菜单栏中的Refactor > Migrate to AndroidX 下执行此操作。

    2) 将com.google.firebasecom.google.android.gms的版本从17.x.x降级到更低版本

    【讨论】:

    • 我刚刚尝试了降级,它成功了,但是这里的错误 implementation 'com.android.support:appcompat-v7:28.0.0' 是那里
    • 太棒了,现在我建议您迁移整个项目以使用我上面建议的 androidx
    • 好的,通过这个迁移会影响支持的设备吗?因为我正在创建这个新的测试项目,以查看为什么当我上传 apk 并制作一个干净的项目时,支持的设备在我现有的项目中被删除了
    • 不,迁移不会影响支持的设备。
    • 对不起,我耽搁了,implementation 'androidx.appcompat:appcompat:1.0.0' androidTestImplementation 'androidx.test:runner:1.1.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' 现在它工作了,所以我应该继续将它们升级到新版本吗?
    猜你喜欢
    • 1970-01-01
    • 2015-10-01
    • 2021-01-06
    • 1970-01-01
    • 1970-01-01
    • 2018-10-29
    • 1970-01-01
    • 1970-01-01
    • 2021-12-21
    相关资源
    最近更新 更多