Genson with Android - Proguard config - android

I have a problem with proguard config in Android Project.
I'm using Genson to parse incoming JSON data.
It is fast and there is no need for extra configuration or deserializers, because on the Server-side there is also Genson.
Everything works fine in debug mode, but in release, with proguard it doesn't.
Unfortunately I have some error during runtime:
FATAL EXCEPTION: main
Process: com.es.mobile.meedy, PID: 16650
java.lang.UnsupportedOperationException: Couldn't find parameter at 0 from type interface com.owlike.genson.Converter , you should first locate the parameterized type, expand it and then use typeOf.
at com.owlike.genson.reflect.TypeUtil.typeOf(Unknown Source)
at com.owlike.genson.GensonBuilder.withConverters(Unknown Source)
at com.mypackage.f.k.a(Unknown Source)
at com.a.a.b.n.a(Unknown Source)
at com.a.a.i.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
It happens even if datamodel is in keep class. I tried all configrations with keep class, classmembers, etc. What else can i do?
EDIT
What else do I know:
I tried keep class with all classes in my project.
I have keep class with genson (-keep class com.owlike.genson.** { *; })
Instanceof with my class shows that it is instance of com.owlike.genson.Converter

The solution to the problem was to add -keepattributes Signature
If annotations are being used then this option should be enabled too -keepattributes *Annotation*
Also the application class being ser/de by Genson must also be provided:
-keep class com.mypackage.model.** { *; }

-keep class com.owlike.genson.*{ *; }
Add that line to your ProGuard configuration.
-keep [,modifier,...] class_specification
Specifies classes and class members (fields and methods) to be preserved as entry points to your
code. For example, in order to keep an application, you can specify
the main class along with its main method. In order to process a
library, you should specify all publicly accessible elements.

Related

Appsflyer Crash : Fatal Exception: java.lang.NoSuchMethodError for MultipleInstallBroadcastReceiver.java line 43

I am getting a Crash which is reported in Crashlytics for com.appsflyer.MultipleInstallBroadcastReceiver.onReceive in MultipleInstallBroadcastReceiver.java class
This Crash is been reported for few users in all the android verisons
Fatal Exception: java.lang.NoSuchMethodError: No virtual method 藡(Landroid/content/Context;Landroid/content/Intent;)V in class Lcom/appsflyer/AppsFlyerLib; or its super classes (declaration of 'com.appsflyer.AppsFlyerLib' appears in /data/app/com.rapido.passenger-1/base.apk)
at com.appsflyer.MultipleInstallBroadcastReceiver.onReceive(MultipleInstallBroadcastReceiver.java:43)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3112)
at android.app.ActivityThread.-wrap18(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1627)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:165)
at android.app.ActivityThread.main(ActivityThread.java:6375)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
From the stack trace it seems to be an obfuscation issue (looking at the method name 藡)
What is the SDK version being used? Are there any proGuard (or other tool) rules configured for AppsFlyer?
If not I would suggest adding a -keep class com.appsflyer.** { *; } rule.
If you do not wish to share any additional information publicly, you can open a ticket with support#appsflyer.com, with the SDK version, any obfuscation related information and a link to this thread.

What are the recommended proguard settings for android support library?

