Importing Google-Play-Services Lib into Intellij Idea 12 (And 13)

Importing google-play-services lib into Intellij IDEA 12 (and 13)

For historical reasons, I'm going to reproduce what I did, taken from here. Many thanks to @Hesam who found it. I will vote to close the whole question.

Note: the shortcuts are for OS X and Intellij 12 and 13.

Make sure you have the latest SDK/ADT Tools and the play services. They change every now and then and are usually not backwards compatible.

UPDATE I had to do this again, so this is the polished version of what I did.

You need to have a copy (as opposed to using it directly from the SDK folder), because if Google updates it, things are going to break when you update your SDK, it's safer to keep a copy (albeit more tedious because you will have to manually update when a new version comes out). I found out that it's better to decide when to update than to be surprised with cryptic compilation errors.

With that in mind, copy the library alongside your project. You should have a folder structure that looks like:

/something/yourmainmodule/

/something/any_other_module/

/something/modules.xml

/something/README.md (if you use github) :)

The library is located in

"ANDROID-SDK"/extras/google/google_play_services/libproject/google-play-services_lib

ANDROID-SDK is wherever you stored the SDK when you downloaded it. Google changes this every now and then, so just find it, it will be there.

Copy that entire folder so your project now looks like this:

/something/yourmainmodule/

/something/any_other_module/

/something/google-play-services_lib/ <-- THIS IS THE NEW ONE

/something/modules.xml

/something/README.md

Good, now let's import it to IntelliJ-IDEA the right way:

1) Select your project/main module from project panel (⌘ 1) and hit ⌘ ↓ in order to open project structure window or just do File -> Project Structure.

2) Select Modules from left panel, then hit + button (or ⌘ N) then select "import module" and navigate to the google-play-services_lib that you just copied next to your project's module folder. (/something/).

The wizard will ask a series of questions, just hit next, defaults are fine, but read what's going on, understand what's happening, this is a core concept in Java, Android and Intellij. Experiment if you don't know what each dialog is saying (or why some may be empty).

After you're done, the google play Project will be added to Modules alongside with your project.

Don't close this window (or open it again if you did).

3) Still in the modules, select your project/module, then select "Dependencies" from right panel (it's a tab) and finally Click + button at the bottom (or ⌘ N which will work if you have the focus in this tab), then from the popup chose "3 Module dependencies..." and select "google-play-services_lib", which you added in the previous step. It should be there. If it's not, you didn't add the module in step 2.

4) Finally, Click + button again (or ⌘ N) but this time select "1 jars or directories...", navigate to the "/libs" folder of the above path and select "google-play-services.jar".

5) Click ok and close project structure window.

If you did this, your main module should have a dependency that looks like this:

Dependencies

Also make sure that in the Project Structure window, FACETS Tab, the Google Play Services has the "Library Module" checked. It is a library module.

Note: Make sure you have not added "google-play-services_lib" project as library in "Libraries" (left panel under Modules). If you have, you can go to "Libraries and simply remove it. Google Play Library Should Not Appear In Libraries.

Credit: this text comes from this StackOverflow answer

How to add google play services in IntelliJ IDEA 13 with gradle

There could be several things going on here:

  • You don't have installed the Google Play Services extra from the SDK Manager. So you can go there and install it. (Not just Google Repository, but Google Play Services itself)
  • If you got the extra installed, but Studio doesn't recognize it, maybe you're pinpointing the wrong SDK. It happens that Android Studio had its own pre-bundled SDK, so, if you got another one installed on your computer, you may be installing the extras in that one, and AS is triying to build with the one that has not the extras installed.

Check it out in Files>ProjectStructure and make sure you got the right SDK.

Adding Google Play Services to non-gradle Android Studio project?

Copy the library from the SDK/Extras Directory

  1. Use your SDK Manager to download the Google Play Services - it'll be found under the Extras directory.

  2. Go to your Android SDK directory and find the google-play-services_lib directory, for me this was in the Android Studio package:

    /Applications/Android Studio.app/sdk/extras/google/google_play_services/libproject/google-play-services_lib/

  3. Copy this entire directory to your project's libs directory.

  4. Add this as a module dependency as you normally would. (For Android Studio, see below for step-by-step instructions.)

  5. You'll need to add a meta-tag to your AndroidManifest.xml file as well, that looks like this:

    <meta-data android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

  6. Profit and Party?

Android Studio Steps

Steps to add the library project as a module dependency once it's already in your libs directory.

  1. File > Import Module.

  2. Select the google-play-services_lib directory under your libs directory.

  3. Ensure Create module from existing sources is selected and click Next until you finish the wizard.

  4. Project Structure > Modules (far left) > Select Your App > Dependencies tab > + > Module Dependency > google-play-services_lib.

  5. Project Structure > Modules (far left) > Select google-play-services_lib > Dependencies tab > + > Jars or directories... > Find and select libs/google-play-services_lib/libs/google-play-services.jar.

    Make sure you click the Export checkbox for this dependency.

    Check the Export checkbox

  6. Profit and Party?

Many thanks to Adama Speakman's post for the specific Android Studio steps.

JP

How to implement Google Play Game Services, Intellij, libgdx

There is a tutorial on libgdx wiki.

Installing the "Google Play Repository" from Android SDK manager should be enough. There is no need to move the google-play-services_lib folder.

My android project definition in root/bulild.gradle:

project(":android") {
apply plugin: "android"

configurations { natives }

dependencies {
compile project(":core")
compile project(":libraries:BaseGameUtils")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
compile 'com.android.support:appcompat-v7:20.0.+'
compile 'com.android.support:support-v4:20.0.+'
compile 'com.google.android.gms:play-services:5.0+'
}

}

LogCat message: The Google Play services resources were not found. Check your project configuration to ensure that the resources are included

This is a bug in the Google Play services library, and it is filed here under issue 755.

Unfortunately, there isn't any solution yet.



Related Topics



Leave a reply



Submit