1

I want to include a module A into Module B. Module A's build.gradle includes packackingOptions that need to be executed. These packackingOptions are executed when I build module A. They are not executed when I build module B, which imports module A.

How can I make sure that the packackingOptions from module A's build.gradle are also executed when importing module A into module B?

Module B's build.gradle looks like this:

dependencies {
  implementation project(':A')
}

Module A's build.gradle looks like this:

android {
 packagingOptions {
        pickFirst 'assets/**'
    }
}
heslegend
  • 86
  • 8
  • Does this answer your question? [how to reference an asset in a library project](https://stackoverflow.com/questions/6346889/how-to-reference-an-asset-in-a-library-project) – JensV Apr 14 '20 at 09:36
  • No, in module A I have two third party dependencies that contain identical assets. Therefore i have to tell gradle to only pick one of the duplicate assets. – heslegend Apr 14 '20 at 09:44
  • Huh, and the assets actually get included from the library? I never managed to do that, can you elaborate on how you do this? Also can you describe the dependency graph a bit more and which module contain what? – JensV Apr 14 '20 at 09:47
  • 1
    Nevermind on the first part, apparently it's possible with gradle now – JensV Apr 14 '20 at 09:48

1 Answers1

0

I set up the project structure as follows:

buildscript-test-app
         |
         |
buildscript-test-lib
 |             \------------------------\
 |                                      |
buildscript-test-lib-sub-a    buildscript-test-lib-sub-b

Both lib-sub-* contain assets/foo.txt with different contents.

build.gradle of buildscript-test-lib:

apply plugin: 'com.android.library'

android {
    // omitted default config stuff

    packagingOptions {
        pickFirst 'assets/**'
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation project(':buildscript-test-lib-sub-a')
    implementation project(':buildscript-test-lib-sub-b')
}

build.gradle of buildscript-test-app:

apply plugin: 'com.android.application'

android {
    // omitted default config stuff
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation project(':buildscript-test-lib')
}

Gradle always picks the file from buildscript-test-lib-sub-a regardless of the order of dependencies (presumably because of alphabetic ordering).

Something else in your buildscript must be wrong if this doesn't work. If it doesn't work, can you provide more details on the build.gradle of your app module and library modules?

Maybe you are overriding pickFirsts in your app. If that's the case, you should instead of pickFirsts = [somevalue] do pickFirst += 'foo' or pickFirst = 'foo'

JensV
  • 3,997
  • 2
  • 19
  • 43