Proguard ClassCastException in Mobile First Server 7.1 - ibm-mobilefirst

I am getting ClassCastException while exporting android hybrid app as apk in Mobile First Server 7.1
Followed below links for enabling Proguard in MFS.
https://www.youtube.com/watch?v=WrCmLJuIMuk
https://www.ibm.com/support/knowledgecenter/SSHS8R_7.1.0/com.ibm.worklight.deploy.doc/admin/t_pg_creating_obfus_apk.html
Find below console error logs
[2016-06-21 11:57:47 - ProguardProguardAndroid] Proguard returned with error code 1. See console
[2016-06-21 11:57:47 - ProguardProguardAndroid] Note: there were 2640 duplicate class definitions.
[2016-06-21 11:57:47 - ProguardProguardAndroid] You should check if you need to specify additional program jars.
[2016-06-21 11:57:47 - ProguardProguardAndroid] java.lang.ClassCastException: java.lang.Object cannot be cast to java.lang.String
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.obfuscate.MemberObfuscator.newMemberName(MemberObfuscator.java:198)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.obfuscate.MemberNameCollector.visitAnyMember(MemberNameCollector.java:74)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.classfile.util.SimplifiedVisitor.visitProgramMember(SimplifiedVisitor.java:79)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.classfile.util.SimplifiedVisitor.visitProgramMethod(SimplifiedVisitor.java:91)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.classfile.visitor.MemberAccessFilter.visitProgramMethod(MemberAccessFilter.java:90)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.classfile.ProgramMethod.accept(ProgramMethod.java:71)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.classfile.ProgramClass.methodsAccept(ProgramClass.java:504)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.classfile.visitor.AllMemberVisitor.visitProgramClass(AllMemberVisitor.java:48)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.classfile.ProgramClass.accept(ProgramClass.java:346)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.classfile.ProgramClass.hierarchyAccept(ProgramClass.java:359)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.classfile.LibraryClass.hierarchyAccept(LibraryClass.java:371)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.classfile.ProgramClass.hierarchyAccept(ProgramClass.java:416)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.classfile.visitor.ClassHierarchyTraveler.visitProgramClass(ClassHierarchyTraveler.java:75)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.classfile.visitor.MultiClassVisitor.visitProgramClass(MultiClassVisitor.java:85)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.classfile.ProgramClass.accept(ProgramClass.java:346)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.classfile.ClassPool.classesAccept(ClassPool.java:116)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.obfuscate.Obfuscator.execute(Obfuscator.java:217)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.ProGuard.obfuscate(ProGuard.java:333)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.ProGuard.execute(ProGuard.java:135)
[2016-06-21 11:57:47 - ProguardProguardAndroid] at proguard.ProGuard.main(ProGuard.java:492)
Find below for contents for 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
####################################################################################################
############################## IBM MobileFirst Platform configuration ############################
####################################################################################################
# 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.*
######################################################################################################
-dontwarn android.**
-keep class android.**
-dontwarn com.android.**
-keep class com.android.**
-dontwarn com.google.**
-keep class com.google.**

I downloaded updated proguard from https://sourceforge.net/projects/proguard/files/proguard/. Replaced bin and lib folders of my proguard with downloaded ones. Proguard folder located in /android-sdks/tools/proguard
This resolved my issue.

Related

MainApplication.java:9: Error: Packagecom.reactnativecommunity.webview does not exist

