生成Apk时出错:com.android.build.api.transform.TransformException:生成主dex列表时出错 [英] Error Building Apk : com.android.build.api.transform.TransformException: Error while generating the main dex list

查看:72
本文介绍了生成Apk时出错:com.android.build.api.transform.TransformException:生成主dex列表时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

After project into two libraries module and one app module Android Studio is unable to build Apk but when I build project into real device into or emulator it work perfectly

这是我在消息"标签中看到的完整堆栈错误

this is the full stack error which I've got in Messages Tab

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

这是Gradle for app模块

this is the Gradle for app module

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')
}

和lib1库模块的Gradle文件

and the Gradle file for lib1 library module

apply plugin: 'com.android.library'
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
}

defaultConfig {
    minSdkVersion 15
    targetSdkVersion 27
    versionCode 1
    versionName "1.0" 
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

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

        zipAlignEnabled true

    }
    debug {
        debuggable true
        minifyEnabled false
        testCoverageEnabled false 
    }


}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
}

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'
implementation project(':lib2')

//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 project(':PersianDateTimePicker')
implementation project(':crystalrangeseekbar-1.1.3')
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.larswerkman:HoloColorPicker:1.5'
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.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 "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "android.arch.persistence.room:runtime:$archRoomVersion"
annotationProcessor "android.arch.persistence.room:compiler:$archRoomVersion"
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"
annotationProcessor 'android.arch.core:core-testing:1.1.1'
implementation 'com.github.angads25:filepicker:1.1.1'
}

推荐答案

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

I got the error and this was because of having two same classes in two modules. while building Apk all classes should be written to main dex list file and if there is a duplicate class name in it, it fails.

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

The way I found the duplicate class name was by using --stacktrace in command line options which could be reached by

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

file > setting > build,execution,deployment > compiler

这篇关于生成Apk时出错:com.android.build.api.transform.TransformException:生成主dex列表时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