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

后端 未结 1 802
夕颜
夕颜 2020-12-17 03:33

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

相关标签:
1条回答
  • 2020-12-17 04:22

    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

    0 讨论(0)
提交回复
热议问题