I have created my custom android library and now wants to use this library in another project. Here is what I did so far:
Created a library project in Android Studio. Build that project, so .aar file was generated like: ..\MyApplication\mylibrary\build\outputs\aar\mylibrary-release.aar
Created a new Android project in Android Studio. Then, I followed this:
app<<Created a library project in Android Studio. Build that project, so .aar file was generated like: ..\MyApplication\mylibrary\build\outputs\aar\mylibrary-debug.aar
Created a new Android project in Android Studio. Then, I followed this:
Created a libs directory under the app and paste the .aar file. This is the structure in my project:
Navigate to File > Project Structure > Dependencies.then click + and select Jar Dependency in the dropdown.
In the Add Jar/Aar Dependency dialog, added the path of the .aar file and select the "implementation" configuration.
added implementation files('my_path/my_lib.aar') in build.config file
Now, if I try to use class name of my Library project. There is one class MPPush.java in my library project. I am not able to see MyClass. It shows No suggestions instead.
I am using Android studio Arctic Fox. Am I missing some configuration?
Related
I have jar file(use like library) in lib folder in android studio project.
I added another android studio project to the first project.
Added another project steps: File -> New -> Import Module.
I want to use with the file jar from the first project in the another project that I added.
How can I do this?
you should add that library again to your new project by following this file -> new -> import module.
While I develop an Android App, I have a library which I have created as separate Android Studio project and can use it by inserting it into new projects. I insert the library by choosing 'File|New|Import Module...' option.
The thing is that after the import, Gradle creates a hard copy of my library. If I change the library code in main external project, the code inside the project which is using the library won't get updated.
How can I have a library and share it among many project? I need to change the library in one single place and then all other projects which are using it get the update.
I found this post also which has no answer:
How to update imported modules with code modification from the their external library project in Gradle/Android Studio
OK I found the answer by myself:
You must not add the external library as an existing module. It will make a copy of it under your project folder.
What you have to do is:
Delete the library folder in your current project. (You can also delete the ./idea/modules/[module_name] folder.)
Open the setting.gradle file and add these:
include ':your_external_library_module_name'
project (':your_external_library_module_name').projectDir = new File('../path/to/your/external/library')
include ':perhaps_second_external_library'
project (':perhaps_second_external_library').projectDir = new File('../path/to/your/second/external/library')
In your build.gradle (:app) file add dependency as:
dependencies {
implementation project(':your_external_library_module_name')
implementation project(':perhaps_second_external_library')
}
Sync the project and you are done.
Creating a standalone library application is a common task in Eclipse + ADT.
I thought that this should be a simple task in Android Studio (1.2 or above), but after struggling with this problem for two days, I figured out that google did nothing about this and implementing a standalone library module is not as simple as I thought. So I decided to share my experiences with you.
To create a standalone and reusable library module in Android Studio:
1- Create a new project with no Activity.
2- New project's default module is named app. Right click on module and refactor/rename it to something like 'library'. Close Android Studio.
3- Open file explorer and rename module's folder from app to library.
4- Open .idea folder. There are some XML files there that have references to app folder. Replace app into library in these files.
5- Open module's gradle file (library/build.gradle) and change plugin to com.android.library. Then remove applicationId.
6- Open Android Studio. Rebuild module. If there is no error, we are done here.
7- Open application which is dependent on that module. Open settings.gradle and include library module as below:
include ':library'
project(':library').projectDir = new File('/Path/To/LibraryProject/library')
8- Open application's app module build.gradle file and add this line into dependencies section:
compile project(':library')
9- Rebuild your project. If everything is right, you will see library module in your project. You can edit library module from there and/or its project and more important: Now you have a standalone library module that you can reuse in multiple projects!
I hope google will make this process a lot easier in future releases of Android Studio!
EDIT:
I checked Android Studio version 1.4 and hopefully in this version we can omit steps 3 and 4.
i am a android app developer and converting myself from Eclipse to Android Studio.
Now i get a difficulty to add library project into another project.
What i can do in Eclipse is very clear:
1.Set project B as library Project (right click->properties->android->is Library)
2.Add this library into Project A (right click->Properties->android->add...->choose Project B->OK
But how can i execute such behavior in AS?
I read article
Create a standalone library with Android Studio
and Create Project A as Library in AS.
Now i create Project B in AS with module BApp,
how can i add Library Project A into B/BApp?
The reason i would not like to copy files of Project A to Project B is, I would also use Library Project A in my many other Project. I dont think it is a good idea that make a hard copy to each Project while i will always update Library A in local.
Appreciation for the Help!
You have to go to Project Structure and add the library as a new module. To do this click on the + icon and select Import Existing Project, once the module is imported go to the Dependencies tab, click on the + icon and select Module Dependency and click on your library.
I added the Google Gson jar file to my Android project by copying and pasting the gson-2.2.4 jar file to the libs folder and then right clicked on the Jar file and then select Build Path > Add to Build Path(I followed this tutorial). Then everything worked fine for me with this jar file, but after pushing to github, when my friends pulling this project, they said that all code relevant to that Gson jar file shows errors. How could I fix this?
Problem 1 : Jar doesnt exist. You probably forgot to add, commit and push your changes to github after adding the jar.
Problem 2 : Jar exists but unrecognised. Ask your friends to remove the existing library from java build path using project properties and add again.
You can create a library project which contains the jar file, and then add this library to your project.
Create library project in eclipse:
File->New->Android application project->Next->Check Mark this porject as a library,
uncheck Create custom launcher icon and Create activity->Finish
Add the library to your project:
Right click your project->Properties->Android->Add->Select the library project you created
->Apply->OK
After finishing these two, you should be able to use Gson, and when pushing your project,
remember to push the library project as well.