Android studio 2.0 gradle transformClassesWithDexForDebug fails when using button “run”

僤鯓⒐⒋嵵緔 提交于 2019-11-30 01:29:10

for few weeks i was trying to solve this problem.

Now I have found workaround for that. If someone face the same problem, turning off instant Run in Android Studio settings will help.

I know that it is not a solution but it is the best thing for now.

cheers Wojtek

add

dexOptions {
    javaMaxHeapSize "4g"
}

in android

I restart Android Studio (2.0) when I have this problem. Then it works. No edit in gradle files or turn off instant run required.

All it took to fix this issue for me was to add the following lines to the build.gradle file for the mobile app:

...

android {

    ...

    // Enabling multidex support.
    multiDexEnabled true
}

dexOptions {
    javaMaxHeapSize "4g"
}

...

}

dependencies {

...

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

...

}

For me adding this line (or commenting out because it is written there in the 13th line) in gradle.properties worked:

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

Also I turned off Instant run (Android Studio 2.1.2).

I have the same problem, on linux. For some reason, some files and dirs inside /build can not be deleted, not even with 'sudo -rf', and this is the origin of the problem for me. I built the project in a MacBookPro and no problem.

attempt to set or access a value of type java.lang.Object using a local variable of type int

Seems like in some place ProGuard optimizes variable allocation, but does it incorrectly.

Try to disable this optimization by adding the line below in your proguard-rules.pro:

-optimizations !code/allocation/variable

Refactoring the library helped me resolving this issue. This must have helped in removing duplicate classes from the library or from the app module.

I discovered many solutions but I solved this issue by adding:

Sol 1: In build.gradle:

defaultConfig {
    multiDexEnabled true
}

Clean your project and rebuild.

Sol 2: If still you have issue in local.properties add,

org.gradle.jvmargs=-XX\:MaxHeapSize\=512m -Xmx512m

Sol 3 Still, You have issue add below mentioned dependency:

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

Anyone solution will definitely work for you. Otherwise add all 3 in your application.

The accepted answer might work, but I'll share what fixed this with me. It was due to the maximum number of methods being reached after the addition of an additional library dependency.

See this guide here to fix, skip down to Configuring Your App for Multidex with Gradle section to get to the point.

None of the above worked for me, but this developer.android.come guide worked out for me:

https://developer.android.com/studio/build/multidex.html

It says the following:

If your minSdkVersion is set to 21 or higher, all you need to do is set multiDexEnabled to true in your module-level build.gradle file, as enter code hereshown here:

android {
    defaultConfig {
        ...
        minSdkVersion 21 
        targetSdkVersion 25
        multiDexEnabled true
    }
    ...
}

However, if your minSdkVersion is set to 20 or lower, then you must use the multidex support library as follows:

Modify the module-level build.gradle file to enable multidex and add the multidex library as a dependency, as shown here:

android {
    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 25
        multiDexEnabled true
    }
    ...
}

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

    minSdkVersion 16
    targetSdkVersion 25  

    multiDexEnabled true
}

Just set this in your app's build.gradle file

This works for me,

  1. In build.gradle, put your current android version as example 3.0.1

    dependencies { classpath 'com.android.tools.build:gradle:3.0.1'}

  2. In gradle-wrapper.properties, change your gradle version as example gradle-4.4 distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip

I hope this can help!

user3692429
 android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0"

    defaultConfig {
        ...
        minSdkVersion 14
        targetSdkVersion 23
        ...

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

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

    repositories {
    mavenCentral() }


    <application    ...
    android:largeHeap="true"
    android:supportsRtl="true"
    android:name="android.support.multidex.MultiDexApplication"> </application>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!