Is there any proguard rules should use while using EncryptedSharedPreferences? - android

before using EncryptedSharedPreferences my app works fine in release mode with (minifyEnabled = true), After adding the security library (version 1.0.0-rc01) to my application the app crash while opening and if i use (minifyEnabled = false) the app works fine, i think i missing something to add it in proguard-rules.pro but i have searched a lot did not found anything.

Looks like something wrong with Tink obfuscation. My current workaround is add this rule to proguard:
-keep class com.google.crypto.tink.** { *; }
But also keep track of updates of issue here.
UPDATE - 06.01.2020
There is more effective solution (thanks #jtsalva to pointing out):
-keepclassmembers class * extends com.google.crypto.tink.shaded.protobuf.GeneratedMessageLite {
<fields>;
}
UPDATE - 08.19.2020
This issue should now fixed in Version 1.0.0-rc03

This issue has been answered with a more targeted proguard rule here
-keepclassmembers class * extends com.google.crypto.tink.shaded.protobuf.GeneratedMessageLite {
<fields>;
}
This saves my app ~0.2MB compared to the currently accepted answer

i try all above . not working for my case.
this what i do and work perfect:
-keepclassmembers class * extends com.google** {
<fields>; }

Related

Unresolved class name warning in proguard android [duplicate]

When I update to Android Studio 4.0 proguard-rules it shows warning Unresolved class name. Below is example but I sure it still waring the exist class in my project.
-keep class com.squareup.haha.** { *; }
-keep class com.squareup.leakcanary.** { *; }
If I change from ** to * this warning is gone.
-keep class com.squareup.haha.* { *; }
-keep class com.squareup.leakcanary.* { *; }
Does anyone get this? Should I ignore this warning or it's bug of Android Studio 4.0?
Update
I find it's bug, it already assigned but not resolved https://issuetracker.google.com/issues/153616200
Update July
Google team already analysis and increase priory of this bug, it may be related to a newer version of R8.
Update August
Fixed in AS 4.2 Canary 9
Check this issue: https://issuetracker.google.com/issues/147802433
`If you right-click on error, there is option "suppress for statement", after that AS adds a comment such as:
noinspection ShrinkerUnresolvedReference
-keep class not.existing
And with this comment there is no error for "not.existing".`
Replace .** with ** as workaround. No compile error and classes are kept.
-keep class com.squareup.haha** { *; }
-keep class com.squareup.leakcanary** { *; }
This issue is fixed in Android Studio 4.2 Canary 8. Please find the release notes here https://androidstudio.googleblog.com/2020/08/android-studio-42-canary-8-available.html and check for this issue id #153616200
A folder and its subfile. I have tested this:
com.xx.xx.* { *; }
I guess that it may contain multiply folders and subfile. I've not tested this:
com.xx.xx.**.* {*;}
All of these answers are mere non-sense because:
LeakCanary is being added as debugImplementation.
it makes no sense to have rules for classes which do not exist in release builds.
it makes even less sense to obfuscate debug builds.
In case you may require any of these rules, you've added it to the wrong build-type.
replace
.**
with
.*.*
result
-keep class com.squareup.haha.*.* { *; }
-keep class com.squareup.leakcanary.*.* { *; }

Finotes not reporting issues

I am using Automated bug reporting SDK finotes in android.
I had integrated the sdk and it was reporting issues during development
but I created a release build for testing. Looks like it is not reporting issues anymore.
Any help will be appreciated.
As per their documentation make sure that you add the following in your pro-guard configuration
-keep class com.finotes.android.finotescore.* { *; }
-keepclassmembers class * {
#com.finotes.android.finotescore.annotation.Observe *;
}
Also make sure that, in init() function doesn’t have their dry run turned ON
dryRun flag will prevent the issues from syncing to their dashboard.
For release build, change init() in Application class to,
Fn.init(this);

‘abstract method not implemented’ on start android app with Crashlytics (Fabric)

I added Crashlytics to my android app (via Idea plugin).
When my app starts I get next error:
java.lang.AbstractMethodError: abstract method not implemented
at io.fabric.sdk.android.ActivityLifecycleManager$ActivityLifecycleCallbacksWrapper$1.onActivityStarted(ActivityLifecycleManager.java)
at android.app.Application.dispatchActivityStarted(Application.java:199)
at android.app.Activity.onStart(Activity.java:1048)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:536)
I completely can't figure out why this happens. Maybe someone faced with this issue?
As mentioned above (by Chris), proguard stripping out something it isn't able to discern as being used. And it really stripping Crashlytics/Fabric classes.
For avoid this, just need add these lines to proguard config file:
-keep class com.crashlytics.** { *; }
-keep class io.fabric.** { *; }
-dontwarn com.crashlytics.**

