1

I could use a little help better understanding the options I have with regards to adding a dependency on an Android library that has been published locally.

In my situation, I have two different projects located in two different directories:

Project of Library: ~/Documents/src/<my library>
Project that will consume library: ~/Documents/src/<client app>

I followed the instructions provided here in order to publish the android library locally:

http://blog.maxaller.name/android/2016/11/25/developing-a-local-android-plugin.html

I'm going to assume that the output library generated ended up here:

~/Documents/src/<my library>/library/build/outputs/aar/*.aar

It'd be nice if I can point directly to this library.

What options do I have in order to update the build.gradle file of the client app such that there is a dependency on that library?

Below is the key pieces of the build.gradle file, as it currently stands:

    buildscript {
        repositories {
            mavenCentral()
            mavenLocal()
            jcenter()
        }
...

dependencies {
... 
   ???implementation <my group ID>:<my artifact ID>:<version #>??

   OR

    implementation project(path: '<What am I doing?>')
...
}

I must troubleshoot a few things before publishing the library online.

Thanks for the clarification in advance!

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Coach Roebuck
  • 904
  • 2
  • 12
  • 20
  • Maybe [this post](https://stackoverflow.com/questions/24149690/add-local-library-project-as-a-dependency-to-multiple-projects-in-android-studio) is helpful? – Bö macht Blau Apr 06 '18 at 16:45
  • Thanks for that link. That is part of what is required. Go ahead and provide an "answer", and I'll check off your answer. It looks like I can import that *.aar file using Android Studio, which will automatically included those lines into my gradle file: https://stackoverflow.com/questions/16682847/how-to-manually-include-external-aar-package-using-new-gradle-android-build-syst – Coach Roebuck Apr 06 '18 at 17:06
  • You're welcome! but I think it's better (for others in the same situation) if you write down how you managed to solve the whole problem. – Bö macht Blau Apr 06 '18 at 17:12
  • That's a good idea. Thank God for Source Control! I can actually review my own work! – Coach Roebuck Apr 06 '18 at 19:26
  • [Stack Overflow's point of view](https://stackoverflow.com/help/self-answer) on answering one's own question. BTW, the reviewing will be done by everyone who does [not] vote on your question or your answer. Your accepting your own answer just says it worked for you, case closed. – Bö macht Blau Apr 06 '18 at 19:45

1 Answers1

1

Discovered that there are options to solve my problem.

I like Option # 1:

I. From the top menu: File -> New Module -> Import .JAR/.AAR -> Follow subsequent instructions.

   A few things will automatically be done for you:

  • The folder named after the *.aar selected will be created.
  • A build.gradle file will also be created inside that folder.
  • Your library will automatically be added to the directory.
  • Your module will be added to the settings.gradle file.

II. Track down the build.gradle of your client app and add this line:

implementation project(':<Your Module Name>')

Given the circumstances of the client app I was working on, I was forced to add that dependency in two different modules.

Reference: How to add .aar dependency in library module?

Option # 2: I can't confirm this approach, but it looks like another acceptable solution.

How to manually include external aar package using new Gradle Android Build System

Coach Roebuck
  • 904
  • 2
  • 12
  • 20