I added all the jars from restlet-android-2.3.1 archive to my libs folder in android studio. I can Make the project, but when I try to debug I'm getting this errors
Path in archive: META-INF/services/org.restlet.engine.converter.ConverterHelper
Origin 1: D:\android\restlet\app\libs\org.restlet.ext.gson.jar
Origin 2: D:\android\restlet\app\libs\org.restlet.ext.html.jar
You can ignore those files in your build.gradle:
android {
packagingOptions {
exclude 'META-INF/services/org.restlet.engine.converter.ConverterHelper'
}
}
AND
Error:Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK META-INF/services/org.restlet.engine.converter.ConverterHelper
File 1: D:\android\restlet\app\libs\org.restlet.ext.gson.jar
File 2: D:\android\restlet\app\libs\org.restlet.ext.gson.jar
If, for example to:
packagingOptions {
exclude 'META-INF/services/org.restlet.engine.converter.ConverterHelper'
}
then I'm getting this:
Error:duplicate files during packaging of APK D:\android\restlet\app\build\outputs\apk\app-debug-unaligned.apk
Path in archive: META-INF/services/org.restlet.engine.ClientHelper
Origin 1: D:\android\restlet\app\libs\org.restlet.ext.sip.jar
Origin 2: D:\android\restlet\app\libs\org.restlet.ext.nio.jar
You can ignore those files in your build.gradle:
android {
packagingOptions {
exclude 'META-INF/services/org.restlet.engine.ClientHelper'
}
}
And so on.
The classes I'm adding to exclude are base classes, and are referenced in other jars.
If to remove problematic jars from libs folder then it will work, but I ended up cutting off half of them. I'll need them. How to fix this? Are all of this restlet jars play well together?
I was having the same issue. I'm just using four of the restlet jars in my project and had to put in the following to the build.gradle file. You would think there's some studio wide setting like "ignore duplicates" but I didn't find it. I eventually added enough exclusions for it to work.
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/services/com.fasterxml.jackson.core.JsonFactory'
exclude 'META-INF/services/com.fasterxml.jackson.core.ObjectCodec'
}
Related
When I add the couchbase lite cordova plugin from:
https://github.com/couchbaselabs/Couchbase-Lite-PhoneGap-Plugin
I get this error when building:
Duplicate files copied in APK META-INF/LICENSE
File 1: C:\JavaScript\Project-Angular\platforms\android\libs\jackson-databind-2.5.0.jar
File 2: C:\JavaScript\Project-Angular\platforms\android\libs\jackson-databind-2.5.0.jar
You can ignore those files in your build.gradle:
android {
packagingOptions {
exclude 'META-INF/LICENSE'
}
}
I know it has something to do with the build.gradle file but I've searched everywhere and all the questions are about Android directly. I don't know how I'm supposed to edit the build.gradle file since its edited.
Removing the plugin fixes the problem
To fix this problem, you must create a file called platforms/android/build-extras.gradle within your project. With that file created, you can paste the following code:
android {
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
}
The next time you try to build and run your project for Android, you should no longer suffer from that problem.
Further documentation on Apache Cordova's build-extras.gradle file can be found in the official documentation:
https://cordova.apache.org/docs/en/5.0.0/guide/platforms/android/tools.html
Best,
Contrary to many other posts on this topic, I want to exclude a native library from an Android build with Gradle.
libfoo.so resides in a library project in the default directory thelib/src/main/jniLibs. In my main project's build.gradle I try to exlude the file as follows:
sourceSets {
all{
jniLibs {
exclude '**/libfoo.so'
}
}
}
This does not work though, the file is still in the final APK. I tried different path specifications already, but none of them work.
Is this even possible, or is there a workaround?
I know this is an old question, i solved my problem with the following
packagingOptions {
exclude 'lib/arm64-v8a/libfoo.so'
}
Hope it helps someones...
Note:
On further searching someone had already solved a similar issue;
Gradle exclude arm64 libs
I created a folder named libs and added a .jar file to it and right click -> add as library.
Later when I wanted to remove that jar file I just did right click -> delete. But noticed it is still in the build.gradle's dependencies block, removed that line as well.
Should have done it in a different way?
I later added the same jar file back. Now there are no errors in the project, but when I try to run the app, I get 2 errors:
Error:duplicate files during packaging of APK C:\Users\UserName\projectname\appname\build\outputs\apk\appname-debug-unaligned.apk Path in archive: META-INF/LICENSE
Origin 1: C:\Users\UserName\projectname\appname\libs\jackson-core-asl-1.9.13.jar
Origin 2: C:\Users\UserName\projectname\appname\libs\jackson-mapper-asl-1.9.13.jar
You can ignore those files in your build.gradle: android { packagingOptions { exclude 'META-INF/LICENSE' } }
-----------
Error:Execution failed for task ':appname:packageDebug'.
Duplicate files copied in APK META-INF/LICENSE
File 1: C:\Users\UserName\projectname\appname\libs\jackson-core-asl-1.9.13.jar
File 2: C:\Users\UserName\projectname\appname\libs\jackson-core-asl-1.9.13.jar
I tried the
You can ignore those files in your build.gradle: android {
packagingOptions { exclude 'META-INF/LICENSE' } }
But nothing changed.
The error message tells you to exclude 'META-INF/LICENSE' but instead you have exclude 'META-INF/ASL2.0'. Change it to the statement it's recommending to you.
Following various sets of instructions, it seems that I should add native libraries to app/src/main/jniLibs and they'll be linked up automagically. However when I do this (for OpenCV) I get the following:
Error:duplicate files during packaging of APK /.../app/build/outputs/apk/app-debug-unaligned.apk
Path in archive: lib/armeabi/libopencv_java.so
Origin 1: /.../app/src/main/jniLibs/armeabi/libopencv_java.so
Origin 2: /.../build/intermediates/exploded-aar/AppName/.libraries/opencv/unspecified/jni/armeabi/libopencv_java.so
You can ignore those files in your build.gradle:
android {
packagingOptions {
exclude 'lib/armeabi/libopencv_java.so'
}
}
Error:Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK lib/armeabi/libopencv_java.so
File 1: /.../app/src/main/jniLibs/armeabi/libopencv_java.so
File 2: /.../app/src/main/jniLibs/armeabi/libopencv_java.so
Adding the exclude section doesn't work. There's only one copy of the file, but somehow it's being referenced twice, and it seems the second (build) include is something auto-generated. What can I do?
In case of duplicate libraries (*.so) files, exclude option will not help as we cannot completely exclude the native binaries. There is one more option in packagingOptions. It is 'pickFirst'. We can avoid duplicate files error and include the first one the compiler encounters.
packagingOptions {
pickFirst 'lib/armeabi/libopencv_java.so'
}
ndk-build was generating duplicates of all of the packages from OpenCV. I removed all of the .so libraries from my app, apart from my actual app library, and then it packaged up fine.
I also had this issue. It seems it's because the documentation and various conversation threads on setting up OpenCV for Android say to put the JNI libraries at the path /src/main/jniLibs or /src/main/libs. The problem is that the /src/ folder is for source code, not libraries. The solution is to move the /main/ folder out of /src/ and into the project root, which is how Google documents this project structure: https://developer.android.com/tools/projects/index.html
I also have the following settings in build.gradle:
android {
sourceSets {
main {
jni.srcDirs = [] //disable automatic ndk-build call
jniLibs.srcDir 'main/libs'
}
}
}
I'm using gradle 1.10 and the version of the android plugin is 0.8.0. My android projects needs these two jars: jackson-core-asl-1.9.11.jar and jackson-mapper-asl-1.9.11.jar. I add the files thus:
dependencies {
compile files('libs/jackson-core-asl-1.9.11.jar')
compile files('libs/jackson-mapper-asl-1.9.11.jar')
}
During gradle build I get an error message saying that these two files are duplicated in META-INF/ASL2.0. I solved the problem by excluding the following files:
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
}
I have to exclude all of them because there apparently is a duplicate file in all of them.
I'd like to know why this problem occurs. Is it a bug of the android plugin or the gradle itself? Can excluding the above files cause any problems? Am I just excluding the above mentioned jars or is there anything else in those META-INF files? I don't want to exclude anything my project needs
First this is not a bug of gradle .
It occurs in MergeJavaResourcesTransform task:
As we know ,APK is just a zip file, so when put META-INFO/xxx into zip file, if file has been added before ,we can not put it again.
And there is no merge rules for META-INFO files , so we can only add on file which names NOTICE etc
Here's some info from the Jackson team https://github.com/FasterXML/jackson-databind/issues/214
There are a variety of posts about this on SO, such as this one: Error generating final archive: Found duplicate file for APK: LICENSE.txt
I've used Jackson with Eclipse and Ant as well (and I'm currently using it in Studio with the same workaround you are using), and I had to use zip on the command to rename the license.txt file. There's more info about the whole thing (including an example of using zip to rename the file) in this post Android Gradle plugin 0.7.0: "duplicate files during packaging of APK".
I have not found anything indicating that renaming or excluding these files will have negative consequences, and I never experienced any problems in about 2 years of using Jackson with Eclipse and Ant.