Gradle Build fails with unexpected error while trying to build APK
I wrote a little code, but whenever I try to build an apk, I get the following error:
Error: Execution completed for task ': app: transformClassesWithMultidexlistForDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: error while executing Java process with main class com.android.multidex.ClassReferenceListBuilder with arguments {C: \ Users \ xxxx \ Desktop \ yyyyy \ app \ build \ intermediates \ multi-dex \ debug \ componentClasses.jar C: \ Users \ xxxx \ Desktop \ yyyyy \ app \ build \ intermediates \ transforms \ jarMerging \ debug \ jars \ 1 \ 1f \ combination. jar}
Where xxxx is my username and yyyyy is the project name. I tried every possible solution I found on Stack Overflow, but I realized that they were all asked about older versions.
I have the latest version of Android Studio. I am using the latest Android SDK, build tools, gradle, JDK 8.0 and JRE 7. I have also tried JRE 8.
build.gradle(module app) :
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "xxxx.yyyyy"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "Unreleased Demo Version"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
{
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:multidex:1.0.1'
}
source to share
This happens when the Android platform continues to grow, hence the size of Android apps. When your app and its link libraries reach a certain size, you run into build errors that indicate that your app has reached the limit of the Android app build architecture.
Modify the build.gradle file at the module level to enable multidex and add the multidex library as a dependency as shown here. : Source
android {
defaultConfig {
multiDexEnabled true
}
}
source to share
Try this in your Module: App gradle folder.
multiDexEnabled true
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
You haven't used any of your code and dependencies you are working with, so it's hard to guess the exact problem.
but from the error you received, I think your program is crossing the 64K method limit.
Apk files encodes bytecode files in DEX format and has a limit of 65,536 methods in a single DEX file.
So, if your application has over 64k methods, you should go for multiple Dex files.
Enabling mutiple Dex means the application build process will generate more than one DEX file
defaultConfig {
....
multiDexEnabled true
}
dependencies {
....
compile 'com.android.support:multidex:1.0.0'
}
source to share
I found that there is no need to install JDK and JRE (ref: last page of android android studio 2.3.2 download as per system requirements)
And there is a folder named "jre" in the programfiles / android-studio folder.
So I decided to remove the JDK and JRE (as a java related issue)
After that, I reinstalled android studio.
And now it works great. (I didn't do research in depth, although it did help me)
source to share
This happens when you have a cross limit of 65,536 methods.
Step 1
You can add the following to your app build.gradle file:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 25
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
Step 2A
After that, you need to extend the Application class as follows
public class MyApplication extends SomeOtherApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Or you can do the following:
Step 2B
public class MyApplication extends MultiDexApplication { ... }
STEP 3
Finally update your manifest file as shown below
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
source to share