Build APK - ERROR - app:transformClassesWithDexFor

2019-05-05 07:54发布

问题:

I watched so many threads here and still didnt find working solution.

When I want to BUILD APK, I get this main error:

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: Error while executing java process with main class com.android.dx.command.Main with arguments {--dex --num-threads=4 --multi-dex --main-dex-list C:\Users\ratik\Desktop\BUILDBOX\VOLUNTEER\STUDIO\app\build\intermediates\multi-dex\debug\maindexlist.txt --output C:\Users\ratik\Desktop\BUILDBOX\VOLUNTEER\STUDIO\app\build\intermediates\transforms\dex\debug\folders\1000\1f\main C:\Users\ratik\Desktop\BUILDBOX\VOLUNTEER\STUDIO\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar}

There is few more errors, but then apear only sometimes, some of them:

Error: at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)

Error: at com.android.dx.command.dexer.Main.processFileBytes(Main.java:723)

Error: at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)

Error:java.lang.OutOfMemoryError: GC overhead limit exceeded

What I tried:

In build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "com.biif.volunteer"
        minSdkVersion 14
        targetSdkVersion 25
        multiDexEnabled true

        ndk {
            moduleName "player_shared"
        }

    }

    buildTypes {
        release {
            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }


    }
    sourceSets.main {
        jni.srcDirs = []// <-- disable automatic ndk-build call
    }
}

dependencies {
    compile ('com.google.android.gms:play-services:+'){exclude module: 'support-v4'}
    compile files('libs/dagger-1.2.2.jar')
    compile files('libs/javax.inject-1.jar')
    compile files('libs/nineoldandroids-2.4.0.jar')
    compile files('libs/support-v4-19.0.1.jar')
    compile ('com.android.support:multidex:1.0.1')
}

In Manifest

android:name="android.support.multidex.MultiDexApplication"

Plus I turned off Instant run (saw in one thread here).

Nothing helped :( Any ideas please? Thanks for help guys :)

回答1:

I included gradle.properties file in the project with:

org.gradle.jvmargs=-Xmx10248m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

and it works.