Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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')
    .
    .
}
like image 211
Shehabic Avatar asked Nov 16 '14 22:11

Shehabic


1 Answers

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.

like image 68
jgvera Avatar answered Nov 15 '22 00:11

jgvera