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..
Related
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.
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 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.
I'm using IntelliJ and running Proguard in debug mode but I can't seem to get rid of warnings such as:
ProGuard: [MyApplication] Warning: can't write resource [META-INF/MANIFEST.MF]
(Duplicate zip entry [android-support-v13.jar:META-INF/MANIFEST.MF])
This project has a couple of modules and android-support-v13.jar is being used on 2 of them. I thought that was the issue so I removed that library from the libs folder, added it as a project library and added the dependency to both modules. That didn't solve anything, the warning persists and I don't understand why.
I know these warnings don't affect anything but a clean build is a happy build!
Possibly a 'proguard.cfg' problem. Does it include any '-injars'? If your project includes another project as a library, jars can be processed twice. Could you post your 'proguard.cfg'?
Extract from http://proguard.sourceforge.net/index.html#manual/troubleshooting.html:
Your input jars contain multiple resource files with the same name.
ProGuard continues copying the resource files as usual, skipping any
files with previously used names. Once more, the warning may be an
indication of some problem though, so it's advisable to remove the
duplicates. A convenient way to do so is by specifying filters on the
input jars. There is no option to switch off these warnings.
OPTION #1:
As you can't post your '-injars', check if they include either 'android-support-v13.jar' or the library included in your project which itself also includes 'android-support-v13.jar'.
Assuming you are building with Ant inside IntelliJ IDEA, you mustn't add -injars, -outjars, or -libraryjars options; the Ant script already does that for you.
OPTION #2:
Although the warnings are harmless, a clean build is a happy build, so try:
http://web.archive.org/web/20160206204259/http://www.dancartoon.com/2012/01/14/fixing-proguard-warning-cant-write-resource-meta-infmanifest-mf/
and
https://gist.github.com/paulpv/4439012
OPTION #3:
Include (!META-INF/MANIFEST.MF) after each '-injars' command
-injars library.jar(!META-INF/MANIFEST.MF)
OPTION #4: Android Proguard Duplicate Definition
Fixed this by moving the 3rd party libraries to another directory, in
my case 'lib'. Then added
-injars lib/jmdns.jar
to the proguard.cfg file.
OPTION #5: Android - Proguard duplicate zip entry error
If your Proguard config file includes the following line, remove it:
-injars bin/classes
OPTION #6: Android obfuscate app using proguard keeps obfuscating library jars - or is it?
I found another way to make Proguard leave library jars alone was to
ask it to preserve their package names, eg:
-keep class javax.** { *; }
-keep class org.** { *; }
-keep class twitter4j.** { *; }
OPTION #7:
A weird solution (deleting META-INF folder in src folder) to something similar here.
I used packagingOptions with exclude in build.gradle, and I have same issues with you.
You can fix it using this.
packagingOptions {
pickFirst 'META-INF/services/javax.annotation.processing.Processor'
pickFirst 'META-INF/DEPENDENCIES.txt'
pickFirst 'META-INF/DEPENDENCIES'
pickFirst 'META-INF/LICENSE.txt'
pickFirst 'META-INF/LICENSE'
pickFirst 'META-INF/NOTICE.txt'
pickFirst 'META-INF/NOTICE'
pickFirst 'META-INF/LGPL2.1'
}
Replace pickFirst with exclude.
The best solution I found was to copy the -obfuscate target from /tools/ant/build.xml into your project's custom_rules.xml. Then the only block that needs to be changed is:
<pathconvert property="project.all.classes.value" refid="project.all.classes.path">
<firstmatchmapper>
<regexpmapper from='^([^ ]*)( .*)$$' to='"\1\2"(!META-INF/MANIFEST.MF)'/>
<identitymapper/>
</firstmatchmapper>
</pathconvert>
The only added bit is (!META-INF/MANIFEST.MF). This will exclude all the manifest files, which won't be copied in to the final APK anyway.
Don't reference the support library by including its jar directly; when you do this, the build system can't disambiguate between multiple versions of it, and you get errors of this type. Include it by referencing its Maven coordinates:
dependencies {
compile 'com.android.support:support-v13:X.X.X'
}
where X.X.X is the proper version number based on what API you're compiling against. If you include this dependency via the UI at Project Structure > (your module) > Dependencies > + Button > Library dependency it will help you choose the right version number.
You may also find it convenient to include other dependencies via Maven coordinates instead of wrangling their jars; that same library dependency UI has a search function to help you find libraries.
be sure to remove this library from the libs or any other folder it was present inside
add -dontwarn to proguard.cfg to ignore warnings