Reputation: 504
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.
Upvotes: 5
Views: 4343
Reputation: 47481
SDK/Extras
DirectoryUse your SDK Manager to download the Google Play Services - it'll be found under the Extras directory.
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/
Copy this entire directory to your project's libs
directory.
Add this as a module dependency as you normally would. (For Android Studio, see below for step-by-step instructions.)
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" />
Profit and Party?
Steps to add the library project as a module dependency once it's already in your libs
directory.
File > Import Module
.
Select the google-play-services_lib
directory under your libs
directory.
Ensure Create module from existing sources
is selected and click Next
until you finish the wizard.
Project Structure
> Modules
(far left) > Select Your App > Dependencies
tab > +
> Module Dependency
> google-play-services_lib
.
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.
Profit and Party?
Many thanks to Adama Speakman's post for the specific Android Studio steps.
JP
Upvotes: 6