【问题标题】:I'm trying to add Firebase to my project, got Manifest merger failed error我正在尝试将 Firebase 添加到我的项目中,出现 Manifest merge failed 错误
【发布时间】:2018-07-19 09:23:38
【问题描述】:

我已添加

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' 到 app 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,它在过去给我带来了很多错误。感觉就像是半解决方案或快速解决方案。

编辑:

项目级 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')


}

【问题讨论】:

标签: android firebase android-manifest


【解决方案1】:

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

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

清单合并失败:属性 meta-data#android.support.VERSION@value value=(26.0.2) from [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 value=(26.1.0) .建议:将 'tools:replace="android:value"' 添加到 AndroidManifest.xml:23:9-25:38 的元素以覆盖。

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

您可以手动维护它或将以下脚本添加到 project 级别 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 支持库版本

【讨论】:

  • 您是否正在使用可用于您的 android 工作室的最新 gradle 插件?顺便说一句,检查更新的编辑 1 部分的帖子。让我知道它是否有效
猜你喜欢
  • 2019-08-22
  • 2019-11-10
  • 1970-01-01
  • 1970-01-01
  • 2021-04-30
  • 2019-10-13
  • 2019-04-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多