Par*_*d0X 296 android dex android-studio-3.0
我有Android Studio Beta.我创建了一个新项目,编译我的旧模块,但是当我尝试启动应用程序时,它没有启动消息:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
Run Code Online (Sandbox Code Playgroud)
com.android.builder.dexing.DexArchiveMergerException:无法合并dex
但我不知道如何解决这个错误.我用谷歌搜索了几个小时但没有成功.
我的项目是:
// 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.0.0-beta6'
classpath "io.realm:realm-gradle-plugin:3.7.1"
classpath 'com.google.gms:google-services:3.1.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
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "parad0x.sk.onlyforyou"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
}
}
compileOptions {
targetCompatibility 1.7
sourceCompatibility 1.7
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
lintOptions {
checkReleaseBuilds false
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//noinspection GradleCompatible
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile project(path: ':loginregisterview')
}
Run Code Online (Sandbox Code Playgroud)
我的模块是gradle:
apply plugin: 'com.android.library'
apply plugin: 'realm-android'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.0.2'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.github.bumptech.glide:glide:4.0.0'
testCompile 'junit:junit:4.12'
compile project(path: ':parser')
}
Run Code Online (Sandbox Code Playgroud)
我的第二个模块:
apply plugin: 'com.android.library'
apply plugin: 'realm-android'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
realm {
syncEnabled = true
}
useLibrary 'org.apache.http.legacy'
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile 'junit:junit:4.12'
// compile 'com.android.support:appcompat-v7:23.1.0'
// compile 'com.fasterxml.jackson.core:jackson-core:2.9.0'
// compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
// compile 'com.fasterxml.jackson.core:jackson-databind:2.9.0'
compile 'com.google.code.gson:gson:2.6.2'
}
Run Code Online (Sandbox Code Playgroud)
____________finding_________
当我没有导入第二个模块(解析器)时,应用程序没有在dex上崩溃,但是当模块未导入时,应用程序无效.:D:D
itz*_*har 296
我尝试了以上所有内容并且没有一个帮助,最后,我发现这对我有用:
应用程序/的build.gradle:
android {
defaultConfig {
multiDexEnabled true
}
}
Run Code Online (Sandbox Code Playgroud)
小智 290
我有同样的问题,当我从升级com.google.android.gms:play-services:11.2.2
到com.google.android.gms:play-services:11.4.0
.这解决了我:
Mir*_*ili 56
有时你只需要消除警告,错误就会自动消失.见下面的特例:
我在模块级build.gradle
文件中有这两个依赖项:
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'
Run Code Online (Sandbox Code Playgroud)
和Studio 已经警告过(除了dex合并问题):
所有
com.android.support
库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃).找到的版本27.0.2
,21.0.3
.例子包括com.android.support:animated-vector-drawable:27.0.2
和com.android.support:support-v4:21.0.3
所以我明确地确定了版本com.android.support:support-v4
(详见此处),并解决了两个问题(警告和与dex合并相关的问题):
implementation 'com.android.support:support-v4:27.0.2' // Added this line (according to above warning message)
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'
Run Code Online (Sandbox Code Playgroud)
其他类似情况见下面的评论.
Kin*_*ses 37
就我而言,不幸的是,Michel和Suragch的解决方案都不适合我.
所以我通过执行以下操作解决了这个问题:
在gradle:3.0中,编译配置现已弃用,应由implementation或api替换.有关详细信息,请参阅此处.您可以阅读Gradle Build Tool的官方文档
编译配置仍然存在但不应使用,因为它不会提供api和实现配置提供的保证.
最好使用实现或api而不是编译
只需更换编译与执行,debugCompile与debugImplementation,testCompile与testImplementation和androidtestcompile与androidTestImplementation
例如:而不是这个
compile 'com.android.support:appcompat-v7:26.0.2'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.github.bumptech.glide:glide:4.0.0'
Run Code Online (Sandbox Code Playgroud)
像这样用
implementation 'com.android.support:appcompat-v7:26.0.2'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.github.bumptech.glide:glide:4.0.0'
Run Code Online (Sandbox Code Playgroud)
之后
希望它会有所帮助!
Sur*_*gch 26
删除.gradle
目录.
再次运行您的应用.
笔记
.gradle
目录位于项目的根文件夹中.(您可能必须先显示隐藏文件.)Mic*_*ung 23
.gradle
按照Suragch的建议删除对我来说还不够.另外,我必须执行一个Build > Clean Project
.
请注意,要查看.gradle
,您需要切换到左上角导航器中的"项目"视图:
Ali*_*lli 23
我尝试了所有其他解决方案,但没有人为我工作.最后,我通过编辑使用相同的依赖版本来解决它build.gradle
.我认为在将库添加到使用不同依赖版本的支持或谷歌库的gradle时会出现此问题.
将以下代码添加到构建gradle文件中.然后clean
和rebuild
项目.
ps:这对我来说是旧解决方案所以你应该使用以下库的更新版本.
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '26.1.0'
}
} else if (requested.group == "com.google.android.gms") {
details.useVersion '11.8.0'
} else if (requested.group == "com.google.firebase") {
details.useVersion '11.8.0'
}
}
}
Run Code Online (Sandbox Code Playgroud)
DIN*_*LIT 14
if(1.尝试清理和重建工作)那么好
否则如果(2.尝试删除gradle工作)然后好
else-> 3.尝试添加grade.properties
android.enableD8 = false
Run Code Online (Sandbox Code Playgroud)
else-> 4. multiDexEnabled
在build.gradle中添加true
android {
compileSdkVersion 26
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
...
}
}
Run Code Online (Sandbox Code Playgroud)
并添加依赖项
dependencies {
compile 'com.android.support:multidex:1.0.1'}
Run Code Online (Sandbox Code Playgroud)
它可能是第一个适用于你的等等,但它实际上取决于你的问题的性质,例如
添加此库后,我收到错误消息
implementation 'com.jjoe64:graphview:4.2.2'
Run Code Online (Sandbox Code Playgroud)
后来我发现我必须检查一下,我必须添加相同版本的支持库.所以我必须尝试另一个版本
compile 'com.jjoe64:graphview:4.2.1'
Run Code Online (Sandbox Code Playgroud)
它解决了这个问题.所以要注意这一点.
小智 13
在我的情况下问题是因为房间库:
compile 'android.arch.persistence.room:runtime:1.0.0-alpha1'
Run Code Online (Sandbox Code Playgroud)
将其更改为:
compile 'android.arch.persistence.room:runtime:1.0.0'
Run Code Online (Sandbox Code Playgroud)
工作.
Sav*_*een 11
嗨,我有同样的问题几乎尝试了一切.所以,最后我通过逐行调试一切经过长达6小时的努力解决了.
classpath 'com.google.gms:google-services:3.0.0'
Run Code Online (Sandbox Code Playgroud)
Google-services 3.0不支持带有playServiceVersion的Studio 3.0的firebase:11.6.0或更低版本.
implementation "com.google.firebase:firebase-messaging:$rootProject.ext.playServiceVersion"
implementation "com.google.firebase:firebase-core:$rootProject.ext.playServiceVersion"
implementation "com.firebase:firebase-jobdispatcher-with-gcm-dep:$rootProject.ext.jobdispatcherVersion"
Run Code Online (Sandbox Code Playgroud)
方案:
我已将谷歌服务改为
classpath 'com.google.gms:google-services:3.1.1'
Run Code Online (Sandbox Code Playgroud)
它支持firebase服务.
希望有人能节省他/她的时间.
启用
defaultConfig {multiDexEnabled true}
如果步骤1不起作用
转到项目结构并找出使用不同版本的外部库.双击它并删除其jar文件.关闭项目并再次打开android studio将重建项目.问题应该消失了.
如果在包含kotlin支持后出现此错误,并且其他解决方案都不起作用,请尝试将app模块的kotlin依赖关系更改build.gradle
为:
implementation ("org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version") {
exclude group: 'org.jetbrains', module: 'annotations'
}
Run Code Online (Sandbox Code Playgroud)
这适用于Android Studio 3.0 Beta 6.请参阅此答案以获得进一步说明.
小智 5
使用Android Studio 3.0稳定版本,以下步骤对我有用:
小智 5
其中一种可能性是:存在相同的库但在依赖项中具有不同的版本.
我在gradle文件中有以下几行出现此问题:
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.code.gson:gson:2.8.2'
gson库位于我的libs目录中,但具有以前的版本.我gson-2.3.1.jar
从libs目录中删除了一切,恢复正常.
[无法合并DEX求助]经过数小时的堆栈溢出后,我解决了"无法合并DEX ERROR"
原因 - Android已将其支持库更新到v27.1.0,因此您必须将gradle文件中的所有android支持行从26.1.0更改为27.1.0
确保存储库部分包含带有" https://maven.google.com "端点的maven部分.例如:
allprojects {repositories {jcenter()maven {url" https://maven.google.com "}}}
原因: - Android无法更新SDK管理器中的支持库,现在它使用maven.google.com进行更新,因此您必须将其包含在内才能使用27.1.0支持库
更改版本后: 1.清理项目2.重建项目
归档时间: |
|
查看次数: |
349747 次 |
最近记录: |