2

I am working on an Android app that integrates Tokbox's OpenTok java sdk. All was working well before I used proguard (I need to use proguard because I exceeded the dex limit).

During runtime, I encountered this error:

Could not find method javax.xml.bind.DatatypeConverter.parseBase64Binary, referenced from method com.opentok.api.OpenTokSDK.generate_token
VFY: unable to resolve static method 39502: Ljavax/xml/bind/DatatypeConverter;.parseBase64Binary (Ljava/lang/String;)[B
VFY: replacing opcode 0x71 at 0x003a
threadid=47: thread exiting with uncaught exception (group=0x4184c2a0)
java.lang.NoClassDefFoundError: javax.xml.bind.DatatypeConverter
    at com.opentok.api.OpenTokSDK.generate_token(OpenTokSDK.java:58)

I found the missing Class inside ...Java/jre7/lib/rt.jar so I tried including it in my proguard.cfg using:

-libraryjars "C:/Program Files/Java/jre7/lib/rt.jar"
-keep class javax.xml.bind.DatatypeConverter { *; }

but the error persists. I can also confirm that DatatypeConverter is not in seeds.txt nor in obfuscated.jar.

I also tried downloading jaxb-api-2.2 and including it in the build but Ant complains about

[dx] Ill-advised or mistaken usage of a core class (java.* or javax.*)
[dx] when not building a core library.

So my question is, how do you tell proguard to keep a class located in rt.jar?

Here is my proguard.cfg:

#################################################################################################
# Standard Configuration for Android App
# See http://proguard.sourceforge.net/index.html#manual/examples.html

# -libraryjars "C:/Program Files/Java/jre7/lib/rt.jar"

# -optimizationpasses 2
-dontoptimize
-dontobfuscate
-dontpreverify
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-verbose
-printseeds seeds.txt 
-printusage unused.txt 
-printmapping mapping.txt 
# -allowaccessmodification
# -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!code/allocation/variable
-keepattributes *Annotation*
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable,Signature
-keepdirectories
-repackageclasses ''

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.content.Context {
   public void *(android.view.View);
   public void *(android.view.MenuItem);
}

-keepclassmembers class * implements android.os.Parcelable {
    static android.os.Parcelable$Creator CREATOR;
}

-keepclassmembers class * implements java.io.Serializable
{
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

# adding this in to preserve line numbers so that the stack traces
# can be remapped
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable


#################################################################################################
# For RoboSpice
# See https://groups.google.com/forum/?fromgroups=#!topic/robospice/xGLRbGkLwQU
#Request classes purged by Proguard as they are "empty", others are kept
-keep class com.limbocitizen.android.playground.model.**

#RoboSpice requests and Results must be kept as they are used by reflection via Jackson
-keepclassmembers class com.limbocitizen.android.playground.request.** {
  public void set*(***);
  public *** get*();
  public *** is*();
}


### XML SERIALIZER SETTINGS

-keepclassmembers,allowobfuscation class * {
    @org.simpleframework.xml.* <fields>;
    @org.simpleframework.xml.* <init>(...);
}


### Json SERIALIZER SETTINGS
-keepclassmembers,allowobfuscation class * {
    @org.codehaus.jackson.annotate.* <fields>;
    @org.codehaus.jackson.annotate.* <init>(...);
}

-keepclasseswithmembers class * {
    native <methods>;
}

#################################################################################################
# For Actionbarsherlock
# See http://actionbarsherlock.com/faq.html

-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }

-keepattributes *Annotation*


#################################################################################################
# My Code

-dontwarn **CompatHoneycomb
-dontwarn **CompatCreatorHoneycombMR2
-dontwarn android.support.**
-dontwarn biz.source_code.base64Coder.**
-dontwarn chesspresso.**
-dontwarn org.bouncycastle.**
-dontwarn com.bst.**
-dontwarn com.bugsense.**
-dontwarn com.facebook.**
-dontwarn com.flurry.**
-dontwarn com.google.android.**
-dontwarn com.google.android.youtube.player.**
-dontwarn com.google.common.**
-dontwarn com.google.gson.**
-dontwarn com.nostra13.**
-dontwarn com.octo.android.robospice.persistence.**
-dontwarn com.opentok.**
-dontwarn com.parse.**
-dontwarn com.pubnub.api.**
-dontwarn com.samsung.**
-dontwarn com.sun.istack.internal.**
-dontwarn com.sun.xml.internal.**
-dontwarn com.testflightapp.**
-dontwarn com.tokbox.**
-dontwarn java.awt.**
-dontwarn java.nio.**
-dontwarn java.beans.**
-dontwarn java.util.**
-dontwarn javax.security.**
-dontwarn javax.xml.**
-dontwarn main.java.tokbox.org.**
-dontwarn org.apache.**
-dontwarn org.apache.commons.pool.**
-dontwarn org.ccil.cowan.tagsoup.**
-dontwarn org.codehaus.jackson.**
-dontwarn org.msgpack.**
-dontwarn org.shaded.apache.**
-dontwarn org.slf4j.**
-dontwarn org.springframework.**
-dontwarn org.w3c.dom.**
-dontwarn org.xml.sax.**
-dontwarn tokbox.org.**

-dontnote **ILicensingService

-keep class * extends com.samsung.** { *; }
-keep class android.support.v4.content.Loader { *; }
-keep class android.support.v4.content.Loader$OnLoadCompleteListener { *; }
-keep class com.createsend.util.jersey.JsonProvider { *; }
-keep class com.google.android.gms.maps.GoogleMapOptions { *; }
-keep class com.google.android.gms.maps.model.CameraPosition { *; }
-keep class com.opentok.** { *; }
-keep class com.tokbox.** { *; }
-keep class com.parse.** { *; }
-keep class com.samsung.** { *; }
-keep class javax.xml.** { *; }
-keep class javax.xml.bind.DatatypeConverter { *; }
-keep class main.java.tokbox.org.** { *; }
-keep class org.codehaus.jackson.** { *; }
-keep class org.osgi.framework.** { *; }
-keep class tokbox.org.** { *; }

1 Answer 1

1

I had included external libs and I just added this to my proguard config file

 -keep class com.opentok.** { *; }
 -dontwarn com.opentok.** 

or for Twitter4j.jar

 -keep class twitter4j.** { *; }
 -dontwarn twitter4j.** 

Also, For your information, I generally put .jar files in project's lib folder

and then define them in proguard config file this way

#-injars bin/classes

#-injars libs

#-outjars bin/classes-processed.jar



-libraryjars <java.home>/jre/lib/rt.jar

-libraryjars <java.home>/lib/tools.jar

-libraryjars /libs/twitter4j-core-3.0.3.jar 
1
  • Hi RDC, I already did "-keep class com.opentok.** { *; }" and "-libraryjars <java.home>/jre/lib/rt.jar" (you can see it on my proguard.cfg). I also put each .jar file (except the rt.jar) in my project's lib folder.
    – aysonje
    Nov 27, 2013 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.