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.NoClassDefFoundErr
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