Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...