首页 > 解决方案 > Android 错误“合并失败”,但并非无处不在的常见错误

问题描述

尝试运行我的 Android 项目时出现以下错误。

如果我使用tools:replace="allowBackup,supportsRtl",那么屏幕截图中形成的场景如下:-

这是错误详细信息屏幕截图

这是我的清单文件

这是合并清单文件中显示的错误

但是如果我在那里使用 tools:replace="android:value" 那么合并的清单文件中会出现以下错误:-

上面是合并清单文件中的错误,下面是显示的一般错误。

这是我的 Gradle 文件:-

这是应用程序级别的 Gradle 文件:-

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion '27.0.3'
defaultConfig {
    applicationId "com.example.android.todolist"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
    }
}
dataBinding.enabled = true
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support.constraint:constraint-layout:1.1.0'
//add Recycler view dependencies; must match SDK version
compile 'com.android.support:recyclerview-v7:25.4.0'
//FAB dependencies
compile 'com.android.support:design:25.4.0'
implementation 'com.google.gms:google-services:3.2.0'
//Testing
// Instrumentation dependencies use androidTestCompile
// (as opposed to testCompile for local unit tests run in the JVM)
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:27.1.1'
androidTestCompile 'com.android.support.test:runner:1.0.2'
androidTestCompile 'com.android.support.test:rules:1.0.2'
}

这是项目级别的 Gradle 文件:-

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

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

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

allprojects {
repositories {
    jcenter()
    google()
}
}

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

我的 Android Studio 版本是 3.1.2。我曾多次尝试清理和重建项目。我也尝试过使缓存无效,但没有任何帮助。我不认为这个错误可以通过执行前两行中提到的任务来纠正。

任何帮助,将不胜感激。提前致谢。

标签: androidandroid-studioandroid-manifest

解决方案


首先,您需要使您的compileSdkVersionbuildToolsVersiontargetSdkVersion使用相同的版本。使用版本 27。因此,将您的应用程序build.gradle 更改为:

应用插件:'com.android.application'

android {

    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "com.example.android.todolist"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

   // ... redacted

然后,您需要为您的依赖项使用支持库版本 27。因此,将依赖项块中的支持库更改为:

dependencies {

    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:27.1.1'
    compile 'com.android.support.constraint:constraint-layout:1.1.0'
    //add Recycler view dependencies; must match SDK version
    compile 'com.android.support:recyclerview-v7:27.1.1'
    //FAB dependencies
    compile 'com.android.support:design:27.1.1'
    implementation 'com.google.gms:google-services:3.2.0'
    //Testing
    // Instrumentation dependencies use androidTestCompile
    // (as opposed to testCompile for local unit tests run in the JVM)
    androidTestCompile 'junit:junit:4.12'
    androidTestCompile 'com.android.support:support-annotations:27.1.1'
    androidTestCompile 'com.android.support.test:runner:1.0.2'
    androidTestCompile 'com.android.support.test:rules:1.0.2'

}

然后在您的依赖项块中删除以下行:

implementation 'com.google.gms:google-services:3.2.0'

因为它不是您的依赖项,但它应该作为类路径放置到根目录。 build.gradle

这里你的根 build.gradle 应该是:

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

buildscript {

    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:3.2.0'

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

}

allprojects {

    repositories {
        jcenter()
        google()
    }

}

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

推荐阅读