在执行以下
时,android studio出现构建错误任务':app:transformClassesWithMultidexlistForDebug'的执行失败。 com.android.build.api.transform.TransformException:生成主dex列表时出错。
这是我的gradle文件,我在其中添加了一些jar依赖项。
App.gradle
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.demo"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
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:27.1.1'
testImplementation 'junit:junit:4.12'
implementation files('libs/commons-codec-1.4.jar')
implementation files('libs/commons-codec-1.9.jar')
implementation files('libs/opencsv-2.4.jar')
implementation files('libs/ormlite-android-4.46.jar')
implementation files('libs/ormlite-core-4.46.jar')
implementation files('libs/Pushwoosh.jar')
implementation files('libs/StartAppInApp-2.3.2.jar')
}
Project.gradle
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
答案 0 :(得分:1)
根据需要确保build.gradle中的multidex为true。
android {
compileSdkVersion 22
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion 22
// Enabling multidex support.
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.3'
}
您还可以创建一个扩展multidex的类,并且该类应在应用程序标记中提及。