我是Android新手,我尝试使用本教程(只是Room数据库部分):here。
当我执行我的应用时,我收到以下错误:
错误:任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'执行失败。
>
com.android.builder.dexing.DexArchiveMergerException:无法合并dex
在我按this修复另一个错误(关于Room的架构导出目录)后,似乎出现了这个问题。我曾尝试使用multiDexEnabled true
关于修复此问题的this post's建议并使用// 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.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
ext {
buildToolsVersion = "25.0.2"
supportLibVersion = "25.3.1"
archRoomVersion = "1.0.0-alpha1"
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' } //needed for Room
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
进行清理/重新构建,但它无法正常工作。
任何建议都将不胜感激。这是我在这里的第一篇文章,所以如果我做错了什么,请告诉我。
Project gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.myname.room_example"
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()] // Room schema
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:multidex:1.0.2'
implementation "android.arch.persistence.room:runtime:1.0.0-alpha1"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"
implementation 'com.android.support:support-annotations:27.0.0'
}
App Gradle:
print(obj)
答案 0 :(得分:0)
将buildToolsVersion
和supportLibVersion
更新为以下代码中的最新内容。
ext {
buildToolsVersion = "25.0.2"
supportLibVersion = "25.3.1"
archRoomVersion = "1.0.0-alpha1"
}
然后清理并重建项目以查看它是否有效。
答案 1 :(得分:0)
我找到了解决方案。替换:
"android.arch.persistence.room:runtime:1.0.0-alpha1"
和
"android.arch.persistence.room:compiler:1.0.0-alpha1"
带
"android.arch.persistence.room:runtime:1.0.0"
和
"android.arch.persistence.room:compiler:1.0.0"