I am using android-support-library-v7 in my project and of course I would like to use progurad to minimize and obfuscate my code.
The problem is that if I use proguard I get errors similar to this:
FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{org.example.project/org.example.project.ActivityMain}: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.v7.preference.PreferenceCategory
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method) Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.v7.preference.PreferenceCategory
at android.support.v7.preference.g.a(Unknown Source)
at android.support.v7.preference.g.a(Unknown Source)
at android.support.v7.preference.g.a(Unknown Source)
at android.support.v7.preference.g.a(Unknown Source)
at android.support.v7.preference.g.a(Unknown Source)
at android.support.v7.preference.h.a(Unknown Source)
at android.support.v7.preference.h.b(Unknown Source)
at org.exampple.project.ActivityMain.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
... 11 more Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
at java.lang.Class.getConstructorOrMethod(Class.java:460)
at java.lang.Class.getConstructor(Class.java:431)
... 22 more
PreferenceCategory is used in my preferences.xml file and I guess it is accessed via reflection. Proguard if probably removes this method (or class) if it is not referenced in code when shrinking. And even if not it surely obfuscates the name.
Google in itßs usual fashion provides absolutely no documentation on the subject.
So, what are the optimum settings to achieve good shrinking and good obfuscation.
There are some similar questions on Stack Overflow, but they boil down to:
-keep class android.support.v7.** { *; }
which cleary defeats the purpose of shrinking and obfuscating.
Trying to randomly guess the settings or by try and error method is extremely time consuming.
The Support Library uses the consumerProguardFiles feature to automatically include the appropriate ProGuard if you're using Gradle, meaning you don't need to manually include anything.
Looking at the ProGuard file for preferences-v7 (stored in the proguard.txt file within the AAR), it contains the following lines:
# Preference objects are inflated via reflection
-keep public class android.support.v7.preference.Preference {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keep public class * extends android.support.v7.preference.Preference {
public <init>(android.content.Context, android.util.AttributeSet);
}
Which covers the exact method that it says you are missing (as PreferenceCategory indirectly extends Preference). Check to make sure you are using the full Gradle dependency.
Check out this project on Github that has proguard rules for popular libraries.

How to make org.apache.http.legacy work with ProGuard (azure mobile services)?

The problem:
I'm using android mobile services, which relies on androidhttpclient.
Referencing org.apache.http.legacy resolves all the problems and the app runs just fine. However, with proguard on, I keep running into issues.
The problem plays out in two scenarios. If I keep the export checkbox checked (in jave build path), I get a 'Stub!' exception as expected (see discussion below)(see screenshot for which checkbox I'm talking about)
The runtime crash of type: "Stub!":
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.stuffd/com.stuffd.MainActivity}: java.lang.RuntimeException: Stub!
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2345)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2405)
at android.app.ActivityThread.access$800(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5317)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.RuntimeException: Stub!
at org.apache.http.message.AbstractHttpMessage.(AbstractHttpMessage.java:7)
at org.apache.http.client.methods.HttpRequestBase.(HttpRequestBase.java:7)
at org.apache.http.client.methods.HttpGet.(HttpGet.java:8)
at com.microsoft.windowsazure.mobileservices.table.MobileServiceJsonTable.executeGetRecords(MobileServiceJsonTable.java:952)
at com.microsoft.windowsazure.mobileservices.table.MobileServiceJsonTable.executeUrlQuery(MobileServiceJsonTable.java:183)
at com.microsoft.windowsazure.mobileservices.table.MobileServiceJsonTable.execute(MobileServiceJsonTable.java:160)
at com.microsoft.windowsazure.mobileservices.table.MobileServiceTable.execute(MobileServiceTable.java:158)
at com.microsoft.windowsazure.mobileservices.table.MobileServiceTable.execute(MobileServiceTable.java:249)
at com.microsoft.windowsazure.mobileservices.table.query.ExecutableQuery.execute(ExecutableQuery.java:101)
If however, I keep the checkbox unchecked (as suggested - see discussion below), I get and AbstractMethodError exception.
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:811)
Caused by: java.lang.AbstractMethodError: abstract method "java.lang.String org.apache.http.client.methods.HttpRequestBase.getMethod()"
at android.net.http.AndroidHttpClient.getMethod(AndroidHttpClient.java:283)
at android.net.http.AndroidHttpClient.execute(AndroidHttpClient.java:301)
proguard config used:
-dontwarn org.apache.http.**
-dontwarn android.net.http.**
-dontwarn com.microsoft.windowsazure.mobileservices.**
Has anyone else run into this and has figured it out?
Here's what I am using, allowing the OS to properly replace the stubbed methods at runtime.
-keep class org.apache.http.** { *; }
-keep class org.apache.commons.codec.** { *; }
-keep class org.apache.commons.logging.** { *; }
-keep class android.net.compatibility.** { *; }
-keep class android.net.http.** { *; }
-dontwarn org.apache.http.**
-dontwarn android.webkit.**
It's all the stubbed packages provided by org.apache.http.legacy.jar.
You're right not exporting the legacy apache lib. However it has to be located outside the libs folder and added to the Build Path (when using Eclipse). Otherwise it gets exported anyway with your Android Private Libraries.
I'm using GMS, Volley and AndroidHttpClient in my own communication classes.
Here's what I had to add to the proguard settings:
-dontwarn org.apache.http.**
-dontwarn com.google.android.gms.**
-dontwarn com.android.volley.toolbox.**
-dontwarn com.myapp.communication.**
-keep class com.google.android.gms.** { *; }

