Duplicate files copied to the Android APK. Is it possible to combine them?

In my Android project, I included two libraries as a JAR in the libs folder. And I add them to the Gradle assembly, as shown below.

dependencies { compile files('libs/siddhi-core-4.0.0-M13-SNAPSHOT.jar') compile files('libs/siddhi-execution-math-4.0.2-SNAPSHOT.jar') } 

These two jar files have a file with the same name ("org.wso2.siddhi.annotation.Extension"), but with different content. And both files are important for the project. Since it has the same name as Gradle, it will not build a statement

 Duplicate files copied in APK 

How to combine these two files into one file with the same name? These two files are text files with a list of class names. Two files have two different lists. Therefore, I want to combine them into one list in a text file with the same name.

enter image description here

+5
source share
4 answers
Finally, I found the answer. In the build gradle application, you can specify to merge conflicting files.
 packagingOptions { merge 'META-INF/annotations/org.wso2.siddhi.annotation.Extension' } 

See here https://google.imtqy.com/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.PackagingOptions.html for details

+4
source

You can exclude the file from the jar, unzip them first and copy the jar without these files. After that, compile this unZip file instead of the actual file, for example

 task unzipJar(type: Copy) { from zipTree('libs/siddhi-core-4.0.0-M13-SNAPSHOT.jar') into ("$buildDir/libs/siddhi-core-4.0.0-M13-SNAPSHOT") include "**/*.class" exclude "org.wso2.siddhi.annotation.Extension" } dependencies { compile files('libs/siddhi-execution-math-4.0.2-SNAPSHOT.jar') compile files("$buildDir/libs/siddhi-core-4.0.0-M13-SNAPSHOT") { builtBy "unzipJar" } } 

Please check this, even I did not get the opportunity to use it, but it should work.

+2
source

You cannot, as both files have the same name resolution (org.wso2.siddhi.annotation.Extension). So this will not work. Let's say some how you turned on both banks than how you are going to use one of them, that is. How the runtime uniquely identifies the class, since both classes have the same namespace as well as the name.

0
source

try this one

  dependencies { compile files('libs/siddhi-execution-math-4.0.2-SNAPSHOT.jar') compile files("$buildDir/libs/siddhi-core-4.0.0-M13-SNAPSHOT") { builtBy "unzipJar" } } 
-1
source

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


All Articles