Take as a starting point the Android Dev Docs on how to use native dependencies with the Android Gradle plugin. Also of interest, though not primarily aiming at native dependencies, are the chapters on how to fix dependency resolution errors and on applying custom build logic.
So, lets take a look at your specific problems.
Duplicate File Conflict
You habe two libc++_shared.so
files, with identical name and path. The Android Dev Docs (see above) suggest:
To resolve this issue, remove one of the binary dependencies
Note, that you actually did that by using pickFirst
and that your problem with libc++_shared.so
has been solved and shifted to another library. But pickFirst
as such unluckily affected the further decisions of Gradle.
So change your packagingOptions
to pick first a specific file with pickFirst 'lib/arm64-v8a/libc++_shared.so'
. Alternatively you can use exclude 'lib/arm64-v8a/libc++_shared.so'
, which semantically excludes further (duplicate) files of that name after it has been added to your APK.
Strictly speaking exclude
and pickFirst
are now deprecated. If I'm not mistaken it's now resources.excludes
and resources.pickFirsts
, used as:
packagingOptions {
resources.excludes += 'foo'
resources.excludes += 'bar'
// or:
// resources.excludes += setOf(
// 'foo',
// 'bar'
// )
}
Version Conflicts
You mentioned that
I see that the problem lays in libgnustl_shared.so
- two libraries are using different versions of this file.
Commonly it's the proper choice to use the more up-to-date library version, therefore:
To resolve this conflict, the Android Gradle plugin uses the following dependency resolution strategy: when the plugin detects that different versions of the same module are in the dependency graph, by default, it chooses the one with the highest version number.
Usually, that's it and the problem is resolved automatically. I suspect, that you overwrote that behaviour by using pickFirst
without naming a concrete file, such applying it to everything.
In case you whyever need both versions, you'll have to treat them as different libraries and rename them, so e.g. libfoo.so.1.1
and libfoo.so.1.2
become libfoo1.so
and libfoo2.so
or something.
And, of course, check whether you provide all necessary dependencies.
I hope that will help you.