Getting Facebook com.facebook.FacebookGraphObjectException: Factory can't proxy method error

I am getting this exception. Please find below the complete stack trace.
com.facebook.FacebookGraphObjectException: Factory can't proxy method: public abstract java.lang.String com.junobe.android.junowallet.SNS.u.a()
at com.facebook.model.GraphObject$Factory.verifyCanProxyClass(SourceFile:290)
at com.facebook.model.GraphObject$Factory.createGraphObjectProxy(SourceFile:216)
at com.facebook.model.GraphObject$Factory.access$0(SourceFile:215)
at com.facebook.model.GraphObject$Factory$GraphObjectProxy.proxyGraphObjectMethods(SourceFile:583)
at com.facebook.model.GraphObject$Factory$GraphObjectProxy.invoke(SourceFile:521)
at $Proxy0.cast()
at com.facebook.Response.getGraphObjectAs(SourceFile:124)
at com.junobe.android.junowallet.SNS.FacebookOpenGraphController.handleResponse(SourceFile:568)
at com.junobe.android.junowallet.SNS.FacebookOpenGraphController.access$6(SourceFile:555)
at com.junobe.android.junowallet.SNS.FacebookOpenGraphController$3.onPostExecute(SourceFile:522)
at com.junobe.android.junowallet.SNS.FacebookOpenGraphController$3.onPostExecute(SourceFile:1)
at android.os.AsyncTask.finish(AsyncTask.java:417)
at android.os.AsyncTask.access$300(AsyncTask.java:127)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3685)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(NativeStart.java)
I am not getting this issue on all devices or all times. Identified this from crashlytics.
I have a hunch that it may be some proguard - obfuscation issue on Android.
I have added the following lines to in the proguard file (As per facebook Documentation):
-keep class com.facebook.** { *; }
-keepattributes Signature
Is there something I am missing .. Any assistance or solution would be welcome.
The only thing that I found that worked for me was to not obfuscate classes that extended facebook classes. I had a bunch of files in one package so for all those files I just excluded them by adding this to my proguard-project.txt.
-keep class com.classes.extending.facebook.** { *; }

Application class not found in Android after using ProGuard

My application worked well, without any errors, so far. But lately I've began using ProGuard to obfuscate the code now I see the following error report in the Google Play developer console:
java.lang.RuntimeException: Unable to instantiate application MYPACKAGE.MyApp: java.lang.ClassNotFoundException: MYPACKAGE.MyApp
at android.app.LoadedApk.makeApplication(LoadedApk.java:482)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3950)
at android.app.ActivityThread.access$1300(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1197)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4507)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: MYPACKAGE.MyApp
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newApplication(Instrumentation.java:945)
at android.app.LoadedApk.makeApplication(LoadedApk.java:477)
MyApp is the custom application class, obviously. There's only one error report on that issue so far, although there are 10,000+ active installations. Does that mean I shouldn't bother with that problem or could it be a serious issue? How can I resolve this?
try add this lines:
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
to proguard.cfg file
ProGuard simply replaces class names by obfuscated class names. If the processed code works on one device (or 10,000+ devices), it should work on all devices.
Moreover, if you disassemble the processed application, you'll see that mypackage.MyApp is still there, with its original name. The default integration of ProGuard in the Android build takes care of keeping activities, services, etc, without any need for additional -keep options.
In short, this is some sort of fluke, most probably unrelated to obfuscation. Simply reinstalling the application may help.
Seems like your class names are missing in proguard's obfuscation configuration. Add the following to your proguard.cfg with the missing class names.
-keep public class your_missing_class_full_name

Categories

Resources