简体   繁体   中英

Add play services dependency in Android AAR

I am trying to create android aar which uses play services. I have added playservices dependency in library gradle file. But when aar is exported in release mode runtime it is not working. How to add google play services in aar? Please help

You may want to check these steps in adding your library as a dependency :

  1. Add the library to your project in either of the following ways (if you created the library module within the same project, then it's already there and you can skip this step):

    • Add the compiled AAR (or JAR) file (the library must be already built):

      1. Click File > New > New Module .
      2. Click Import .JAR/.AAR Package then click Next .
      3. Enter the location of the compiled AAR or JAR file then click Finish .
    • Import the library module to your project (the library source becomes part of your project):

      1. Click File > New > Import Module .
      2. Enter the location of the library module directory then click Finish .

The library module is copied to your project, so you can actually edit the library code. If you want to maintain a single version of the library code, then this is probably not what you want and you should instead add the compiled AAR file as described above.

  1. Make sure the library is listed at the top of your settings.gradle file, as shown here for a library named "my-library-module":
include ':app', ':my-library-module'
  1. Open the app module's build.gradle file and add a new line to the dependencies block as shown in the following snippet:
dependencies {
    compile project(":my-library-module")
}
  1. Click Sync Project with Gradle Files .

But, if it's an app module that you want to reuse, you can turn it into a library module by following these steps to convert an app module to a library module :

  1. Open the module-level build.gradle file.
  2. Delete the line for the applicationId . Only an Android app module can define this.
  3. At the top of the file, you should see the following:

    apply plugin: 'com.android.application'

    Change it to the following:

    apply plugin: 'com.android.library'

  4. Save the file and click Tools > Android > Sync Project with Gradle Files .

For a more detailed information, see this documentation . Also. this related SO post can give additional insights.

As play-services now a days contains aar library instead of jar, we can not merge aar file with library ie another aar file. And, hence it is not possible to add play-services inside aar file. Best solution for this problem is who ever is using aar made by you, tell them to add play-services dependency in project.

  1. Add a new module to your project and select import .JAR/.AAR Package .
  2. After you added the module proceed like this : Project Structure → Select the app module → Dependencies tab → clieck the + button → select the module you added → Ok

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM