生成Apk时出错:com.android.build.api.transform.TransformException:生成主dex列表时出错

时间:2018-08-27 04:20:11

标签: android android-gradle

将项目分为两个库模块和一个应用程序模块后,Android Studio无法构建Apk,但是当我将项目构建到真实设备中或仿真器中时,它可以完美地运行

这是我在“消息”标签中遇到的完整堆栈错误

library(ggplot2)

#Dummy group variable
Ancestry$row <- 1

#Create a label variable
Ancestry$percent <- (Ancestry$Proportion/sum(Ancestry$Proportion)) * 100

ggplot(Ancestry, aes(x = row,y = Proportion, fill = Race)) +
    geom_bar(stat="identity") + 
    geom_text(aes(label = percent), 
        position = position_stack(vjust = 0.5))

这是Gradle for app模块

FAILURE: Build failed with an exception.

What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
 com.android.build.api.transform.TransformException: Error while generating the main dex list.

Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

Get more help at https://help.gradle.org

BUILD FAILED in 1m 58s

和lib1库模块的Gradle文件

apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android.extensions'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
signingConfigs {
    config {
        storeFile file('E:/***.jks')
    }
}
compileSdkVersion 27
dataBinding {
    enabled = true
}
androidExtensions {
    experimental = true
}
defaultConfig {
    applicationId "com.**.**"
    minSdkVersion 15
    targetSdkVersion 27
    versionCode 307
    versionName "V 3.0.7"
    multiDexEnabled true

    javaCompileOptions {
        annotationProcessorOptions {
            includeCompileClasspath true
        }
    }
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
}

packagingOptions {
    exclude 'META-INF/LGPL2.1'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/NOTICE'
}

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.config

        zipAlignEnabled true

    }
    debug {
        debuggable true
        minifyEnabled false
        testCoverageEnabled true 
    }


} 

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
    unitTests {
        includeAndroidResources = true
    }
    unitTests.returnDefaultValues = true
} 


}

dependencies {
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.powermock:powermock-module-junit4:1.6.4'

//test
androidTestCompile 'com.android.support.test:runner:1.0.2'
androidTestCompile 'com.android.support.test:rules:1.0.2'

// Optional -- Hamcrest library
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'

// Optional -- UI testing with Espresso
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation files('libs/zip4j_1.3.2.jar')
implementation project (':lib1')
implementation project (':lib2')
implementation project(':PersianDateTimePicker')
implementation project(':crystalrangeseekbar-1.1.3')


 implementation files('libs/easywsdl/ksoap2-android-assembly-3.6.2-jar-with-dependencies.jar')
 implementation "com.android.support:multidex:$multi_dex_version"
implementation "com.android.support:support-v4:$support_version"
implementation "com.android.support:appcompat-v7:$support_version"
implementation "com.android.support:design:$support_version"
implementation "com.android.support:cardview-v7:$support_version"
implementation "com.android.support:recyclerview-v7:$support_version"
implementation "com.android.support:support-v13:$support_version"
implementation "com.android.support:preference-v7:$support_version"
implementation "com.android.support:support-vector-drawable:$support_version"
implementation "com.android.support:animated-vector-drawable:$support_version"
implementation "com.android.support:mediarouter-v7:$support_version"
implementation 'com.esri.arcgis.android:arcgis-android:10.2.9'
implementation 'com.nononsenseapps:filepicker:2.4.2'
implementation 'com.github.bmelnychuk:atv:1.2.9'
implementation 'com.github.johnkil.print:print:1.3.1'
implementation 'com.larswerkman:HoloColorPicker:1.5'
implementation 'com.gordonwong:material-sheet-fab:1.2.1'
implementation 'com.github.sevar83:indeterminate-checkbox:1.0.5@aar'
implementation 'com.github.clans:fab:1.6.4'
implementation 'ch.acra:acra:4.9.2'
implementation 'net.time4j:time4j-android:3.32-2017b'
implementation 'com.ibm.icu:icu4j:57.1'
implementation 'lib.kashif:folderpicker:2.2'
implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'org.apache.httpcomponents:httpcore:4.4.7'
implementation('com.github.bumptech.glide:glide:4.6.1') {
    exclude group: "com.android.support"
}
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
implementation 'com.github.lecho:hellocharts-android:v1.5.8'
implementation 'com.wang.avi:library:2.1.3'
implementation 'com.github.florent37:viewanimator:1.0.5'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.anko:anko-sqlite:$anko_version"
implementation "io.reactivex.rxjava2:rxjava:$rxjava2_version"
implementation "io.reactivex.rxjava2:rxandroid:$rxandroid_version"
implementation "com.google.dagger:dagger:$dagger"
implementation "com.google.dagger:dagger-android:$dagger"
implementation "com.google.dagger:dagger-android-support:$dagger"
annotationProcessor "com.google.dagger:dagger-compiler:$dagger"
annotationProcessor "com.google.dagger:dagger-android-processor:$dagger"
implementation "android.arch.persistence.room:runtime:$archRoomVersion"
annotationProcessor "android.arch.persistence.room:compiler:$archRoomVersion"
implementation 'android.arch.persistence.room:rxjava2:1.1.1'
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
implementation "android.arch.lifecycle:viewmodel:$lifecycle_version"
implementation "android.arch.lifecycle:livedata:$lifecycle_version"
implementation "android.arch.lifecycle:runtime:$lifecycle_version"
annotationProcessor "android.arch.lifecycle:compiler:$lifecycle_version"
implementation "android.arch.lifecycle:common-java8:$lifecycle_version"
implementation "android.arch.lifecycle:reactivestreams:$lifecycle_version"
testImplementation "android.arch.core:core-testing:$lifecycle_version"
androidTestImplementation 'android.arch.core:core-testing:1.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.github.angads25:filepicker:1.1.1'
implementation 'com.github.nekocode:Badge:2.0'
implementation files('libs/gt-shapefile-2.7.0.jar')
implementation files('libs/gt-metadata-2.7.0.jar')
}

2 个答案:

答案 0 :(得分:3)

我得到了错误,这是因为在两个模块中有两个相同的类。在构建Apk时,应将所有类都写入主dex列表文件,如果其中有重复的类名,则它将失败。

我发现重复的类名的方法是在命令行选项中使用--stacktrace,

  

文件>设置>构建,执行,部署>编译器

答案 1 :(得分:-1)

我建议请启用multidex来解决此问题

defaultConfig {
    multiDexEnabled true
}

遵循下面的网址,可帮助启用multidex
https://stackoverflow.com/a/27284064/3894930