I have a existing project say A which has dependencies over a few projects. Now I want to make this project A as a library project for Project B. What I have done so far is in the build.gradle of Project A, I have changed the plugin from "android:application" to "android:library", My question is how to use the project A as a library module to Project B. When i add a new Module and give its dependency to Project A the build files are not generated in the new module. If a create a new Project for B and then import Project A as a module i get errors on the dependencies used for Project A. Please suggest how to go about.
1 Answers
Edit build.gradle
of your module (not the root build.gradle).
Replace apply plugin: 'com.android.application'
with apply plugin: 'com.android.library'
.
Remove applicationId
from the same build.gradle project as described below:
defaultConfig {
applicationId "com.example.packageName"//remove this line
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
After this sync your gradle file. Now your project has been marked as library, but to create a release version of library you need to use this library into a module, so we will create a new module in the same project.
For creating new module go to:
File-> New Module-> (choose)phone and tablet Application->next...
Let's say the new module created is B. Now add dependency of library A on module B as described by user @Sam Rad here.
Run your project, after succesfull Run you will find a release version of library in folder
A->build->outputs-> (.aar package Release version)
Hope this will help

- 11,237
- 7
- 58
- 76

- 761
- 1
- 5
- 17
-
Before I do this I want a help. The Project A which I want to make as a Library is a application project which has many modules dependencies. I would be grateful if you could tell me how to convert this project into a library project first up. I have changed the plugin to android:application to android:library but it doesn't do all the trick. Kindly help me with this. – Saraschandraa Jun 30 '15 at 04:53
-
@Saraschandraa I have edited the answer and if you use the release version of library then it will provide all its dependencies alongwith – Adi Tiwari Jun 30 '15 at 12:49
-
every time i create the library module and then create a application module which has the dependency over the library module, I have problem with the R file. Can you help me out how to fix this. – Saraschandraa Jul 02 '15 at 07:07
-
1.Go to Build->clean project – Adi Tiwari Jul 03 '15 at 05:24
-
then go to File->invalidate caches and restrart->invalidate and restart – Adi Tiwari Jul 03 '15 at 05:25