简体   繁体   中英

How to update imported modules with code modification from the their external library project in Gradle/Android Studio

I'm developing an android app, in which I recently migrated from Eclipse to Android Studio and Gradle.

In my projected I created 5 UI Libs, and added them as modules in my project, libs I have created are pushed on my github account (publicly).

In eclipse when you add external dependency for a project marked as lib, when you update the external project's code then you clean your build, your project get these updates, but in Gradle I noticed that it creates Physical Copies, completely independent from their sources, my question is how can I change only external libs and have my project updated.

here's a snipped from my gradle's config:

dependencies {
    // Libraries
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:5.0.89'
    .
    .
    . 
    compile 'com.squareup.picasso:picasso:2.4.0'

    // Projects
    compile project(':com.shehabic.helpicon')
    .
    .
}

How to actually use external libraries

I've read that is not recommended but it is practical for debugging:

  1. File > Project Structure... > PLUS sign to add module

  2. "Create New Module" dialogs:

    • Select "Import .JAR/.AAR Package"
    • Find and select your package but copy the path before continue
    • Name your package
  3. Back at "Project Structure" dialog:

    • The message "Gradle project sync in progress.." appears, but it takes to click OK for the build to actually start. Instead, you can continue with the dependency.
    • Select "app" module, go to DEPENDENCIES tab, and PLUS sign to add MODULE DEPENDENCY
    • Select your module
    • Click OK for the build to run.

That does create a copy of your package inside your android project but it also generates all necessary information and files, and you can always get rid of the copy or leave it alone.

Your module have been added to the settings.gradle file:

':app', ':module_name'

A build.gradle file for your module have been created:

configurations.maybeCreate("default")
artifacts.add("default", file('package.jar'))

And the dependency has been added to the build.gradle of your ':app':

compile project(':module_name')
  1. Now, access the build.gradle file of your added module and paste the path you copied:

configurations.maybeCreate("default") artifacts.add("default", file('X:\\Java\\Applications\\YourApplication\\dist\\package.jar'))

Wherever you edit your package, just "Clean & Build" it. Whenever you want your app to reflect that "update" in the package from outside your android project, just sync. When you are done debugging, you can remove the module, the dependency and the old copy, and add the last build of your package as a copy.

You must not add the external library as a module. It will make copy of it under your project folder.

What you have to do is:

1) Delete the library folder in your current project. 2) Open the 'seeting.gradle' file and add these:

include ':your_external_library_module_name', ':perhaps_second_external_library'

project (':your_external_library_module_name').projectDir = new File('../path/to/your/external/library')
project (':perhaps_second_external_library').projectDir = new File('../path/to/your/second/external/library')

2) In your 'build.gradle' file add dependency as:

dependencies {
    compile project(':your_external_library_module_name')
    compile project(':perhaps_second_external_library')
}

3) Sync the project and you are done.

Do NOT add a module using Studio's "Open Module Settings".

Just add the full path of your library's AAR file in your child app's build gradle:

implementation files('/workspace/AndroidAppsBase/base_app/build/outputs/aar/base_app-debug.aar')

When you make changes to your library project and rebuild the project, a new .aar file will be created. To reflect the change in your child project just rebuild it.

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