5

I have an existing project that was built without gradle for Android Studio and I'm trying to get Google Play Services imported to fix a java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable exception.

The only problem is it doesn't seem possible... I've considered porting it to gradle but the codebase is rather large (40+ Activities) and it would be a nightmare for someone like me, who's never used gradle before, to accomplish.

I've trying importing the Google Play Services project from the SDK but it hangs forever "creating gradle files".

Anyone have any experience loading this library to a non-gradle project before?

As an aside, I've tried loading the project into Eclipse to see if I could do something that way, but the build paths self-destruct to where I've spent hours trying to sort through them to no avail.

DranoMax
  • 474
  • 4
  • 18
  • "was built without gradle for Android Studio" -- AFAIK, all Android Studio builds go through Gradle. – CommonsWare May 09 '14 at 21:03
  • The amount of activities in your project doesn't make implementing Gradle any more complicated. It's very simple to switch to Gradle. – ashishduh May 09 '14 at 21:04
  • I use Google Play Services in AS without gradle in my current project - it was one I started in IntelliJ idea and ported over to AS (without gradle) when it came out last year. Adding the Play Services to my project was not a major issue for me (it did not hang on gradle files).I used some stuff from [this](http://stackoverflow.com/questions/17960315/importing-google-play-services-lib-into-intellij-idea-12-and-13) question to get it working. Or you could try using IntellJ instead of AS to add it and see if that makes a difference. – free3dom May 10 '14 at 13:21

1 Answers1

6

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

Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
  • Hi, I am having trouble at step 2. After specifying the `google-play-services_lib` directory, it doesn't enable the next button, like [this](http://tinypic.com/r/ei8ak7/8). Please help if you can. – Khanh Nguyen Sep 02 '14 at 03:38
  • Are you on Android Studio? Which version? – Joshua Pinter Sep 02 '14 at 18:04
  • I solved it by adding a build.gradle file into the `google-play-services_lib` folder. Looks like AS bases on this file to detect whether it's a valid module or not. Thanks anyway. – Khanh Nguyen Sep 03 '14 at 02:25
  • Also from AS 0.4.2 onwards, there's a simpler way: [http://stackoverflow.com/questions/16624827/android-studio-with-google-play-services](http://stackoverflow.com/questions/16624827/android-studio-with-google-play-services). – Khanh Nguyen Sep 03 '14 at 02:26
  • 1
    @KhanhNguyen Glad you found the solution. That "easier" method you linked to only applies if you're using Gradle, which I'm not and the original question title includes "non-gradle". ;) – Joshua Pinter Sep 03 '14 at 18:32
  • According to @Kurt, if the "Create module from existing sources" isn't available in Step 3 of the Android Studio instructions, you can just copy the `google-play_services.jar` into your `libs` directory and then right click on the `.jar` and choose "Add As Library". Thanks Kurt! – Joshua Pinter Apr 10 '15 at 16:58
  • 1
    Is this still possible in 2018? Seems like it's missing the `libproject` library in the SDK/extras/google folder. – TankorSmash Jan 06 '18 at 04:15