0

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.*
Alex Filatov
  • 2,232
  • 3
  • 32
  • 39

2 Answers2

0

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

Community
  • 1
  • 1
DoraC
  • 332
  • 1
  • 5
  • Thanks for your answer, however what I don't really understand is why should I have to modify the configuration used as template for a MobileFirst application. The video and tutorials do not include any "add custom configurations to file" section, so it should work for a new project like this one without any changes. – user2363813 May 16 '16 at 21:18
  • Hi @user2363813, I was able to reproduce your issue. I agree that with a new MobileFirst default project, the default proguard configurations should work without any changes. If you are an IBM customer, please submit a PMR so we can further look into this issue. – DoraC May 16 '16 at 22:43
0

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.

S.A.Norton Stanley
  • 1,833
  • 3
  • 23
  • 37