proguard causes a crash in google play services' ActivityRecognitionResult getMostProbableActivity

I've recently released an app to the play store, and while it works perfectly fine without proguard, i've got an unexpected crash when i did decide to use it.
I've looked here for the recommended proguard rules for google play services, i've also tried adding another line for this case. Here's what I got (the third line is for my app):
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep class * implements com.google.android.gms.internal.ae
-keep class * extends il.co.kix.minitasker.EntityBase
Here's the crash report after doing a retrace
android.os.BadParcelableException: Parcelable protocol requires a Parcelable.Creator object called CREATOR on class com.google.android.gms.location.ActivityRecognitionResult
at android.os.Parcel.readParcelable(Parcel.java:2086)
at android.os.Parcel.readValue(Parcel.java:1965)
at android.os.Parcel.readMapInternal(Parcel.java:2226)
at android.os.Bundle.unparcel(Bundle.java:223)
at android.os.Bundle.containsKey(Bundle.java:271)
at android.content.Intent.hasExtra(Intent.java:4116)
at com.google.android.gms.location.ActivityRecognitionResult.boolean hasResult(android.content.Intent)(Unknown Source)
com.google.android.gms.location.DetectedActivity getMostProbableActivity()
at il.co.kix.minitasker.ActivityRecognitionIntentService.void onHandleIntent(android.content.Intent)(Unknown Source)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:60)
The offending lines of code probably are:
...
#Override
protected void onHandleIntent(Intent intent) {
if (ActivityRecognitionResult.hasResult(intent)) {
ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
DetectedActivity mostProbableActivity = result.getMostProbableActivity();
...
Can anyone help out with a rule to add? I don't want to disable it all together but it does fix the issue.
The Android runtime accesses these CREATOR fields by means of reflection, which is generally impossible to detect using static analysis. You therefore need to tell ProGuard to preserve them:
-keepclassmembers class * implements android.os.Parcelable {
static ** CREATOR;
}
This doesn't seem to be a standard setting in android-sdk/tools/proguard/proguard-android.txt, but it probably should be.
This problem drove me insane. Proguard is stripping internal classes that are not explicitly imported. Even worse, this problem did not exist for me (after using Proguard) then one day is suddenly showed up after a few little code changes.
I added a swathe of Proguard flags to fix the issue. In the end, I am not sure which one did the trick:
Definitely add these three:
-keep class android.os.Parcelable.Creator
-keep class com.google.android.gms.location.ActivityRecognitionResult
-keep class com.google.android.gms.** {*;}
You can also try:
-dontshrink
-dontoptimize
at the top
Honestly it's a dependency-walker type problem and Proguard should be better than this, but I did eventually fix it as above.

Phonegap 2.4 Android Proguard config

I've upgraded a build from Phonegap (Cordova) 2.0 to 2.4 and everything was working fine in dev until I actually came to testing the final release apk. What I'm finding, after a lot of time wasted, is that for some reason now when I run the build my proguard config is breaking the phonegap build in some way that means that when it runs the deviceready is never called. There seem to be no errors when building, nor running and nothing as far as I can see but I'm guessing something is silently failing in the cordova js as i'm not getting compile / log errors on the device.
As I say this is ONLY when having ran the Proguard obfs in the build process. If i turn off Proguard it all works fine. I reverted all my code back to 2.0 to be sure and that is all fine so somewhere along the way there has been a stuble change that is seemingly not documented / or nobody has hit just yet (2.4 only came out a few weeks ago - at time of writing 26th feb 2013).
My Proguard config contains the following for phonegap (as well as some other standard config)
-keep public class * extends com.phonegap.api.Plugin
-keep public class * extends org.apache.cordova.api.Plugin
-keep public class org.apache.cordova.DroidGap
-keep public class org.apache.cordova.**
-keep public class org.apache.**
-dontwarn android.webkit.*
-dontwarn org.apache.**
and decompiling the dex doesn't seem to throw any light - everything looks ok at a glance...
Anyone have any ideas???
Try replacing the Cordova "keep" settings in your proguard-project.txt with the following line, which should maintain all Cordova classes, fields, and methods, both public and private (and thus reenable deviceready):
-keep class org.apache.cordova.** { *; }
Then you just need to include your class(es) (presumably extending CordovaPlugin, not just Plugin) e.g.
pre-v3:
-keep public class * extends org.apache.cordova.api.CordovaPlugin
v3+:
-keep public class * extends org.apache.cordova.CordovaPlugin
Phonegap Plugins are being excluded from the final APK I guess. Cordova.js probably doesn't even exist to give errors.

Categories

Resources