torsdag 12 juni 2014

Android : Importing Google Play Services API in IntelliJ IDEA


I'll be using an gradle built Android module. First create an empty Android project.

Now we need to setup the dependecies, http://developer.android.com/google/play-services/setup.html.
This first way is the easy way, edit the 'build.gradle' in the DriveTest directory and add:
dependencies {
    compile 'com.android.support:appcompat-v7:19.+'
    compile 'com.google.android.gms:play-services:4.4.52'
}

Lastly open the AndroidManifest.xml for the Android module and add the following as a child under the <application> tag:
<meta-data android:name="com.google.android.gms.version"
                   android:value="@integer/google_play_services_version" />

Afterwards you should be able to auto-complete the dependencies in the IDE.

Another way is to copy the file from 'sdk\extras\google\m2repository\com\google\android\gms\play-services\4.4.52\play-services-4.4.52.aar' to your android modules lib folder then update your build.gradle scripts with the following :
repositories {
    flatDir()
            {
                dirs 'libs'
            }
}
dependencies {
    compile ':play-services:4.4.52@aar'
}



Troubleshooting :
Make sure you have the following installed in the Android SDK.

Be sure to check min-sdk version in your AndroidManifest.xml and build.gradle files. 9 at least.

Remember that Google Play Services work inside the emulator these days, just make an AVD that runs the Google APIs with version 4.2.2 and above. Just be sure to sign the application, i use the command line when installing a signed package as IDEA has no auto-installation when building. (what i've found)

Quickest route for me, uninstalling my debug installation first. Then installing the signed release.