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
Import a module To import an existing module into your project, proceed as follows: Click File > New > Import Module. In the Source directory box, type or select the directory of the module(s) that you want to import: If you are importing one module, indicate its root directory.
In Android Studio, Right-clicking on the folder to add as library. Editing the dependencies in the build. gradle file, adding: compile fileTree(dir: 'libs', include: '*. jar')}
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:
./idea/modules/[module_name]
folder.)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')
build.gradle (:app)
file add dependency as:dependencies {
implementation project(':your_external_library_module_name')
implementation project(':perhaps_second_external_library')
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With