Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

ProGuard with Conceal v.2 #182

Open
2x2xplz opened this issue Oct 18, 2017 · 7 comments
Open

ProGuard with Conceal v.2 #182

2x2xplz opened this issue Oct 18, 2017 · 7 comments

Comments

@2x2xplz
Copy link

2x2xplz commented Oct 18, 2017

New Android project using Conceal 2.0.1 and I'm having some issues with the previous ProGuard suggestions. Conceal works fine in debug builds but not with ProGuard. I'm using Android Studio 3.0 beta 7, and testing on a device running Android 5.1.

I did eventually find settings that prevented crashes (see below) but my concern is, on other devices running other Android versions (4, or 6+), will my settings be sufficient?

As per the documentation, I include SoLoader.init(this, false) in Application.onCreate()

Finally after much trial and error I was finally able to prevent the app from crashing when I call crypto.isAvailable() by adding these lines to my ProGuard config:

-keep class com.facebook.crypto.** { *; }
-keep class com.facebook.jni.** { *; }
-keepclassmembers class com.facebook.cipher.jni.** { *; }

The first 2 lines are necessary to prevent this error:

10-17 19:25:36.342 9358-9358/? A/art: art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: java_class == null
10-17 19:25:36.342 9358-9358/? A/art: art/runtime/check_jni.cc:65]     in call to GetFieldID
10-17 19:25:36.342 9358-9358/? A/art: art/runtime/check_jni.cc:65]     from java.lang.String java.lang.Runtime.nativeLoad(java.lang.String, java.lang.ClassLoader, java.lang.String)

And the third line is required to prevent this error:

10-17 19:28:06.773 11536-11536/? E/art: Failed to register native method com.facebook.cipher.jni.DecryptHybrid.initHybrid([B[B)Lcom/facebook/jni/HybridData; in /data/app/com.<my app name>-2/base.apk
10-17 19:28:06.775 11536-11536/? E/libfb: error java.lang.NoSuchMethodError: no static or non-static method "Lcom/facebook/cipher/jni/DecryptHybrid;.initHybrid([B[B)Lcom/facebook/jni/HybridData;"

Using -keepnames for any of the 3 will not prevent the crashes

-keep class com.facebook.** { *; } is an alternative that will work, but the entirety of this package will go un-minified.

I'm no ProGuard expert so I'm unsure if my setup is optimal, any input from the project maintainers would be great, especially settings that are known to work on a wide variety of Android devices.

@abayomiAkanji
Copy link

abayomiAkanji commented Oct 26, 2017

Hey @2x2xplz , thanks for the heads-up. Very helpful. I have been battling with the crash.

As you suggested, including the code below in the proguard fixed it.

-keep class com.facebook.crypto.** { *; }
-keep class com.facebook.jni.** { *; }
-keepclassmembers class com.facebook.cipher.jni.** { *; }

@phileo
Copy link

phileo commented Nov 29, 2017

I am experiencing this problem as well.
The config file proguard_annotations.pro was supposed to provide the correct ProGuard config. However it is not working at least not on v2.0.1 AAR.

The working solution suggested by @2x2xplz is not optimal, because it effectively turns off ProGuard for the vast majority of classes in this library.
Has anyone tried building from source and successfully incorporate into a project with ProGuard turned on? Actually, how do you build from source? The instructions in the main page appear to be outdated and not working on Android Studio 3.0.1
Do we need to include DoNotStrip.java and KeepGettersAndSetters.java into our app modules?

@helios175
Copy link
Contributor

I will review the ProGuard definitions. The projects I work with use the same code but different build and proguard definitions. I must have missed something probably from the fbjni library.

@afiqiqmal
Copy link

Hey @2x2xplz , Thanks for the solutions..

-keep class com.facebook.crypto.** { *; }
-keep class com.facebook.jni.** { *; }
-keepclassmembers class com.facebook.cipher.jni.** { *; }

//just add this, everything is fine..
-dontwarn com.facebook.**

@idish
Copy link

idish commented May 4, 2018

Bump. Current proguard-annotations file is not sufficient for proguard to work.

@idish
Copy link

idish commented Jul 23, 2018

proguard-annotations is still not updated

@stkent
Copy link

stkent commented Nov 12, 2018

Still true as of 2.0.2. An update would be appreciated :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants