Android StudioGradle

Issues after updating to Android Studio 2.0v

In this post, I just like to sum up all the issues faced after updating Android version.

After updating to Android Studio 2.0v, you may see following issues.

You’ll be asked to install latest gradle version to enable Instant Run. you think it helps and installs the latest Gradle version.

Now, your problems starts You may be able build project. But couldn’t able to run the project. When you run the project, you’ll see Out of memory exception as below. 😐

Error:java.lang.OutOfMemoryError: Java heap space.
Please assign more memory to Gradle in the project's gradle.properties file.
For example, the following line, in the gradle.properties file, sets the maximum Java heap size to 1,024 MB:
<em>org.gradle.jvmargs=-Xmx1024m</em>
<a href="http://www.gradle.org/docs/current/userguide/build_environment.html">Read Gradle's configuration guide</a><br><a href="http://docs.oracle.com/javase/7/docs/technotes/guides/vm/gc-ergonomics.html">Read about Java's heap size</a>

I tried different ways to increase the memory, like changing the memory values in gradle.properties file

org.gradle.jvmargs=-Xmx2048m -XX\:MaxPermSize\=512m

and changing values in studio64.exe.vmoptions file in C:\Program Files\Android\Android Studio\bin folder

-Xms512m
-Xmx2048m

but not worked. 🙁

The only thing that worked for me is adding javaMaxHeapSize value of dexOptions in app’s build.gradle file.

android{
  ....
  ....
  dexOptions {
     javaMaxHeapSize "2g"
  }
}

this fixes the OutOfMemoryError issue. The reason for this issue is the latest version gradle needs more memory to build the app.

And after fixing You may see Multiple dex files issue. For me I get this error

Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/zxing/BarcodeFormat;  😮

I tried following to fix this issue

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

Which resulted same issue in different way 😡

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/zxing/BarcodeFormat.class

in inconsistent location 'C:\Users\employee2\AppData\Local\Android\sdk\add-ons\addon-google_apis-google-19-1'
(Expected 'C:\Users\employee2\AppData\Local\Android\sdk\add-ons\addon-google_apis-google-19')

Error:Error converting bytecode to dex:

So, I removed that multiDexEnabled true line and search for the BarcodeFormat class usage in project. I finally find out that same dependencies library added in module’s and app’s  build.gradle file. I just commented dependencies library in app’s build.gradle file fixed the issue.  😎

So, finally After fixing all issues and you’ll be able to run the app. 

And then, now you made some code changes and run the app. App won’t run on device with latest code changes. In the Android Studio Run tab you’ll see “No changes”.  What! 😮

The reason for this Instant Run not recognizes certain code changes, and it also needs latest android API.

instant_run

So, the only option to see your code changes effect in app and run on device, is disable Instant Run. Please see following image to disable

after updating

That’s it now you able to see code changes by running the app on device.  😎

Hope it saves somebodies time. 💡

You may also interested in

Leave a Reply

Your email address will not be published.