utf
utf

Reputation: 3

add library occurred build errors

What went wrong?

Execution failed for task ':app:transformClassesWithDexForDebug'.> com.android.build.api.transform.TransformException:
java.lang.RuntimeException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException:
java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException

Upvotes: 0

Views: 90

Answers (2)

Prokash Sarkar
Prokash Sarkar

Reputation: 11873

Android programs are compiled into .dex (Dalvik Executable) files, which are in turn zipped into a single .apk file on the device. Sometimes, You need to enable multidex support & larger heap size for compiling those classes with large dex size. For this do the following changes,

First of all, add the multidex dependencies in build.gradle,

dependencies {
    compile 'com.android.support:multidex:1.0.1'
}

change the dexOptions,

android {
dexOptions {
        incremental true
        javaMaxHeapSize "4g"
    }
}

Lastly, add a singleton class that extends multidex support,

public class MyApplication extends MultiDexApplication {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

Open your manifest file and add the singleton class,

<application
        android:name=".app.MyApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        .....
   </application>

Upvotes: 0

Shridutt Kothari
Shridutt Kothari

Reputation: 7394

add below in your build gradle:

dexOptions {
    javaMaxHeapSize "4g"
    preDexLibraries = false
}

add multiDexEnabled true in defaultconfig of build.gradle like this

defaultConfig {
    multiDexEnabled true
}

Upvotes: 0

Related Questions