% npx react-native run-android Starting JS server... Building and
installing the app on the device (cd android && ./gradlew
installDebug)...
Configure project :react-native-reanimated WARNING: The specified Android SDK Build Tools version (28.0.2) is ignored, as it is below
the minimum supported version (29.0.2) for Android Gradle Plugin
4.1.0. Android SDK Build Tools 29.0.2 will be used. To suppress this warning, remove "buildToolsVersion '28.0.2'" from your build.gradle
file, as each version of the Android Gradle Plugin now has a default
version of the build tools. Warning: Mapping new ns
http://schemas.android.com/repository/android/common/02 to old ns
http://schemas.android.com/repository/android/common/01 Warning:
Mapping new ns
http://schemas.android.com/repository/android/generic/02 to old ns
http://schemas.android.com/repository/android/generic/01 Warning:
Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02
to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns
http://schemas.android.com/sdk/android/repo/repository2/02 to old ns
http://schemas.android.com/sdk/android/repo/repository2/01 Warning:
Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02
to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Configure project :react-native-linear-gradient WARNING: Configuration 'provided' is obsolete and has been replaced with
'compileOnly'. It will be removed in version 5.0 of the Android Gradle
plugin. For more information, see
http://d.android.com/r/tools/update-dependency-configurations.html.
Configure project :react-native-orientation WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and
'api'. It will be removed in version 5.0 of the Android Gradle plugin.
For more information, see
http://d.android.com/r/tools/update-dependency-configurations.html.
Configure project :app WARNING: The option 'android.useDeprecatedNdk' is deprecated. The current default is
'false'. It has been removed from the current version of the Android
Gradle plugin. NdkCompile is no longer supported WARNING:
Configuration 'compile' is obsolete and has been replaced with
'implementation' and 'api'. It will be removed in version 5.0 of the
Android Gradle plugin. For more information, see
http://d.android.com/r/tools/update-dependency-configurations.html.
WARNING: API 'variant.getMergeResources()' is obsolete and has been
replaced with 'variant.getMergeResourcesProvider()'. It will be
removed in version 5.0 of the Android Gradle plugin. For more
information, see
https://d.android.com/r/tools/task-configuration-avoidance. To
determine what is calling variant.getMergeResources(), use
-Pandroid.debug.obsoleteApi=true on the command line to display more information. WARNING: API 'variant.getPackageApplication()' is
obsolete and has been replaced with
'variant.getPackageApplicationProvider()'. It will be removed in
version 5.0 of the Android Gradle plugin. For more information, see
https://d.android.com/r/tools/task-configuration-avoidance. To
determine what is calling variant.getPackageApplication(), use
-Pandroid.debug.obsoleteApi=true on the command line to display more information. WARNING: API 'variant.getMergeAssets()' is obsolete and
has been replaced with 'variant.getMergeAssetsProvider()'. It will be
removed in version 5.0 of the Android Gradle plugin. For more
information, see
https://d.android.com/r/tools/task-configuration-avoidance. To
determine what is calling variant.getMergeAssets(), use
-Pandroid.debug.obsoleteApi=true on the command line to display more information.
Task :app:compileDebugJavaWithJavac FAILED /Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/MainApplication.java:9:
Error: Packagecom.reactnativecommunity.webview does not exist import
com.reactnativecommunity.webview.RNCWebViewPackage;
^ /Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/MainApplication.java:18:
Error: Packagecom.beefe.picker does not exist import
com.beefe.picker.PickerViewPackage;
^ /Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/MainApplication.java:28:
Error: Packagecom.reactnativenavigation does not exist import
com.reactnativenavigation.NavigationApplication;
^ /Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/MainApplication.java:29:
Error: Packagecom.reactnativenavigation.react does not exist import
com.reactnativenavigation.react.NavigationReactNativeHost;
^ /Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/MainApplication.java:30:
Error: Packagecom.reactnativenavigation.react does not exist import
com.reactnativenavigation.react.ReactGateway;
^ /Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/MainApplication.java:36:
Error: Symbol not found public class MainApplication extends
NavigationApplication {
^ シンボル: Class NavigationApplication
/Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/MainApplication.java:45:
Error: Symbol not found
protected ReactGateway createReactGateway() {
^ シンボル: Class ReactGateway 場所: Class MainApplication
/Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/com/aitem/MainActivity.java:8:
Error: Packageandroid.support.annotation does not exist import
android.support.annotation.Nullable;
^ /Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/com/aitem/MainActivity.java:12:
Error: Packagecom.reactnativenavigation does not exist import
com.reactnativenavigation.NavigationActivity;
^ /Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/com/aitem/MainActivity.java:18:
Error: Symbol not found public class MainActivity extends
NavigationActivity {
^ シンボル: Class NavigationActivity /Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/com/aitem/MainActivity.java:21:
Error: Symbol not found
protected void onCreate(#Nullable Bundle savedInstanceState) {
^ シンボル: Class Nullable 場所: Class MainActivity
/Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/MainApplication.java:44:
Error: Method does not override super
#Override
^ /Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/MainApplication.java:46:
Error: Symbol not found
ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
^ シンボル: Class NavigationReactNativeHost 場所: Class MainApplication
/Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/MainApplication.java:47:
Error: Method does not override super
#Override
^ /Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/MainApplication.java:52:
Error: Symbol not found
return new ReactGateway(this, isDebug(), host);
^ シンボル: Class ReactGateway 場所: Class MainApplication
/Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/MainApplication.java:55:
Error: Method does not override super
#Override
^ /Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/MainApplication.java:68:
Error: Symbol not found
new PickerViewPackage(),
^ シンボル: Class PickerViewPackage 場所: Class MainApplication
/Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/MainApplication.java:70:
Error: Class FBSDKPackageのコンストラクタ FBSDKPackageは指定された型に適用できません。
new FBSDKPackage(mCallbackManager),
^ 期待値: 引数がありません 検出値: CallbackManager 理由: 実引数リストと仮引数リストの長さが異なります
/Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/MainApplication.java:72:
Error: Symbol not found
new RNCWebViewPackage(),
^ シンボル: Class RNCWebViewPackage 場所: Class MainApplication
/Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/MainApplication.java:79:
Error: Method does not override super
#Override
^ /Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/com/aitem/MainActivity.java:20:
Error: Method does not override super
#Override
^ /Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/com/aitem/MainActivity.java:22:
Error: Symbol not found
super.onCreate(savedInstanceState);
^ シンボル: 変数 super 場所: Class MainActivity /Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/com/aitem/MainActivity.java:26:
Error: Symbol not found
PackageInfo info = getPackageManager().getPackageInfo(
^ シンボル: メソッド getPackageManager() 場所: Class MainActivity
/Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/com/aitem/MainActivity.java:48:
Error: Method does not override super
#Override
^ /Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/com/aitem/MainActivity.java:50:
Error: Symbol not found
super.onActivityResult(requestCode, resultCode, data);
^ シンボル: 変数 super 場所: Class MainActivity ノート:/Users/tenna/Downloads/aitem/android/app/src/main/java/com/aitem/com/aitem/MainActivity.javaは推奨されないAPIを使用またはオーバーライドしています。
ノート:詳細は、-Xlint:deprecationオプションを指定して再コンパイルしてください。 Error25個
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output 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
Deprecated Gradle features were used in this build, making it
incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation
warnings and determine if they come from your own scripts or plugins.
See
https://docs.gradle.org/7.3.3/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 7s 145 actionable tasks: 2 executed, 143 up-to-date
Could not install the app on the device, read the error above for
details. Make sure you have an Android emulator running or a device
connected and have set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
Command failed: ./gradlew installDebug
Error: Command failed: ./gradlew installDebug
at checkExecSyncError (node:child_process:707:11)
at Object.execFileSync (node:child_process:726:15)
at runOnAllDevices (/Users/tenna/Downloads/aitem/node_modules/react-native/local-cli/runAndroid/runAndroid.js:299:19)
at buildAndRun (/Users/tenna/Downloads/aitem/node_modules/react-native/local-cli/runAndroid/runAndroid.js:135:12)
at /Users/tenna/Downloads/aitem/node_modules/react-native/local-cli/runAndroid/runAndroid.js:65:12
at processTicksAndRejections (node:internal/process/task_queues:96:5)
click on android folder
click on app folder
click on src folder
click on java folder
click on MainApplication.java file and remove Packagecom.reactnativecommunity.webview in line 9
use latest updated one
npm i react-native-webview

How do I set up Proguard with Kotlin JVM (not android) and Gradle

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

Proguard and Kotlin-Reflect/Kotlin Annotations

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.

android gradle plugin 3.0.0-alpha2: Error inflating class android.support.v7.widget.FitWindowsLinearLayout

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.** { *; }

Errors using Proguard in new IBM MobileFirst 7.1 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.