4

I have tried the following links

http://developer.android.com/intl/es/tools/building/multidex.html

UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define

com.android.build.transform.api.TransformException

':app:transformClassesWithDexForDebug'. > com.android.build.transform.api.TransformException: when i added Facebook latest SDK in my studio project

Android Studio TransformException : Error:Execution failed for task ':app:transformClassesWithDexForDebug'

Java finished with non-zero exit value 2 - Android Gradle

com.android.build.transform.api.TransformException

My gradle build file is as below.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.1'

    defaultConfig {
        applicationId "appId"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        incremental true
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile files('libs/rt.jar')
    compile 'com.android.support:multidex:1.0.0'
}

My manifest is as below.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="packageName">

    <application
        android:name="android.support.multidex.MultiDexApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

My activity file is as below.

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

After all this, I still get the following error.

Error:Execution failed for task
':app:transformClassesWithMultidexlistForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_72\bin\java.exe'' finished with non-zero exit value 1
Community
  • 1
  • 1
novice_dev
  • 702
  • 1
  • 7
  • 22
  • Scroll up a bit more in the messages window where you found that error. There might be a more useful error message saying what went wrong. – George Mulligan Apr 11 '16 at 23:58
  • Hi George, following is my stack trace. There is nothing wrong here. I am Android Studio noob. – novice_dev Apr 12 '16 at 00:30
  • Are you working on adding the full message displayed to the post? I do not see it there yet. – George Mulligan Apr 12 '16 at 00:33
  • Hi @george-mulligan, following is my stack trace. I am Android Studio noob. I don't find anything wrong. All the other :app: shown as UP-TO-DATE :app:transformClassesWithMultidexlistForDebug Preparing output jar [E:\AndroidStudioProjects\MADS\app\build\intermediates\multi-dex\debug\componentClasses.jar] Copying resources from program jar [E:\AndroidStudioProjects\MADS\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar] :app:transformClassesWithMultidexlistForDebug FAILED – novice_dev Apr 12 '16 at 00:38
  • Why do you have `rt.jar` as a dependency? – George Mulligan Apr 12 '16 at 00:51
  • I want it to use ScriptEngine for evaluating math expression. rt.jar contains the java.script.*. Hence, rt.jar is a dependency. – novice_dev Apr 12 '16 at 00:52
  • Just out of curiosity does it work without it? – George Mulligan Apr 12 '16 at 00:53
  • Nope, the build fails without rt.jar – novice_dev Apr 12 '16 at 00:57

4 Answers4

5

I have found a quick fix. But there might be a better solution to this.

changing minSdkVersion means it will not gonna work for below the sdk version

Under your Android folder look for you build.gradle file. Replace the minSdkVersion to 21. The code for it should look like this

ext {
    buildToolsVersion = "28.0.3"
    minSdkVersion = 21
    compileSdkVersion = 28
    targetSdkVersion = 28
}

thanks to Edward Beazer

Wasi Sadman
  • 1,382
  • 1
  • 15
  • 27
4

Answer

I had to do the following at the app level

  • Remove rt.jar as library
  • Remove compile files('libs/rt.jar') from build.gradle
  • Clean and build project.

Thanks to George Mulligan for pointing it out.

novice_dev
  • 702
  • 1
  • 7
  • 22
0

I'm not sure this is the same for the Windows OS with straight JAVA. I was having the same issue with cordova run android and it always fail in Mac. So I added the following to my build.gradle file and the build passed, and I was able to test on the emulator. Add your compiled info under android section and multidex under default config

android {
    compileSdkVersion 23
    buildToolsVersion "23"
}

defaultConfig {
    multiDexEnabled true
}

Notice the build is just 23 and not 23.0.1

Cerlin
  • 6,622
  • 1
  • 20
  • 28
Bamanyi
  • 83
  • 1
  • 4
0

I know it is passed. but I had same problem. the message was this:

Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. java.io.IOException: Can't write [D:...app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:....\support-core-ui-27.1.1.aar\eadf2be3981e05166424b72b4128200e\jars\classes.jar(;;;;;;**.class)] (Duplicate zip entry [classes.jar:android/support/v4/view/ViewPager$1.class]))

I searched a lot but nothing found. I resolved it by adding below line to gradle:

implementation 'com.android.support:support-v4:27.0.2'
Sajjad.HS
  • 381
  • 2
  • 8
  • 19