我正在尝试将Firebase添加到我的项目,出现清单合并失败错误

时间:2018-07-19 09:23:38

标签: android firebase android-manifest

我已添加

classpath 'com.google.gms:google-services:4.0.0'

到buildscript / dependencies中的项目级gradle文件。

我还添加了

  compile 'com.google.firebase:firebase-core:16.0.1'

到依赖项内的应用程序级别gradle文件

我还已经将google-services.json文件添加到应用文件夹中。

我还添加了 apply plugin: 'com.google.gms.google-services'至应用gradle文件的顶部。 (教程说的是底部,但我的顶部也有织物,我不认为这是个问题,我也已经在底部进行了测试,结果相同)

当我尝试运行项目时,出现此错误:

  

错误:任务':app:processBetaDebugManifest'的执行失败。

     
    

清单合并失败:来自以下位置的属性meta-data#android.support.VERSION@value value =(26.0.2)     [com.android.support:recyclerview-v7:26.0.2]     AndroidManifest.xml:25:13-35也位于     [com.android.support:support-v4:26.1.0] AndroidManifest.xml:28:13-35     值=(26.1.0)。建议:将'tools:replace =“ android:value”'添加到      覆盖AndroidManifest.xml:23:9-25:38中的元素。

  

为什么会这样?我什么都没改变,只是添加了Firebase,如官方消息所述。

我不想在清单中使用tools:replace,这过去使我遇到了许多错误。感觉像是半解决方案或快速解决方案。

E D I T:

项目级gradle文件:

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        classpath 'com.google.gms:google-services:4.0.0'
    }
}



allprojects {
    repositories {
        google()
        jcenter()

        flatDir {
            dirs 'libs'
        }
    }
}

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

应用级gradle文件:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'


android {
    compileSdkVersion 26
    defaultConfig {

        minSdkVersion 19
        targetSdkVersion 26

        vectorDrawables.useSupportLibrary = true
    }


    buildTypes {
        release {
            debuggable false

            shrinkResources false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true

            shrinkResources false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    // Specifies a flavor dimensions. Must have at least one.
    flavorDimensions "myFlavorDimension"

    productFlavors {

        beta {
            applicationId "hu.adamvarhegyi.myproject.beta"
            versionCode 12
            versionName '1.0.94 beta'
        }

        //Release
        standard {
            applicationId "hu.adamvarhegyi.myproject"
            versionCode 12
            versionName '1.0.94'
        }
    }





    applicationVariants.all { variant ->
        variant.outputs.all { output ->
            def project = "my_project"
            def SEP = "_"
            def buildType = variant.variantData.variantConfiguration.buildType.name
            def versionName = variant.versionName
            def versionCode = "(v_" + variant.versionCode + ")"
            def date = new Date();
            def formattedDate = date.format('yyyy-MM-dd-HH-mm')

            def newApkName = project + SEP + buildType + SEP + versionName + SEP + versionCode + SEP + formattedDate + ".apk"

            outputFileName = new File(newApkName)
        }
    }


}


buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        // These docs use an open ended version so that our plugin
        // can be updated quickly in response to Android tooling updates

        // We recommend changing it to the latest version from our changelog:
        // https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin
        classpath 'io.fabric.tools:gradle:1.+'
    }
}



repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
    maven { url "https://maven.google.com" }
    maven { url "https://jitpack.io" }
}




dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    compile('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
        transitive = true;
    }

    compile project(':gameanalytics')
    compile 'com.google.android.gms:play-services-basement:8.4.0'
    compile 'com.google.android.gms:play-services-ads:8.4.0'

    compile('com.android.support:appcompat-v7:26.0.2')


    compile('com.android.support:recyclerview-v7:26.0.2')
    compile 'com.android.support:gridlayout-v7:26.0.2'

    compile('com.makeramen:roundedimageview:2.2.1')
    compile('de.hdodenhof:circleimageview:2.1.0')
    compile 'com.squareup.okio:okio:1.13.0'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    implementation 'com.github.javiersantos:PiracyChecker:1.2.3'

    compile 'com.google.firebase:firebase-core:16.0.1'

    compile(name: 'my_project_engine', ext: 'aar')


}

1 个答案:

答案 0 :(得分:0)

您正在使用不同版本的Android支持库,导致在不同版本的支持库的清单中出现此冲突

这也可能是因为您的任何依赖项都使用不同版本的支持库作为其依赖项。

  

清单合并失败:来自[com.android.support:recyclerview-v7: 26.0.2 ] AndroidManifest的属性meta-data#android.support.VERSION@value value =(26.0.2) [com.android.support:support-v4: 26.1.0 ]中也存在.xml:25:13-35。AndroidManifest.xml:28:13-35 value =(26.1.0) 。建议:在AndroidManifest.xml:23:9-25:38的元素上添加'tools:replace =“ android:value”'以进行覆盖。

您必须对所有库使用相同 Android 支持库版本

您可以手动进行维护,也可以将以下脚本添加到项目 build.gradle

这将强制所有版本的Android支持库使用相同版本,因此您无需手动维护

allprojects {

    // Force all of the primary support libraries to use the same version.
    configurations.all {
        resolutionStrategy {
            eachDependency { details ->
                if (details.requested.group == 'com.android.support') {
                    details.useVersion versions.supportLibrary
                }
            }
        }
    }
}

编辑1

您将在这里以更可靠的方式

进行管理

dependencies.gradle

buildscript {

    ext.versions = [
            // Basic
            'supportLibrary'       : '26.1.0',
    ]

    allprojects {

        // Force all of the primary support libraries to use the same version.
        configurations.all {
            resolutionStrategy {
                eachDependency { details ->
                    if (details.requested.group == 'com.android.support') {
                        details.useVersion versions.supportLibrary
                    }
                }
            }
        }
    }
}

项目级别 build.gradle

buildscript {
    . . .
}

apply from: 'dependencies.gradle'

模块级别 build.gradle

dependencies {

    ...

    implementation "com.android.support:appcompat-v7:${versions.supportLibrary}"
    implementation "com.android.support:design:${versions.supportLibrary}"
    implementation "com.android.support:support-vector-drawable:${versions.supportLibrary}"

    ...
}

这是您可以轻松管理所有 Android支持库版本

的方法