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
3 Answers
You may want to check these steps in adding your library as a dependency:
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):
- Click File > New > New Module.
- Click Import .JAR/.AAR Package then click Next.
- 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):
- Click File > New > Import Module.
- 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.
- 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'
- 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")
}
- 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:
- Open the module-level
build.gradle
file. - Delete the line for the
applicationId
. Only an Android app module can define this. 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'
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.

- 7,686
- 3
- 15
- 22
-
Though it's a great explanation for adding module as a dependency, but it was not useful for me for the reasons I stated below. – Anuja Kothekar Jul 12 '17 at 17:58
As play-services now a days contains aar library instead of jar, we can not merge aar file with library i.e. 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.

- 2,537
- 2
- 15
- 28
- Add a new module to your project and select import .JAR/.AAR Package.
- 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

- 2,376
- 2
- 24
- 38