5 Dec 2015

Seeing java.lang.OutOfMemoryError : GC overhead limit when compiling

You are most likely exhausting the heap size especially during compilation. Try to add inside this setting in your app/build.gradle:

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

You can also reduce the build time too by setting incremental to be true:

android {
   dexOptions { 
      incremental true
      javaMaxHeapSize "4g"
   }
}

Still not working? Try to increase the heap size of Android Studio.
  1. Quit Android Studio.
  2. Create or edit a studio.vmoptions file.
    • On Mac, this file should be in ~/Library/Preferences/AndroidStudio/studio.vmoptions.
    • On Windows, it should be in %USERPROFILE%\.AndroidStudio\studio[64].exe.vmoptions.
    Increase the maximum memory to 2 Gb and max heap size of 1 Gb.
     -Xmx2048m
     -XX:MaxPermSize=1024m`
    
  3. Start Android Studio.
Read More !

28 Nov 2015

Getting "com.android.dex.DexException: Multiple dex files define"

One of the issues in the new Gradle build system is that you can often get "Multiple dex files define" issues.

If a library is included twice as a dependency you will encounter this issue. Review the libs folder for JARS and the gradle file at app/build.gradle and see if you can identify the library dependency that has been loaded into your application twice.

If one dependency library already includes an identical set of libraries, then you may have to make changes to your Gradle configurations to avoid this conflict. This problem usually happens when there are multiple third-party libraries integrated into your code base.

Another error if you attempt to include a library that is a subset of another library. For instance, suppose we included the Google play-services library but thought we also needed to include it with the play-services-map library.:

dependencies {
    compile 'com.google.android.gms:play-services:6.5.+'
    compile 'com.google.android.gms:play-services-maps:6.5.+'
}

It turns out that having both is redundant and will cause errors. It is necessary in this case to remove one or the other, depending on your need to use other Google API libraries.
Read More !

16 Nov 2015

Getting "tooling.GradleConnectionException" errors

If you see org.gradle.tooling.GradleConnectionException errors, you may need to install a newer version of JDK (there have been reports of 1.7.0_71 having this issue). First try to restart the adb server first.
Amar's Android Tech

Read More !

7 Nov 2015

Getting "failed to find Build Tools revision x.x.x"

If you're opening another Android Studio project and the project fails to compile, you may see "failed to find Build Tools revision x.x.x" at the bottom of the screen. 
Since this package is constantly being changed, it should be no surprise that other people who have installed Android Studio may have different versions. You can either click the link below to install this specific Build Tools version, or you can modify the build.gradle file to match the version you currently have installed.
Amar's Android Tech

Read More !

26 Oct 2015

Seeing Unsupported major.minor version 52.0 on some plugins

Some Android Studio plugins do not support Java 1.6 anymore, so it's best to confirm what version you are using. Inside Android Studio, click on About Android Studio. You should see the JRE version listed as 1.x.x below :
Amar's Android Tech
If you have multiple Java versions installed, you should make sure that v1.6 is not being used.
On OS X machines, you can remove the JDK from being noticed. You can move it the temporary directory in case other issues are created by this change.
sudo mv /System/Library/Java/JavaVirtualMachines/1.6.0.jdk /tmp
Read More !

17 Oct 2015

Unable to delete emulator getting "AVD is currently running in the Emulator"

Open the Tools => Android => AVD Manager and select virtual device that you want to delete. Click on the down arrow at the end and select the [Show on Disk] option which will open the emulator directory. Inside the [Your Device].avd folder, locate any *.lock files and delete them. You can now delete the emulator.
Read More !

10 Oct 2015

Android Studio is Crashing or Freezing Up

If Android Studio starts freezing up or crashing even after rebooting the IDE or your computer, your Studio has likely become corrupted. The best way to resolve this is to clear all the caches by removing all the following folders:

~/Library/Application Support/AndroidStudio
~/Library/Caches/AndroidStudio
~/Library/Logs/AndroidStudio
~/Library/Preferences/AndroidStudio

and then uninstall Android Studio and re-install the latest stable version. This should allow you to boot Android Studio again without errors.
Read More !

5 Oct 2015

Add application shortcut to the home screen

In this post, I will be discussing about how to create shortcut for Android applications programmatically.
What is Android Shortcut?
Android allows you to create app shortcuts, but you can also create special shortcuts that link directly to screens within an app. For example, shortcuts could link to the Navigation screen in Maps or any screen in the Settings app.
To Create Shortcut
It is very simple to create shortcut programmatically, all you need to do is broadcast the intent with necessary information.
Below code snippet will create the shortcut.
//create shortcuts of app
        Intent HomeScreenShortCut= new Intent(getApplicationContext(),
                MainActivity.class);
        HomeScreenShortCut.setAction(Intent.ACTION_MAIN);
        HomeScreenShortCut.putExtra("duplicate", false);
        //shortcutIntent is added with addIntent
        Intent addIntent = new Intent();
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, HomeScreenShortCut);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Matrialtest");
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                Intent.ShortcutIconResource.fromContext(getApplicationContext(),
                               R.drawable.ic_launcher));
        addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        getApplicationContext().sendBroadcast(addIntent);

Add add this permission to your manifest

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
That’s all. It’s time to test our code.
Run the application using emulator or device by right clicking on the project >> Run as >> Android application >> Choose emulator or device.
Read More !

28 Sept 2015

Error:failed to find Build Tools revision 23.0.0 rc2


Going crazy with this error from about a couple of hours.

The error is:

failed to find Build Tools revision 23.0.0 rc1
But I think to have all update



I could fix it by changing it to

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.0"
}
in build.gradle file

Open the SDK Manager and find the version of the Android SDK Build-tools which is installed and that you want to use. Then go to Gradle Scripts > build.gradle (Module: app). Set the buildToolsVersion to your version.
There is an easier solution. "Right click on the project > Open Module Settings. Choose the Complie Sdk Version and Build Tools Version you want to use".
Read More !

25 Sept 2015

Cannot locate factory for objects of type DefaultGradleConnector, as ConnectorServiceRegistry has been closed.

I get this error when trying to run my App on Android Studio.


Gradle 'MyApp' refresh failed.
Error:Cannot locate factory for objects of type DefaultGradleConnector, as ConnectorServiceRegistry has been closed.

Just Restarting Android Studio usually fixes this error for me.

Read More !