android - 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。我曾多次尝试清理和重建项目。我也尝试过使缓存无效,但没有任何帮助。我不认为这个错误可以通过执行前两行中提到的任务来纠正。
任何帮助,将不胜感激。提前致谢。
解决方案
首先,您需要使您的compileSdkVersion
、buildToolsVersion
和targetSdkVersion
使用相同的版本。使用版本 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
}
推荐阅读
- python-3.x - 需要 url (demo) 用于 Ups Shipment Api 集成
- javascript - 在流星 js 应用程序中显示组织结构图
- sql - 日期时间功能:学期、季度
- javascript - 查找列表中哪个元素具有特定文本
- android - 将 LiveData 转换为 MutableLiveData
- c++ - 你能用 cmake 创建可重定位的安装(跨机器)吗?
- angular - 如何等待 Angular 中不同组件的可观察解析
- java - Spring 的 Spark 作业注入
- java - 如何使用有界类型参数扩展泛型类
- java - 使用 PDFBox 和 Apache Batik 的 PDF 到 SVG 渲染问题