butterknife is not working when in signed apk - android

I created an app using butterknife to implement onclick, ontouch,etc function, it works fine when I test it on my android devices, and it also works good when I install the debug-apk in the android deivces. However, when I generated an signed apk and try to run it in my android device, the "onclick" and "ontouch" are not working.I generated the apk using Android studio. Anyone knows the reason why this happens?

Copied from http://jakewharton.github.io/butterknife/
Use these rules in proguard-rules.pro file
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keepclasseswithmembernames class * {
#butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
#butterknife.* <methods>;
}

Add
-keepnames class * { #butterknife.Bind *;}
to the proguard file

Related

Worklight push notification not working after applying proguard

I am using IBM's mobilefirst worklight version 6.3 for push notification. Everything works fine when i dont apply proguard.
When i apply proguard and run the build while subscribing for the push notification only i get the following exception.
java.lang.RuntimeException: Failed to find the icon resource. Add the icon file under the /res/drawable folder.
I have the push.png named file in the drawable folder.
Any suggestions on how to handle that on the proguard or is it a worklights bug?
had the same issue with another third party library but it was resolved when i added keep class com.classname.** {*;} i did the same for worklight as well -keep class com.worklight.** {*;} but it is of no use.
below is the proguard configuration that i have used
-keepclassmembers class * {
#android.webkit.JavascriptInterface <methods>;
}
-keep class com.google.gson.Gson
-keep class com.billdesk.** {*;}
-keep public class com.worklight.** {*;}
-dontwarn com.worklight.**
-dontwarn com.auth0.jwt.**
-dontwarn com.squareup.picasso.**
-dontwarn com.viewpagerindicator.**
-dontwarn org.bouncycastle.**
MobileFirst 6.3 does not officially support obfuscation using Proguard.
Even so, an Android project obfuscated using Proguard works fine without issues in most cases.
I am not able to recreate the issue you mention.I tested the MFP 6.3 Eventsource notifications sample after obfuscating with Proguard and the application worked fine. No runtime exceptions were seen.
Android SDK Tools : 25.1.1
Target API Level : 19
Proguard version : 4.7
To begin with:
Ensure that push.png is present in all drawable folders and not just the generic one.
Check the proguard obfusction logs to see if "push.png" is being crunched in all folders and look for error messages.
Modify the proguard configuration to contain-
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepattributes InnerClasses
-keep class **.R
-keep class **.R$* {
<fields>;
}
-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 { *; }
-keep class com.google.** { *;}
-dontwarn com.google.common.**
-dontwarn com.google.ads.**
-dontwarn com.worklight.androidgap.push.GCMIntentService
-dontwarn com.worklight.androidgap.plugin.WLInitializationPlugin
-dontwarn com.worklight.wlclient.push.GCMIntentService
-dontwarn org.bouncycastle.**
-dontwarn com.worklight.nativeandroid.common.WLUtils
-dontwarn com.worklight.wlclient.push.WLBroadcastReceiver
-dontwarn com.worklight.wlclient.push.common.*
-dontwarn com.worklight.wlclient.api.WLPush

Proguard doesnt obfuscate Class name, only methods are obfuscated

I try using Proguard in android studio, but seems like Proguard is not obfuscating the class name, for example, my app structure, and the config:
and config
but when i try trigger the exception in the app:
the exception is listed in ADB console:
only the methods are obfuscated, the MainActivity.class is not
This is an expected behaviour because the class is an activity!
All classes that are mentioned in AndroidManifest.xml have to keep their names (activities, services, providers, receivers, application, instrumentation). Otherwise the system won't be able to find them.
Gradle build automatically generates some rules for your ProGuard configuration to achieve this. It scans AndroidManifest.xml and adds rules for each class found there.
If you want to see all the rules that are used, add this line to your ProGuard rules:
-printconfiguration "build/outputs/mapping/configuration.txt"
It will create configuration.txt file containing all the rules.
There should be something like this:
# view AndroidManifest.xml #generated:50
-keep class com.github.browep.proguard.MainActivity {
<init>(...);
}
I was facing the same problems,
After updating my Android plugin for Gradle, Proguard stop obfuscating my utility and other class files.
After few searching, I found that Android studio gradle now uses newer version of Proguard.
And according to this stack-overflow answer, which stated that:
proguard automatically add rules specific for android/google package.
Therefore, After few rule changes in my app, Proguard obfuscated the class names again.
Old proguard-rules.pro:
#support-v4
##link https://stackoverflow.com/questions/18978706/obfuscate-android-support-v7-widget-gridlayout-issue
-dontwarn android.support.v4.**
-keep class android.support.v4.** { *; }
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
#support-v7
-dontwarn android.support.v7.**
-keep class android.support.v7.** { *; }
#https://stackoverflow.com/a/34895791/4754141
-keep class !android.support.v7.view.menu.**
-keep interface android.support.v7.* { *; }
#support design
##link https://stackoverflow.com/a/31028536
-dontwarn android.support.design.**
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }
#error : Note: the configuration refers to the unknown class 'com.google.vending.licensing.ILicensingService'
#solution : #link https://stackoverflow.com/a/14463528
-dontnote com.google.vending.licensing.ILicensingService
-dontnote **ILicensingService
#updating to Gradle 2.14.1 caused error : https://stackoverflow.com/q/17141832/4754141
-keepattributes EnclosingMethod
#render script
##link https://stackoverflow.com/questions/22161832/renderscript-support-library-crashes-on-x86-devices
-keepclasseswithmembernames class * { native <methods>; }
-keep class android.support.v8.renderscript.** { *; }
New proguard-rules.pro:
#https://stackoverflow.com/a/41901653/4754141
#https://stackoverflow.com/a/23840049/4754141
-keep class android.support.** { *; }
-keep interface android.support.** { *; }

