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

 

Could not resolve com.android.support:support-v4:22.0.0, Android Studio

While implementing Push Notifications, I get this error Could not resolve all dependencies for configuration

I’ve installed Google Play Services and Google Repository using SDK manager

not resolve

and added the following dependencies in gradle file

dependencies {
   compile 'com.google.android.gms:play-services-gcm:7.0.0'
   ....
}

When I run the app, I see following error,

Could not resolve all dependencies for configuration ':library:_debugCompile'.
> Could not resolve com.android.support:support-v4:22.0.0.
Required by:
:library:unspecified > com.google.android.gms:play-services:7.0.0 > com.google.android.gms:play-services-base:7.0.0
> No cached version of com.android.support:support-v4:22.0.0 available for offline mode.

After searching solution for a while, I found the issue is due to this  “You need to make sure you have Android Support Repository up to date – that is where Android Support Library dependencies are resolved.”

So, I installed Android Support Repository,

fix_issue
and Rebuild app… Fixed the issue.

Hope it helps somebody..

ref link: http://stackoverflow.com/a/29569756/341443

Jar mismatch! Fix your dependencies, ADT Eclipse

I see this exception Jar mismatch! Fix your dependencies, while working on a project in ADT Eclipse editor

In the logcat, I see as below

Found 2 versions of android-support-v4.jar in the dependency list,
but not all the versions are identical (check is based on SHA-1 only at this time).
All versions of the libraries must be the same at this time.

Solution for Jar mismatch

To fix this issue,

I followed following steps to fix

  • Right Click the project
  • Go To "Android Tools" > "Add Support Library"
  • Approve the permissions and let it update the library
  • If you have a library project, Repeat this process for the project App Library too.
  • Now Clean project and rebuild fixes the issue.

Jar mismatch

Hope it helps somebody

ref link: http://stackoverflow.com/a/24609733/341443

cheers 🙂

You may be also interested in