10

This error came after when I added compile 'org.apache.httpcomponents:httpmime:4.2.3'. Can't find solution I also tried multiple dex file true in default config section. I also tried creating another app for testing which was running successfully.

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 2

This is my build.gradle file.

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.2"

        defaultConfig {
            applicationId "com.example.qualwebs.assistme"
            minSdkVersion 19
            targetSdkVersion 23
            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:23.1.1'
        compile 'com.android.support:design:23.1.1'
        compile 'de.hdodenhof:circleimageview:2.0.0'
        compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
        compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
        compile 'com.getbase:floatingactionbutton:1.10.1'
        compile 'org.apache.httpcomponents:httpmime:4.2.3'
    }
Pritish Joshi
  • 2,025
  • 3
  • 18
  • 33
  • add useLibrary 'org.apache.http.legacy' to in your gradle file under the android block. Check [this](http://stackoverflow.com/questions/31653002/how-to-use-the-legacy-apache-http-client-on-android-marshmallow). Since now Apache HTTP Client is now the legacy class. – MrDumb Dec 15 '15 at 09:34
  • `compile 'org.apache.httpcomponents:httpmime:4.5.1'` – IntelliJ Amiya Dec 15 '15 at 09:35
  • 1
    About multidex, you also have to make a change in the Application class ( you have to extend MultiDexApplication ), or if you don't extend Application , put android:name="android.support.multidex.MultiDexApplication" on the application tag in the manifest. – Rick Sanchez Dec 15 '15 at 09:35

3 Answers3

8

The Android plugin for Gradle available in Android SDK Build Tools 21.1 and higher supports multidex as part of your build configuration. Make sure you update the Android SDK Build Tools tools and the Android Support Repository to the latest version using the SDK Manager before attempting to configure your app for multidex.

Setting up your app development project to use a multidex configuration requires that you make a few modifications to your app development project. In particular you need to perform the following steps:

  1. Change your Gradle build configuration to enable multidex
  2. Modify your manifest to reference the MultiDexApplication class

Modify your app Gradle build file configuration to include the support library and enable multidex output .

    android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        ...
        minSdkVersion 19
        targetSdkVersion 23
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

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

In your manifest add the MultiDexApplication class from the multidex support library to the application element.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>

Edited

You can use

compile 'org.apache.httpcomponents:httpmime:4.5.1' 

Read

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

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • Thanks for answer... I tried solution what you have given but still I am getting such kind of error. –  Dec 15 '15 at 10:04
  • 1
    Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/http/ConnectionClosedException.class –  Dec 15 '15 at 10:04
  • Okay .Comment out `compile 'org.apache.httpcomponents:httpmime:4.2.3'` for testing case – IntelliJ Amiya Dec 15 '15 at 10:06
  • Have a look here http://stackoverflow.com/questions/29872225/java-util-zip-zipexception-duplicate-entry – IntelliJ Amiya Dec 15 '15 at 10:09
  • 1
    thanks.. issue has been solved. I have used the upper version `compile 'org.apache.httpcomponents:httpmime:4.5.1'` with your solution thanks for help. –  Dec 15 '15 at 10:20
  • Note: If your app uses extends the Application class, you can override the attachBaseContext() method and call MultiDex.install(this) to enable multidex. For more information, see the [MultiDexApplication](https://developer.android.com/reference/android/support/multidex/MultiDexApplication.html?hl=es) reference documentation. – Farzad May 24 '16 at 22:27
2

You have problem of multidex file so please add below dependency to your app Gradle file.

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

Also add this line:

defaultConfig {

    applicationId 'pkg'
    minSdkVersion 
    targetSdkVersion 
    versionCode 
    versionName 

    // Enable MultiDexing:  https://developer.android.com/tools/building/multidex.html
    multiDexEnabled true
}

Also add below in Manifest.xml :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>

Edited :

Try the following:

Change setting

Ctrl + Alt + S -> Compiler -> Gradle

InVM Options field write:

-Xmx2048m -XX:MaxPermSize=512m

Add in gradle

dexOptions { javaMaxHeapSize "2g" }

Thanks..!!

AndiGeeky
  • 11,266
  • 6
  • 50
  • 66
0

This issue is quite possibly due to exceeding the 65K methods dex limit imposed by Android. This problem can be solved either by cleaning the project, and removing some unused libraries and methods from dependencies in build.gradle, OR by adding multidex support.

So, If you have to keep libraries and methods, then you can enable multi dex support by declaring it in the gradle config.

defaultConfig {        
// Enabling multidex support.
multiDexEnabled true
}
Sharath
  • 691
  • 8
  • 23