【问题标题】:Error while compling the android application - Execution failed for task :app:transformClassesWithDexForDebug编译 android 应用程序时出错 - 任务执行失败:app:transformClassesWithDexForDebug
【发布时间】:2017-01-10 12:44:16
【问题描述】:

在我添加谷歌地图活动之前,我的应用程序正在正确编译。然后我得到这个错误

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-8-openjdk-amd64/bin/java'' finished with non-zero exit value 2

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






Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
:app:transformClassesWithDexForDebug FAILED
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-8-openjdk-amd64/bin/java'' finished with non-zero exit value 2

build.gradle

android {
    compileSdkVersion 24
    buildToolsVersion "23.0.3"
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "zupportdesk.desk.zupport.chatsystem"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'

    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.android.support:recyclerview-v7:24.2.0'
    compile 'com.android.support:design:24.2.0'
    compile 'com.android.support:cardview-v7:24.2.0'
    compile 'org.java-websocket:Java-WebSocket:1.3.0'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile 'br.com.liveo:navigationdrawer-material:2.5.1'



    compile files('libs/gson-2.2.2.jar')
    compile files('libs/signalr-client-sdk-android.jar')
    compile files('libs/signalr-client-sdk.jar')

}

谁能帮我解决这个问题。 tnx

【问题讨论】:

标签: java android android-gradle-plugin build.gradle


【解决方案1】:

在 buildTypes{ ... } 之后将其添加到您的 build.gradle:

 dexOptions {
    javaMaxHeapSize "4g"
}

【讨论】:

    【解决方案2】:

    在 gradle 中添加此依赖项...您的应用已达到 64k 引用限制。更多 here

    compile 'com.android.support:multidex:1.0.0'
    

    也添加这个

    android {
    
        defaultConfig {
    
            // Enabling multidex support.
            multiDexEnabled true
    }
    }
    

    【讨论】:

      【解决方案3】:

      添加google maps后,方法和引用数超过64K:

      错误:.dex 文件中的方法引用数不能超过 64K。

      这是一个大问题,每个大项目都会遇到这样的问题。但是谷歌给出了解决方案:Configure Apps with Over 64K Methods

      希望对你有帮助。

      【讨论】:

        【解决方案4】:

        根据你的问题

        代替

        compile 'com.google.android.gms:play-services:9.4.0'
        

        使用这个

        com.google.android.gms:play-services-maps:9.4.0
        

        这将仅包括地图所需的播放服务。您的代码将导入所有播放服务包,这将导致您的应用超过 64K 方法限制

        【讨论】:

          【解决方案5】:

          根据谷歌的建议:Selectively compiling APIs into your executable,你可以尝试在你的build.gradle文件中替换下面这行:

          compile 'com.google.android.gms:play-services:9.6.1'

          你需要什么:

          compile 'com.google.android.gms:play-services-maps:9.6.1' compile 'com.google.android.gms:play-services-xxx2:9.6.1' compile 'com.google.android.gms:play-services-xxx3:9.6.1'

          【讨论】:

            猜你喜欢
            • 2017-09-01
            • 2016-05-24
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多