7

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')
    .
    .
}
Shehabic
  • 6,787
  • 9
  • 52
  • 93
  • 1
    I have the same question! Could you find an answer? – Dr. Ehsan Ali Sep 15 '15 at 06:48
  • 1
    Yes, I ended up doing something better, I'm so sorry that I'm short in time, but the best is to export this lib. as local maven repo, and in requirements use mavenLocal(); then refer to your lib. – Shehabic Dec 04 '15 at 13:03

3 Answers3

1

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.

jgvera
  • 21
  • 4
0

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.

Dr. Ehsan Ali
  • 4,735
  • 4
  • 23
  • 37
0

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.

nirav dinmali
  • 197
  • 11
  • This question is 4 years old, if it's part of the project nothing needs to be done, Gradle handles that for you, if it's an external module then mavenLocal() would be the way to go, pointing to a fixed direct wouldn't be a good idea. – Shehabic Jan 26 '19 at 22:01
  • Hi, can you please share why that would not be a good idea? My apps were 10 years old and I developed them in Eclipse. In the past week I started migrating all my apps to latest API and Android Studio and my approach is working for now. But want to know if any issues with it which I am overlooking. My library project is a separate project I developed and many of my apps which are individual projects use this library. – nirav dinmali Jan 28 '19 at 00:28
  • because a local directory like that exists on your current computer, if you change to a different computer or used any VCS then your path becomes invalid. – Shehabic Feb 03 '19 at 22:20