Gradle同步和构建失败

时间:2019-07-04 05:57:15

标签: android

在gradle同步和构建中出错。当我尝试添加firebase core sdk时出现错误,否则该应用程序成功构建并运行,它只是firebase core sdk在我尝试添加时导致同步失败。

我尝试使用Internet上的所有解决方案,但似乎无济于事,还尝试了该错误,即该错误为清单中添加了工具,但该方法也不起作用 错误是:

ERROR: Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
        is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
        Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-19:19 to override.

Build.gradle(项目)

  {
    // Top-level build file where you can add configuration options common to all sub-projects/modules.

    buildscript {
        repositories {
            google()
            jcenter()

        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.4.1'
            classpath 'com.google.gms:google-services:4.2.0'
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }

    allprojects {
        repositories {
            google()
            jcenter()

        }
    }

    task clean(type: Delete) {
        delete rootProject.buildDir
    }

    }   

Build.Gradle(Module:app)

{

    apply plugin: 'com.android.application'

    android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "ca.mohawk.patel.capstoneproject"
            minSdkVersion 21
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.google.firebase:firebase-core:17.0.0'
        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'

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

2 个答案:

答案 0 :(得分:0)

Build.gardle(Module:app){

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "ca.mohawk.patel.capstoneproject"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.google.firebase:firebase-core:17.0.0'
    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'

}

}

//     应用插件:“ com.google.gms.google-services”

答案 1 :(得分:0)

来自firebase

  

此版本是主要版本更新,其中包含重大更改。   在此版本中,库已从Android支持迁移   Jetpack(AndroidX)库的库。

除非您在应用中进行以下更改,否则更新的库将无法工作:

  • 升级 com.android.tools.build:升级到v3.2.1或更高版本。
  • 升级,将SdkVersion升级到28或更高版本。
  • 更新您的应用以使用Jetpack(AndroidX);按照迁移到AndroidX中的说明进行操作。

从gradle文件中,您正在使用android support library,请更改为androidx