编译android应用程序时出错 - 任务执行失败:app:transformClassesWithDexForDebug

时间:2016-09-02 11:50:30

标签: java android android-gradle build.gradle

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

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

5 个答案:

答案 0 :(得分:2)

添加谷歌地图后,方法和引用计数超过64K:

  

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

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

希望这可以帮到你。

答案 1 :(得分:1)

根据你的问题

而不是

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

使用此

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

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

答案 2 :(得分:0)

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

 dexOptions {
    javaMaxHeapSize "4g"
}

答案 3 :(得分:0)

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

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

还添加此

android {

    defaultConfig {

        // Enabling multidex support.
        multiDexEnabled true
}
}

答案 4 :(得分:0)

根据Google的建议:Selectively compiling APIs into your executable,您可以尝试替换build.gradle文件中的以下行:

$sql = "select * from pd"; $result = mysqli_query($con,$sql); if($rowcount=mysqli_num_rows($result)) { while($row = mysqli_fetch_assoc($result)) { $resul[] = $row; } } mysqli_close($con); echo json_encode(array("pd_main"=>$resul));

满足您的需求:

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