Android gradle duplicates native shared libraries

My question is similar to the question asked here:

How to exclude duplicated C shared libraries (.so) in a multi-project Android build?

In my project, I have a shared library that has its own code MySharedLib . I have a TestDuplicateSharedLibApp application that depends on MySharedLib and also has its own code.

As part of the gradle build, I will disable the ndk-build automatic call by setting jni.srcDirs =[] . I explicitly invoke the ndk-build command.

As part of the MySharedLib build process, libMySharedLib.so generated and packaged in MySharedLib.aar .

TestDuplicateSharedLibApp dependent on MySharedLib . As part of ndk-build, libTestDuplicateSharedLibApp.so and libMySharedLib.so copied to the TestDuplicateSharedLibApp/libs directory.

Since I need to pack shared libraries in the latest apk, I have jniLibs.srcDirs=['libs'] in my build.gradle.

When the last apk package is packaged, the package fails due to duplicate copies of libMyShared.so , one from MySharedLib.aar and the other from TestDuplicateSharedLibApp/libs . I tried pick-first and exclude packaging options, but they did not help.

Basically what I need is equivalent to jniLibs.srcDirs for files. In TestDuplicateSharedLibApp I would like to say: include only libTestDuplicateSharedLibApp.so . I foresaw this by doing: jniLibs.srcDirs=[] and if the jniLibs.srcFiles option jniLibs.srcFiles='libTestDuplicateSharedLibApp.so'

I would be grateful for a solution to this problem.

+6
source share

Source: https://habr.com/ru/post/977516/


All Articles