当我尝试构建项目时,我无法合并dex错误。我确实在其他线程上尝试了所有解决方案,但我找不到一个对我有用的解决方案......所以请不要马上将其标记为重复。
所以这是确切的错误:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
我的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.0.1'
// 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
}
和我的模块build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
//buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.example.leodr.upgradeadmin"
minSdkVersion 15
targetSdkVersion 27
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(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.google.code.gson:gson:2.8.2'
compile 'com.android.support:appcompat-v7:27.0.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
作为外部库我使用GSON。
答案 0 :(得分:0)
尝试启用multidex
修改build.gradle
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
defaultConfig {
multiDexEnabled true
}
在您最明确的文件中定义您的应用名称属性,如此
android:name="com.pkg.YouApplication"
将其包含在您的Application类
中public class YouApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}