繁体   English   中英

包含Firebase和GMS服务时,Android Gradle构建失败,发生异常

[英]Android gradle build failed with an exception when include firebase and gms service

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

/Users/macbookair/Desktop/ANDROID/APPTEST/app/src/main/AndroidManifest.xml:22:18-91错误:来自[com.android]的属性application @ appComponentFactory value =(android.support.v4.app.CoreComponentFactory) .support:support-compat:28.0.0] AndroidManifest.xml:22:18-91也存在于[androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value =(androidx.core .app.CoreComponentFactory)。 建议:在AndroidManifest.xml:5:5-21:19的元素上添加'tools:replace =“ android:appComponentFactory”'以进行覆盖。

请任何人帮助我,我已经尝试了很长时间以解决此错误。

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'}

在此处输入图片说明

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

1)迁移整个项目以使用androidx库,您可以在菜单栏中的“ 重构” >“ 迁移到AndroidX”进行操作

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM