【问题标题】:Gradle Sync and Build FailGradle 同步和构建失败
【发布时间】:2019-07-04 05:57:15
【问题描述】:

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

我已尝试使用互联网上的所有解决方案,但似乎没有任何效果,还尝试了错误提供的解决方案,该解决方案为向清单添加工具但也不起作用 错误是:

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(模块: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'
    }

【问题讨论】:

标签: android


【解决方案1】:
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'

【讨论】:

【解决方案2】:

来自firebase

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

除非您在应用中进行以下更改,否则更新后的库将不起作用:

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

从 gradle 文件中,你使用的是android support library,请改成androidx

【讨论】:

    猜你喜欢
    • 2016-12-29
    • 2016-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-22
    • 2014-03-30
    相关资源
    最近更新 更多