I am trying to generate unsigned APK it shows error.
Cannot copy 'E:---------------\app\libs\apache-mime4j-0.6.jar' to 'C:\Users--------.AndroidStudio2.2\system\jars\apache-mime4j-0.6.jar'. Reason: Data error (cyclic redundancy check).
i tried adding in code in default config
multiDexEnabled true
and also
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
}
is it necessary toi do disk check ?
any help will be really appreciated
CRC error would indicate data corruption. Try replacing the lib with a fresh copy.
Btw, seeing that it is copying the lib from E: drive to generate the Apk, why don't you try adding the dependency from Maven Central from Project Structure(assuming you are using Android Studio). Adding it this way will auto manage any issues as it will be stored in with the other libs.
After trying a few solutions off the internet I decided to try deleting the .gradle folder and that worked for me
I also face this problem. Just given the same folder for .jks and build output file. Then this problem will be solved.
Related
Gradle : 4.10.1
Gradle Android Plugin version : 3.3.2
Proguard : 6.0.3
JDK - 1.9
Android Studio 3.3.2
When I try to build apk release version along with Proguard. I get the following error -
Caused by: java.io.IOException: Please correct the above warnings first.
at proguard.InputReader.execute(InputReader.java:149)
at proguard.ProGuard.readInput(ProGuard.java:255)
at proguard.ProGuard.execute(ProGuard.java:96)
......
This seems to be caused due to this -
Warning: class [META-INF/versions/9/module-info.class] unexpectedly contains class [module-info]
Note: duplicate definition of program class [module-info]
Note: there were 20 duplicate class definitions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
Warning: there were 21 classes in incorrectly named files.
You should make sure all file names correspond to their class names.
The directory hierarchies must correspond to the package hierarchies.
From extensive searching it looks like Proguard has a problem with META-INF/versions/9. I have multiple dependencies that contain this.
While the issue to seems to somewhat documented, no solutions prescribed seem to work.
https://sourceforge.net/p/proguard/bugs/665/
suggests filtering out those class files via -
-injars my_lib.jar(!META-INF/versions/**.class)
However when I try this it just labels more files as duplicate and incorrectly named. I also tried excluding it via gradle-
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/versions'
exclude 'META-INF/versions/9/module-info.class'
}
This also fails to resolve the problem. How do I solve this problem ?
I realise this is a very old question, but I was able to get this to work using this gradle configuration:
task obfuscate(type: proguard.gradle.ProGuardTask) {
configuration files("proguard-project.txt")
libraryjars files("build/rt.jar", "build/jce.jar")
injars files("build/libs/desktop-${version}.jar"), filter: "!META-INF/versions/**/*.class"
outjars files("build/libs/obfuscated.jar")
}
I think the issue with the injars directive you used might be the path - should be META-INF/versions/**/*.class.
Using the option -ignorewarnings in proguard-project.txt 'fixed' it for me, the generated jar works fine as long as the only warnings mentioned by Proguard are related to META-INF.
I realise this is an old question, but I had issues with this when upgrading some other libs in an application.
I found the <inLibsFilter> tag at the proguard maven plugin page which helped me get it to work. I used it like this (in my <configuration> tag:
<inLibsFilter>!META-INF/versions/**</inLibsFilter>
Hopefully it can help others that may stumble upon it..
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,
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'
}
I exported my project from Eclipse and imported to Android Studio using the instructions in this link: http://developer.android.com/sdk/installing/migrate.html
When I build, I have an error:
Duplicate files copied in APK META-INF/DEPENDENCIES
After searching, I found a solution: add
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
into build.gradle. And it works!
But I don't understand why I had this error and why I've had to apply that fix. Can anybody explain?
While Scott Barta's answer is correct, is lacks a simple and common solution: just add
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
to your build.gradle to ignore those duplicates.
In Android Gradle builds, you're not permitted to include the same file with the same path more than once in the output. In your build, there were two META-INF/DEPENDENCIES files coming from different places. Since you don't need this file at all in your application, the simplest thing to do is to tell the build system to ignore it altogether, which is what this exclude directive does.
There's also a pickFirst directive to tell the build system to keep one of the copies; there's a tiny amount of detail on that in Android Gradle plugin 0.7.0: "duplicate files during packaging of APK".
Android builds in Gradle are rather strict about duplicate files, which can make life difficult. There's a similar problem if you include the same Java class more than once, where you get the "Multiple dex files define" error (see Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat) for a typical example).
Other build systems are more lenient. It's typical in Java that if you include the same class more than once in a classpath, for example, the first copy it sees is the one that's used; duplicates after that are ignored. This is in most cases easier to deal with, but it has a couple problems. The biggest one is that there can be subtle errors if multiple different versions of a file creep into the build without you knowing -- it can be difficult to figure out what's going on. When you do figure it out, you can usually solve it by juggling the order in which things are included to make sure the one you want makes it to the final output, but in very complex builds, this can be difficult to achieve, and it can happen that doing seemingly unrelated things like including new libraries in your project can upset the ordering and lead to a lot of woe.
For that reason, Gradle has the philosophy of not relying on ordering of things to determine "winners" in the game of resolving duplicates, and it forces the developer to make all dependencies explicit. Android's implementation of its build system on top of Gradle follows that philosophy.
The simplest solution is to add
packagingOptions {
pickFirst 'META-INF/*'
}
to your build.gradle in android section
The easiest way I've found to resolve this problem is to use a wildcard, so you don't find yourself having to manually declare each file in conflict.
packagingOptions {
pickFirst '**'
}
In case that anyone having these problem while uploading new .apk to Google Play Store, after updatng Android Studio ;
click V1 Jar Signature not Full Apk Signature while Generating new Apk with old Keystore
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.android.gms:play-services-ads:10.2.1'
implementation 'com.android.support:support-annotations:25.0.1'
testImplementation 'junit:junit:4.12'
**// select only one in two line below** implementation ‘package’ //implementation project(‘:package’)
}
// good luck
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.