1

I have an Android Instant App with following structure:

  • B: base module
  • Installed: installed app module
  • Instant: instant app module
  • F: feature with functional specific to Installed app. F depends on local aar library local-lib located in project\F\libs.

F's build.gradle is following:

repositories {
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    api ":local-lib@aar"
}

I tried to include F module to Installed app module like this:

dependencies {
    implementation project(':B')
    implementation project(':F')
}

But gradle couldn't resolve local-lib, giving error:

Error:Could not resolve all dependencies for configuration ':Installed:releaseCompileClasspath'.
> Could not find :local-lib:.
  Searched in the following locations:

      ... some remote repositories ...

  Required by:
      project :Installed > project :F

I tried to duplicate libs folder to project\Installed\libs, and it worked. So basically I need 2 copies of local-lib to make this work? How should I organise imports to avoid duplication? Perfect case would be if libs folder was inside F module.

mol
  • 2,607
  • 4
  • 21
  • 40

1 Answers1

1

IMHO, the cleanest way to make it work would be to use some local repository, like a Maven, publish your local-lib here, and reference it from here, and do the same for each of your libraries. When you publish to an artifact repository manager - let's say a Maven - you will have your .aar coupled with a pom file, containing all the needed dependencies.

You have to keep in mind here that your aar is kind of a flat file, meaning, while you reference it somewhere, there is not way to keep track of the transitive dependencies of it (that's the job of the pom files on Maven).

This means that when you reference F in Installed, the F aar is added, but Installed doesn't know that it has to get local-lib in order for F to work properly, or doesn't know where. That's why you have lines on the remote repositories: gradle searches everywhere (in every possible place = in every repository you have listed) for the dependency.

When you copy/paste the code as a module of your project, the gradle knows what are the transitive dependencies because it can access the gradle file for each dependency.

When you copy the aar directly inthe Installed/libs folder, it also works because gradle checks here (you probably have a compile line in your gradle checking for that folder).

If you want to keep the flat file, you should try putting somewhere reachable by all modules, on the same folder level (take a look at that question), or you could try to add the local-lib as an Android module project, and not just put it in the libs folder.

w00ly
  • 455
  • 1
  • 5
  • 18
  • Thanks for detailed explanation! – mol May 31 '17 at 13:59
  • Thanks for the accepted answer ;) If you choose to go for maven, take a look at: https://jeroenmols.com/blog/2015/08/06/artifactory/ and be careful about the pom generation (dependencies are not generated by default) – w00ly May 31 '17 at 14:21