Search code examples
androidandroid-studiobuild.gradledex

Unable to run app Error:Execution failed for task ':app:transformClassesWithDexForDebug'


When I try to run my app I am getting this error

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.8.0_72\bin\java.exe'' finished with non-zero exit value 2

I tried all the possible solutions mentioned here Error:Execution failed for task ':app:transformClassesWithDexForDebug'

  1. I am not getting any duplicate lib
  2. Increased the heap size to 1024 MB
  3. clean project
  4. closed all other studio windows

Please find below my build.gradle

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.dapl.shoppingapp"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    maven { url "https://jitpack.io" }
    mavenCentral()
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile files('libs/quickblox-android-sdk-chat-2.5.jar')
    compile files('libs/quickblox-android-sdk-core-2.5.jar')
    compile files('libs/quickblox-android-sdk-messages-2.5.jar')
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.google.android.gms:play-services:8.3.0'
    compile 'org.lucasr.twowayview:twowayview:0.1.4'
    compile 'com.google.android.gms:play-services-gcm:8.3.0'
    compile files('libs/apache-httpcomponents-httpcore.jar')
    compile files('libs/httpclient-4.2.3.jar')
    compile files('libs/httpmime-4.2.4.jar')
    compile files('libs/gcm.jar')
    //    compile project(':libraries:viewpager_indicator')
}

Please help!

By adding multiDexEnabled true in defaultConfig getting this error

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/NOTICE.txt File1: C:\Users\DAT-Asset-117-PC\Downloads\Skype downloads\ShoppingApp\ShoppingApp\app\libs\httpclient-4.2.3.jar File2: C:\Users\DAT-Asset-117-PC\Downloads\Skype downloads\ShoppingApp\ShoppingApp\app\libs\apache-httpcomponents-httpcore.jar File3: C:\Users\DAT-Asset-117-PC\Downloads\Skype downloads\ShoppingApp\ShoppingApp\app\libs\httpmime-4.2.4.jar

EDIT : After doing all these I am getting another error

java.lang.VerifyError: org/lucasr/twowayview/TwoWayView
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at android.view.LayoutInflater.createView(LayoutInflater.java:594)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at com.dapl.shoppingapp.tabs.storeTabs.storeTabFragment.StoreTabFragment1.onCreateView(StoreTabFragment1.java:29)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
            at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
            at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
            at android.support.v4.view.ViewPager.populate(ViewPager.java:1106)
            at android.support.v4.view.ViewPager.populate(ViewPager.java:952)
            at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1474)
            at android.view.View.measure(View.java:16900)
            at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:818)
            at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:495)
            at android.view.View.measure(View.java:16900)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5406)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:332)
            at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
            at android.view.View.measure(View.java:16900)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5406)
            at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1616)
            at android.widget.LinearLayout.measureVertical(LinearLayout.java:729)
            at android.widget.LinearLayout.onMeasure(LinearLayout.java:601)
            at android.view.View.measure(View.java:16900)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5406)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:332)
            at android.view.View.measure(View.java:16900)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5406)
            at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1616)
            at android.widget.LinearLayout.measureVertical(LinearLayout.java:729)
            at android.widget.LinearLayout.onMeasure(LinearLayout.java:601)
            at android.view.View.measure(View.java:16900)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5406)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:332)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2408)
            at android.view.View.measure(View.java:16900)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5406)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:332)
            at android.view.View.measure(View.java:16900)
            at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:818)
            at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:495)
            at android.view.View.measure(View.java:16900)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5406)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:332)
            at android.view.View.measure(View.java:16900)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5406)
            at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1616)
            at android.widget.LinearLayout.measureVertical(Linear

Getting Crash: This two way view is my lib. and I think this crash is beacuse of multiDexEnabled true


Solution

  • Android 5.0 and higher uses a runtime called ART which natively supports loading multiple dex files from application APK files.

    Add

    1. multiDexEnabled true

    Example

    defaultConfig {
        ...
        minSdkVersion 15
        targetSdkVersion 23
        ...
    
        // Enabling multidex support.
        multiDexEnabled true
    }
    

    Edit Add this

        android {
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
        }
    
    }