Volley seems not working after ProGuard obfuscate

I have an Android app which uses Google Volley as my download broker. I just tried to use ProGuard to obfuscate the code, and find out the volley download starts failing at runtime.
Here's my ProGuard config:
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keep class com.android.volley.** { *; }
-keep interface com.android.volley.** { *; }
-keepattributes *Annotation*
-dontwarn org.apache.**
and here is the error I saw in the code:
Async download FAILED. Exception message: The chosen LogFactory implementation does not extend LogFactory. Please check your configuration. (Caused by java.lang.ClassCastException: The application has specified that a custom LogFactory implementation should be used but Class 'org.apache.commons.logging.impl.LogFactoryImpl' cannot be converted to 'a.a.a.b.c'. Please check the custom implementation. Help can be found #http://commons.apache.org/logging/troubleshooting.html.)
I was wondering if I did some proguard config caused some dependency problem. Please help out.
The Apache logging library uses some reflection on its log factories. Keeping their names should be sufficient:
-keep class org.apache.commons.logging.**
Side-note on your configuration: -keep class ..... always implies -keep interface ....., so you can leave out the latter.

App crashes on production but not in development

I just launched my brand new app on Google Play but its crashing when i try to open it. The thing is, it used to work just fine in development.
I have ProGuard enabled and i tried disabling it, generating the signed apk and manually installing it on a device.. but my app still won't open.
Since i have Crittercism enabled, after a few tries, i finally got a crash to be reported to the website, and it says:
Unable to start activity ComponentInfo{com.pizzapp.android/com.pizzapp.android.login.PAWelcomeActivity}: java.lang.RuntimeException: java.lang.NoSuchMethodException: a(Activity,int)
PAWelcomeActivity is my main activity!
my proguard-project.txt is like:
-keepattributes SourceFile, LineNumberTable, Exceptions, Signature, InnerClasses
-keep class com.newrelic.** { *; }
-keep class com.facebook.** { *; }
-keep class com.parse.** { *; }
-dontwarn com.newrelic.**
Does anybody have an idea what this crash is?
Thanks,
Newton
Update 1:
Here you can see how my package is organised:
You are probably obfuscating the Activity lifecycle method names. Make sure not to do that.
I finally solved it… the problem is that i forgot to add the ActionBarSherlock code for the proguard to work with it..
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keepattributes *Annotation*

connecting android application with akka remote server

I am building an application with android platform. Will like to design a server side akka application that will provide services in a distributed manner to the android application. Both systems are designed as separate applications. Will it be possible to connect the akka remote server with the android application. Please help me out cos I am new to both akka and android.
You can do this, but you will suffer.
You must somehow be able to access the class definitions for akka-remote and dependencies (netty, scala) from your android app. This can be problematic, since the sum of dependencies has more than 65536 methods which is Dalviks cap. (That is - your classes.dex file inside the apk cannot have more method definitions than 65536).
AFAIK, there's three main approaches:
Split up the dependencies into separate apklibs and make your apk depend on these.
I can't really recommend this since I haven't tried it.
Split up the dependencies into separate classes.dex files that you load programmatically from your app.
Probably doable. Never tried it.
Run proguard before packing your classes.dex
You'll have to battle with proguard to get the config right, and you may get strange runtime failures. My config is posted below.
Once you get akka-remote up and running on your android device you can connect to the server like in the examples in the docs. However, keep in mind that:
The IP of your Android device may or may not be available at boot time, so you may wan't to keep that part of your akka config dynamic (haven't done this myself).
The IP of your Android device may not be reachable from the server. So if you get into a state where the server needs to call the client back, it will never succeed.
My proguard.cfg (some lines are not needed - haven't bothered figure out which ones):
-dontoptimize
#-optimizationpasses 2
-dontobfuscate
-dontpreverify
-dontskipnonpubliclibraryclassmembers
-dontskipnonpubliclibraryclasses
-dontnote **
-verbose
-keep class com.typesafe.config.Config { *; }
-keep class com.typesafe.config.ConfigFactory { *; }
-keep class org.slf4j.Logger { *; }
-keep class org.slf4j.LoggerFactory { *; }
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
#Scala
-dontwarn scala.**
-keepclassmembers class * {
** MODULE$;
}
-keep class scala.Option
-keep class scala.Function1
-keep class scala.PartialFunction
#https://issues.scala-lang.org/browse/SI-5397
-keep class scala.collection.SeqLike {
public protected *;
}
-keep class scala.Tuple*
-keepclasseswithmembers public class * {
public static void main(java.lang.String[]);
}
-keep class * implements org.xml.sax.EntityResolver
-keepclassmembers class * {
** MODULE$;
}
-keepclassmembernames class scala.concurrent.forkjoin.ForkJoinPool { *; }
-keepclassmembernames class scala.concurrent.forkjoin.ForkJoinWorkerThread {
int base;
int sp;
int runState;
}
-keepclassmembernames class scala.concurrent.forkjoin.ForkJoinTask {
int status;
}
-keepclassmembernames class scala.concurrent.forkjoin.LinkedTransferQueue { *; }
#Akka
-dontwarn org.jboss.netty.logging.**
-dontwarn org.osgi.**
-dontwarn javax.servlet.**
#-dontwarn org.jboss.netty.channel.socket.http.**
## Unsafe is there at runtime
-dontwarn sun.misc.Unsafe
-keep class sun.misc.Unsafe{
*;
}
-keep class akka.** { *; }
-keep class com.google.protobuf.GeneratedMessage {
*;
}
-keep class org.javatuples.** { *; }
-keep class org.jboss.**
-dontwarn org.jboss.netty.handler.codec.marshalling.**
-dontwarn org.jboss.netty.channel.socket.nio.**
-dontwarn org.jboss.netty.handler.codec.compression.JdkZlibEncoder
-dontwarn org.jboss.netty.handler.codec.spdy.SpdyHeaderBlockZlibCompressor
-dontwarn org.jboss.netty.channel.socket.http.HttpTunnelingServlet
-dontwarn org.jboss.modules.**
-dontwarn __redirected.**
-dontwarn org.slf4j.LoggerFactory
-dontwarn org.slf4j.MarkerFactory
-dontwarn org.slf4j.MDC
-dontwarn org.slf4j.impl.AndroidLogger
-dontwarn org.slf4j.impl.AndroidLoggerFactory
Good luck.
I'm not sure if you were thinking of using the Akka remoting protocol, but if it were me, I would consider looking into the excellent HTTP+REST library Spray (http://spray.io/). I've played around with this library and it is very slick. It is well integrated with Akka and would allow you to provide REST APIs for your services. As a bonus, going REST also allows you to have services that will easily integrate with things other than your Android frontend.
I've included a couple of links as a starting point. The Google 2010 I/O talk on writing REST clients for Android apps is especially interesting:
http://www.google.com/events/io/2010/sessions/developing-RESTful-android-apps.html
http://www.techrepublic.com/blog/app-builder/calling-restful-services-from-your-android-app/1076

Categories

Resources