Looking for some help from someone who puts the pro in proguard.
Annotations used by kotlin-reflect (required dependency for jackson-module-kotlin v v2.8.8) are getting stripped out after upgrading to kotlin 1.1.2-3. The error from proguard is:
Warning:kotlin.reflect.jvm.internal.impl.descriptors.CallableDescriptor: can't find referenced class org.jetbrains.annotations.ReadOnly
This is happening for a few annotations, not just ReadOnly. We have tried adding a good ol' catch all but the error still exists:
-keep class org.jetbrains.kotlin.** { *; }
-keep class org.jetbrains.annotations.** { *; }
-keepclassmembers class ** {
#org.jetbrains.annotations.ReadOnly public *;
}
Looking at the source for ReadOnly it is an #interface with java.lang.annotations.* imported for #Documented, #RetentionPolicy.CLASS, #Target
Or a shorter version:
-dontwarn kotlin.reflect.jvm.internal.**
The fix for us was to add dontwarn for the reflect warnings.
-dontwarn kotlin.reflect.jvm.internal.impl.descriptors.CallableDescriptor
-dontwarn kotlin.reflect.jvm.internal.impl.descriptors.ClassDescriptor
-dontwarn kotlin.reflect.jvm.internal.impl.descriptors.ClassifierDescriptorWithTypeParameters
-dontwarn kotlin.reflect.jvm.internal.impl.descriptors.annotations.AnnotationDescriptor
-dontwarn kotlin.reflect.jvm.internal.impl.descriptors.impl.PropertyDescriptorImpl
-dontwarn kotlin.reflect.jvm.internal.impl.load.java.JavaClassFinder
-dontwarn kotlin.reflect.jvm.internal.impl.resolve.OverridingUtil
-dontwarn kotlin.reflect.jvm.internal.impl.types.DescriptorSubstitutor
-dontwarn kotlin.reflect.jvm.internal.impl.types.DescriptorSubstitutor
-dontwarn kotlin.reflect.jvm.internal.impl.types.TypeConstructor
These annotations exist in kotlin-compiler which is why proguard can't find them. Just ignore the warning instead of adding kotlin-compiler as a dependency (as this issue suggests Cannot resolve symbol #ReadOnly and #Mutable in Kotlin 1.1.0 compilation).
This may be a bug in kotlin-reflect; they should provide proguard rules to hide this from integrating apps.
Related
I would like to ask if you know a guide or if you know how to use Proguard with Kotlin and Gradle and would like to share your knowledge, I would really appreciate it. Already searched Stack Overflow, but couldn't find a single (answered) question about using Proguard + Kotlin JVM (not android!) + Gradle.
I only found guides on the Internet regarding this matter for android, but I'm not using Kotlin for android, I'm building a Java Plugin (in other words, JVM) with Kotlin and I would like to use Proguard to minify and obfuscate my code. Note that my project is using Gradle Shadow to shadow its dependencies into the final jar (these dependencies don't need to be obfuscated but can be minified, and definitively do need to exist in the obfuscated jar created by Proguard).
I would like to know all the steps, things like how to step up Gradle to automatically minify & obfuscate my code (with a custom task), how to remove Kotlin metadata from java compiled classes, common issues & solutions to that issues, and anything else that you think it can be useful to know, everything is helpful. Thank you very much.
I got this working some time ago, refer to the Proguard manual to learn about the syntax of its configuration file. Also, for some reason, sometimes Proguard just says that the current obfuscated jar is "up-to-date" even when there's no jar, seems to be a bug that I could not find the steps to reproduce. If that happens to you, just change the Proguard version you're using and reload Gradle dependencies.
build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
// add this
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("com.guardsquare:proguard-gradle:7.1.1") {
exclude("com.android.tools.build")
}
}
}
plugins {
kotlin("jvm") version "1.5.30"
id("com.github.johnrengelman.shadow") version "7.0.0"
}
group = "com.yourgroup"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
maven("https://oss.sonatype.org/content/groups/public/")
}
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0")
// your dependencies here
}
tasks.test {
useJUnitPlatform()
}
// disables the normal jar task
tasks.jar { enabled = false }
// and enables shadowJar task
artifacts.archives(tasks.shadowJar)
tasks.shadowJar {
archiveFileName.set(rootProject.name + ".jar")
val dependencyPackage = "${rootProject.group}.dependencies.${rootProject.name.toLowerCase()}"
// your relocations here
exclude("ScopeJVMKt.class")
exclude("DebugProbesKt.bin")
exclude("META-INF/**")
}
tasks.register<proguard.gradle.ProGuardTask>("proguard") {
// here is where you configure your Proguard stuff, you can include libraries directly
// through here, or in the configuration file, I usually just use the configuration file
// to do everything (it can be any name and extension you want, just using .pro here cause
// that's what Android uses)
configuration("proguard-rules.pro")
}
// keep this if you want run proguard task automatically after building
tasks.build.get().finalizedBy(tasks.getByName("proguard"))
tasks.withType<JavaCompile> {
sourceCompatibility = "16"
targetCompatibility = "16"
options.encoding = "UTF-8"
}
tasks.withType<KotlinCompile> { kotlinOptions.jvmTarget = "16" }
proguard-rules.pro: This is just an example file used to minify a Minecraft plugin, but the logic applies no matter what kind of jar you're dealing with.
# injars = your shadowed jar
-injars build/libs/YourShadowedJarHere.jar
# outjars = the name of the new obfuscated/minified jar
-outjars build/libs/YourShadowedJarHere-min.jar
# important! you need to add this "rt" file from your JDK as libraryjars!
-libraryjars "C:\Program Files\Java\jdk1.8.0_291\jre\lib\rt.jar"
# add here the jar to any compileOnly dependency you might have (or add "dontwarn" to make proguard ignore the missing classes)
-libraryjars "PathTo\YourProject\SomeLocalLibraries\SomeLocalLibrary.jar"
-dontwarn net.minecraft.**
-dontwarn org.bukkit.**
-dontwarn com.google.**
-dontwarn com.comphenix.**
-dontwarn android.**
-dontwarn org.hibernate.**
-dontwarn com.sk89q.worldedit**
-dontwarn com.sk89q.worldguard**
-dontwarn net.milkbowl.vault.economy**
-keep class yourpackage.dependencies.yourproject.hikari.metrics.**
-dontwarn com.codahale.metrics.**
-keep class com.codahale.metrics.**
-dontwarn **hikari.metrics**
-dontwarn javax.crypto.**
-dontwarn javassist.**
-dontwarn **slf4j**
-dontwarn io.micrometer.core.instrument.MeterRegistry
-dontwarn org.codehaus.mojo.**
-dontwarn **prometheus**
-dontwarn **configurate.**
-dontwarn **koin.core.time.**
-dontwarn net.Indyuce.**
-dontwarn **xseries.**
-keepnames class kotlin.coroutines.** { *; }
-dontwarn **kotlinx.coroutines.**
-dontwarn **org.apache.commons.codec**
#-dontshrink
#-dontobfuscate
#-dontoptimize
# Keep your main class
-keep,allowobfuscation,allowoptimization class * extends org.bukkit.plugin.java.JavaPlugin { *; }
# Keep event handlers
-keep,allowobfuscation,allowoptimization class * extends org.bukkit.event.Listener {
#org.bukkit.event.EventHandler <methods>;
}
# Keep main package name
// -keeppackagenames "your.package"
# Keep public enum names
-keepclassmembers public enum yourpackage.** {
<fields>;
public static **[] values();
public static ** valueOf(java.lang.String);
}
# Keep all ProtocolLib packet listeners (this was rough to get working, don't turn on optimization, it ALWAYS breaks the sensible ProtocolLib)
-keepclassmembers class yourpackage.yourproject.** {
void onPacketSending(com.comphenix.protocol.events.PacketEvent);
void onPacketReceiving(com.comphenix.protocol.events.PacketEvent);
}
# Keep static fields in custom Events
-keepclassmembers,allowoptimization class yourpackage.yourproject.** extends org.bukkit.event.Event {
#yourpackage.dependencies.kotlin.jvm.JvmStatic <fields>;
public static final <fields>;
#yourpackage.dependencies.kotlin.jvm.JvmStatic <methods>;
public static <methods>;
}
# Remove dependencies obsfuscation to remove bugs factor
#-keep,allowshrinking class yourpackage.dependencies.** { *; }
# If your goal is obfuscating and making things harder to read, repackage your classes with this rule
-repackageclasses yourpackage.yourproject
-allowaccessmodification
-mergeinterfacesaggressively
# You can parse any resource files that might contain a reference of your classes here (so they are updated according to the modifications made by Proguard)
-adaptresourcefilecontents **.yml,META-INF/MANIFEST.MF
# Some attributes that you'll need to keep (warning: removing *Annotation* might break some stuff)
-keepattributes Exceptions,Signature,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
#-keepattributes Exceptions,Signature,Deprecated,LineNumberTable,*Annotation*,EnclosingMethod
#-keepattributes LocalVariableTable,LocalVariableTypeTable,Exceptions,InnerClasses,Signature,Deprecated,LineNumberTable,*Annotation*,EnclosingMethod
I've been trying to use detox to test e2e.
RN 0.57.0
I followed the integration steps for android but I'm blocked on trying to compile the project.
detox build -c android.emu.debug
It builds perfectly when I run the normal ./gradlew assembleRelease command.
Note: there were 27 duplicate class definitions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
Warning: library class android.content.res.XmlResourceParser extends or implements program class org.xmlpull.v1.XmlPullParser
Warning: android.support.test.espresso.core.internal.deps.guava.cache.Striped64: can't find referenced class sun.misc.Unsafe
...
Warning: android.support.test.espresso.core.internal.deps.guava.cache.Striped64$Cell: can't find referenced class sun.misc.Unsafe
Warning: android.support.test.espresso.core.internal.deps.guava.util.concurrent.AbstractFuture$UnsafeAtomicHelper: can't find referenced class sun.misc.Unsafe
...
Warning: android.support.test.espresso.core.internal.deps.guava.util.concurrent.AbstractFuture$UnsafeAtomicHelper$1: can't find referenced class sun.misc.Unsafe
Warning: library class android.content.Intent depends on program class org.xmlpull.v1.XmlPullParser
Warning: library class android.content.IntentFilter depends on program class org.xmlpull.v1.XmlSerializer
Warning: library class android.content.IntentFilter depends on program class org.xmlpull.v1.XmlPullParser
Warning: library class android.graphics.drawable.BitmapDrawable depends on program class org.xmlpull.v1.XmlPullParser
Warning: library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser
...
Warning: library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser
Warning: library class android.util.Xml depends on program class org.xmlpull.v1.XmlPullParser
Warning: library class android.util.Xml depends on program class org.xmlpull.v1.XmlSerializer
Warning: library class android.util.Xml depends on program class org.xmlpull.v1.XmlPullParser
Warning: there were 24 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 14 instances of library classes depending on program classes.
You must avoid such dependencies, since the program classes will
be processed, while the library classes will remain unchanged.
(http://proguard.sourceforge.net/manual/troubleshooting.html#dependency)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithProguardForReleaseAndroidTest'.
> Job failed, see logs for details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 30s
child_process.js:644
throw err;
^
Perhaps detox requires another proguard file?
----UPDATE----
Here is my build.gradle dependencies:
dependencies {
compile project(':rn-fetch-blob')
implementation project(':react-native-firebase')
implementation project(':react-native-image-resizer')
implementation project(':react-native-zendesk-support')
implementation project(':bugsnag-react-native')
implementation project(':react-native-fast-image')
implementation project(':react-native-calendar-events')
implementation project(':react-native-contacts')
implementation project(':react-native-device-info')
implementation project(':react-native-image-picker')
implementation project(':react-native-config')
implementation project(':react-native-restart')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:27.1.0"
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.android.support:recyclerview-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:cardview-v7:27.1.0'
implementation 'com.google.android.gms:play-services-gcm:15.0.1'
implementation "com.facebook.react:react-native:+" // From node_modules
// Firebase dependencies
implementation "com.google.android.gms:play-services-base:15.0.1"
implementation "com.google.firebase:firebase-core:15.0.2"
implementation "com.google.firebase:firebase-analytics:15.0.2"
implementation('com.crashlytics.sdk.android:crashlytics:2.9.3#aar') {
transitive = true;
}
implementation project(':react-native-photo-view')
implementation (project(':react-native-camera')) {
implementation 'com.android.support:exifinterface:27.1.0'
implementation ('com.google.android.gms:play-services-vision:15.0.1') {
force = true
}
}
implementation(project(':react-native-notifications')) {
exclude group: 'com.google.firebase', module: 'firebase-messaging'
}
implementation("com.google.firebase:firebase-messaging:15.0.2") {
implementation project(':react-native-notifications')
}
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion"
implementation project(':react-native-code-push')
androidTestImplementation(project(":detox"))
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
}
Not sure if the react native dependencies make a difference...
Perhaps there is a mismatch in versions?
after upgrading the android gradle plugin from 3.0.0-alpha1 to 3.0.0-alpha2 my application does not start anymore: part of the stacktrace:
05-27 09:14:57.692 3015-3015/com.tmtron.dscontrol2app.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tmtron.dscontrol2app.debug, PID: 3015
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tmtron.dscontrol2app.debug/com.tmtron.dscontrol2.gui.MainActivity}: android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class android.support.v7.widget.FitWindowsLinearLayout
Caused by: android.view.InflateException: Binary XML file line #17: Binary XML file line #17: Error inflating class android.support.v7.widget.FitWindowsLinearLayout
Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.v7.widget.FitWindowsLinearLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.FitWindowsLinearLayout" on path: DexPathList[[zip file "/data/app/com.tmtron.dscontrol2app.debug-ZE45jTeV6eTnNIeveAjAbw==/base.apk", zip file "/data/app/com.tmtron.dscontrol2app.debug-ZE45jTeV6eTnNIeveAjAbw==/split_lib_dependencies_apk.apk", zip file "/data/app/com.tmtron.dscontrol2app.debug-ZE45jTeV6eTnNIeveAjAbw==/split_lib_slice_0_apk.apk", zip file "/data/app/com.tmtron.dscontrol2app.debug-..."/data/app/com.tmtron.dscontrol2app.debug-ZE45jTeV6eTnNIeveAjAbw==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.tmtron.dscontrol2app.debug-ZE45jTeV6eTnNIeveAjAbw==/lib/x86, /system/lib, /system/vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
at com.tmtron.dscontrol2.gui.MainActivity.onCreate(MainActivity.java:41)
at android.app.Activity.performCreate(Activity.java:6954)
05-27 09:14:57.693 3015-3015/com.tmtron.dscontrol2app.debug E/AndroidRuntime:
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
It seems like the class android.support.v7.widget.FitWindowsLinearLayout is not found anymore.
Any ideas?
BTW: I have already tried to do all kinds of cleanup, invalidate-caches, restart, etc. as mentioned in this SO.
I think this is a temporarily bug.
Proparbly Proguard removes this class because of some reason, therefore this exception occurs.
For now the easiest solution might be to disable Proguard in the build.gradle file. If you still want to keep it, you will have to change your proguard settings.
This is what I did and what worked for me:
-dontwarn android.support.v7.**
-keep class android.support.v7.widget.** { *; }
As I also had issues with constraint and design libray I added this:
-dontwarn android.support.constraint.**
-keep class android.support.constraint.** { *; }
-dontwarn android.support.design.**
-keep class android.support.design.** { *; }
I hope it helps you:)
UPDATE
This bug has already been fixed - it works for me with gradle plugin 3.0.0-alpha4
ORIGINAL answer (kept for reference)
Actually I didn't have ProGuard enabled for my debug builds, but the Shrinker of the Android Gradle Plugin (which uses the same proguard files.
Temporary workaround for the issue: add the following instructions to the proguard-rules.pro file:
-keep class android.support.v7.widget.** { *; }
-keep class android.support.v4.widget.** { *; }
-keep class android.support.design.** { *; }
-keep class com.bluelinelabs.conductor.** { *; }
I just turned on ProGuard on my build and now I'm getting a
java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.chimera.GmsModuleInitializer" on path: DexPathList[[zip file "/system/app/PlayGames.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
The docs say that everything that I need to use Proguard with Play Services should be included by the Android Gradle plugin:
Note: ProGuard directives are included in the Play services client
libraries to preserve the required classes. The Android Plugin for
Gradle automatically appends ProGuard configuration files in an AAR
(Android ARchive) package and appends that package to your ProGuard
configuration. During project creation, Android Studio automatically
creates the ProGuard configuration files and build.gradle properties
for ProGuard use. To use ProGuard with Android Studio, you must enable
the ProGuard setting in your build.gradle buildTypes. For more
information, see the ProGuard guide.
This the important part of my app module build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
...
}
...
buildTypes {
...{
applicationIdSuffix ".debug"
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
...
//google play services
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
}
This is my top level build.gradle file:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
What am I missing?
ClassNotFoundException usually occurs when an application tries to load in a class through its string name but no definition for the class with the specified name could be found.
From this forum, you can fix it by adding com.google.android.gms.** { *; }.
Just add to your proguard-project.txt:
keep class com.google.android.gms.** { *; }
dontwarn com.google.android.gms.**
You can also check on the suggested comment in this SO question.
Google Play Services aars contain proguard.txt with the necessary clauses. So the setting shouldn't really be necessary. You can investigate what happened with the fragment in ProGuard output files. Check app/build/output/mapping/{buildVariant}/usage.txt and mapping.txt. The fragment should be mentioned in one of those.
Hope this helps!
I know this is a rather old post but I would like to highlight the following should it help someone in the future.
Like #abielita mentioned, the ClassNotFoundException is caused by an unhandled case of reflection.
When using broad -keep options (ending with .** { *; }), you will instruct ProGuard not to shrink, optimize or obfuscate all classes and classmembers for the package name mentioned before the wildcards. This will eventually lead in a poorly optimized project. Therefore, it's better to narrow down such -keep option to only target the missing class. In OP's example, adding a -keep option for the missing class like shown below will tackle this particular issue;
-keep class com.google.android.gms.chimera.GmsModuleInitializer
ProGuard can help you set up narrowed down -keep options if you add -addconfigurationdebugging to the configuration file, more details on this feature is documented in the ProGuard manual, here.
Recently the ProGuard Playground was released, you can quickly visualise the effect of the broad -keep options vs the narrowed down ones. A nice benefit here is that you do not need to continuously (re-)build the project.
I am learning how to implement Proguard for Java obfuscation in MobileFirst 7.1. I created a new MobileFirst project with Android environment and followed the process described in IBM documentation:
http://www.ibm.com/support/knowledgecenter/SSHS8R_7.1.0/com.ibm.worklight.deploy.doc/admin/t_pg_creating_obfus_apk.html?lang=en
However, when trying to export the signed APK I am getting the following errors:
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] Proguard returned with error code 1. See console
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] Note: there were 2640 duplicate class definitions.
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] You should check if you need to specify additional program jars.
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] java.lang.ClassCastException: java.lang.Object cannot be cast to java.lang.String
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.obfuscate.MemberObfuscator.newMemberName(MemberObfuscator.java:198)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.obfuscate.MemberNameCollector.visitAnyMember(MemberNameCollector.java:74)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.classfile.util.SimplifiedVisitor.visitProgramMember(SimplifiedVisitor.java:79)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.classfile.util.SimplifiedVisitor.visitProgramMethod(SimplifiedVisitor.java:91)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.classfile.visitor.MemberAccessFilter.visitProgramMethod(MemberAccessFilter.java:90)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.classfile.ProgramMethod.accept(ProgramMethod.java:71)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.classfile.ProgramClass.methodsAccept(ProgramClass.java:504)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.classfile.visitor.AllMemberVisitor.visitProgramClass(AllMemberVisitor.java:48)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.classfile.ProgramClass.accept(ProgramClass.java:346)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.classfile.ProgramClass.hierarchyAccept(ProgramClass.java:359)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.classfile.LibraryClass.hierarchyAccept(LibraryClass.java:371)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.classfile.ProgramClass.hierarchyAccept(ProgramClass.java:416)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.classfile.visitor.ClassHierarchyTraveler.visitProgramClass(ClassHierarchyTraveler.java:75)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.classfile.visitor.MultiClassVisitor.visitProgramClass(MultiClassVisitor.java:85)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.classfile.ProgramClass.accept(ProgramClass.java:346)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.classfile.ClassPool.classesAccept(ClassPool.java:116)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.obfuscate.Obfuscator.execute(Obfuscator.java:217)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.ProGuard.obfuscate(ProGuard.java:333)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.ProGuard.execute(ProGuard.java:135)
[2016-05-16 15:24:38 - myTestMyTestAppAndroid] at proguard.ProGuard.main(ProGuard.java:492)
I am confused because this is supposed to be a clean project, and I have not made any changes to the base files, neither in the app's assets or the proguard configuration file.
So why are these errors appearing while trying to export the APK?
proguard-project.txt:
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-injars bin/classes
-injars libs
-outjars bin/classes-processed.jar
# Using Google's License Verification Library
-keep class com.android.vending.licensing.ILicensingService
# Specifies to write out some more information during processing.
# If the program terminates with an exception, this option will print out the entire stack trace, instead of just the exception message.
-verbose
# Annotations are represented by attributes that have no direct effect on the execution of the code.
-keepattributes *Annotation*
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepattributes InnerClasses
-keep class **.R
-keep class **.R$* {
<fields>;
}
# These options let obfuscated applications or libraries produce stack traces that can still be deciphered later on
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
# Enable proguard with Cordova
-keep class org.apache.cordova.** { *; }
-keep public class * extends org.apache.cordova.CordovaPlugin
-keep class com.worklight.androidgap.push.** { *; }
-keep class com.worklight.wlclient.push.** { *; }
-keep class com.worklight.common.security.AppAuthenticityToken { *; }
# Enable proguard with Google libs
-keep class com.google.** { *;}
-dontwarn com.google.common.**
-dontwarn com.google.ads.**
# apache.http
-keep class org.apache.http.** { *; }
-dontwarn org.apache.http.**
-optimizations !class/merging/vertical*,!class/merging/horizontal*,!code/simplification/arithmetic,!field/*,!code/allocation/variable
-keep class net.sqlcipher.** { *; }
-dontwarn net.sqlcipher.**
-keep class org.codehaus.** { *; }
-keepattributes *Annotation*,EnclosingMethod
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
# These classes contain references to external jars which are not included in the default MobileFirst project.
-dontwarn com.worklight.common.internal.WLTrusteerInternal*
-dontwarn com.worklight.jsonstore.**
-dontwarn org.codehaus.jackson.map.ext.*
-dontwarn com.worklight.androidgap.push.GCMIntentService
-dontwarn com.worklight.androidgap.plugin.WLInitializationPlugin
-dontwarn com.worklight.wlclient.push.GCMIntentService
-dontwarn org.bouncycastle.**
-dontwarn com.worklight.androidgap.jsonstore.security.SecurityManager
-dontwarn com.worklight.wlclient.push.WLBroadcastReceiver
-dontwarn com.worklight.wlclient.push.common.*
-dontwarn com.worklight.wlclient.api.WLPush
-dontwarn com.worklight.wlclient.api.SecurityUtils
-dontwarn android.support.v4.**
-dontwarn android.net.SSLCertificateSocketFactory
-dontwarn android.net.http.*
You need to add some configurations in your proguard-project.txt.
This Stackoverflow post can help you get started on adding some configuration for Proguard. Looks like they encountered a similar issue:
Android compile ClassCastException with Proguard
Here is a list of useful proguard configurations:
http://proguard.sourceforge.net/manual/examples.html#midlet
This could be because of the version of proguard in Android SDK. I had the same issue and solved it by updating proguard in my Android sdk tools.
I downloaded the latest version of proguard from https://sourceforge.net/projects/proguard/files/proguard/. Replaced bin and lib folders of my proguard with downloaded ones. Proguard folder can be located in /android-sdks/tools/proguard.
Hope this helps.