Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Crash with DexGuard enabled #7514

Closed
herisulistiyanto opened this issue Jun 29, 2021 · 4 comments
Closed

Android Crash with DexGuard enabled #7514

herisulistiyanto opened this issue Jun 29, 2021 · 4 comments

Comments

@herisulistiyanto
Copy link

herisulistiyanto commented Jun 29, 2021

SDK and version

SDK : Java
Version: 10.6.0

Observations

  • How frequent do the crash occur?
    100% Crash at App Start (Fresh Install & Migration Scenario)
  • Does it happen in production or during dev/test?
    It happen in dev obfuscated with DexGuard 9.1.5
  • Can the crash be reproduced by you?
    Yes, it is 100% reproduce-able
  • Can you provide instructions for how we can reproduce it?
    Build the App with DexGuard 9.1.5 enabled

Crash log / stacktrace

E/REALM: /tmp/realm-java/realm/realm-library/src/main/cpp/jni_util/java_method.cpp:33: [realm-core-11.0.2] Assertion failed: m_method_id != nullptr with (method_name, signature) =  ["runMigrationCallback", "(JLio/realm/internal/OsRealmConfig;Lio/realm/internal/OsSharedRealm$MigrationCallback;J)V"]
    <backtrace not supported on this platform>!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose

A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 20604 (ru.livestudents)

Steps & Code to Reproduce

Here's the DexGuard configuration :

-dontnote io.realm.RealmObject
-keep class * extends io.realm.RealmObject

-keep class **RealmProxy extends io.realm.RealmObject {
    public static <methods>;
}

-dontnote io.realm.ValidationList
-keepclassmembers class io.realm.ValidationList {
    public static java.util.List getProxyClasses();
}

-dontnote io.realm.exceptions.*
-dontnote io.realm.internal.*
-keep class io.realm.exceptions.RealmError       { *; }
-keep class io.realm.exceptions.RealmIOException { *; }
-keep class io.realm.internal.OutOfMemoryError   { *; }
-keep class io.realm.internal.ColumnType         { *; }
-keep class io.realm.internal.Mixed              { *; }
-keep class io.realm.internal.Row                { *; }
-keep class io.realm.internal.TableSpec          { *; }

-keepresourcefiles lib/**/librealm-jni.so
-keep class io.realm.internal.Keep
-keep @io.realm.internal.Keep class *

-keep @interface io.realm.annotations.RealmModule { *; }
-keep class io.realm.annotations.RealmModule { *; }
-keep class io.realm.annotations.RealmModule
-dontnote io.realm.annotations.RealmModule
-keep @io.realm.annotations.RealmModule class *

AGP & Gradle Version :

AGP : 3.5.3
Gradle : gradle-6.7.1-all

Been tried to use another version of Realm-Java (6.1.0), facing the same crash issue.
Is there any clue about this issue?

Thanks

@bmunkholm bmunkholm transferred this issue from realm/realm-core Jun 30, 2021
@cmelchior
Copy link
Contributor

Hi @herisulistiyanto We provide our own Proguard configuration, which should be automatically applied, but in the past we have seen various issues between Proguard and Dexguard, so I suspect this is one of them. You can see ours here: https://github.com/realm/realm-java/blob/master/realm/realm-library/proguard-rules-consumer-common.pro

I will need to investigate further to figure out exactly what could be wrong, but I suspect a temporary workaround would be to add

-keep class io.realm.internal.OsSharedRealm          { *; }

To your configuration

@herisulistiyanto
Copy link
Author

Hi @herisulistiyanto We provide our own Proguard configuration, which should be automatically applied, but in the past we have seen various issues between Proguard and Dexguard, so I suspect this is one of them. You can see ours here: https://github.com/realm/realm-java/blob/master/realm/realm-library/proguard-rules-consumer-common.pro

I will need to investigate further to figure out exactly what could be wrong, but I suspect a temporary workaround would be to add

-keep class io.realm.internal.OsSharedRealm          { *; }

To your configuration

Hi @cmelchior , thanks for the reply and suggestion.

It seems in my case there are two classes need to be preserved with DexGuard 9.x enabled :

-keep class io.realm.internal.OsSharedRealm          { *; }
-keep class io.realm.internal.RealmNotifier          { *; }

Because if i don't keep the RealmNotifier class, it still crash the App :

E/REALM: /tmp/realm-java/realm/realm-library/src/main/cpp/jni_util/java_method.cpp:33: [realm-core-11.0.2] Assertion failed: m_method_id != nullptr with (method_name, signature) =  ["beforeNotify", "()V"]
    <backtrace not supported on this platform>!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose

I've check both classes already annotated with @Keep but somehow it still stripped by DexGuard (set on dexguard config to keep annotated class also).
Not sure it is best solution but it solve my crash issue.

@cmelchior
Copy link
Contributor

Hmm, strange. Because our own configuration should account for that:

-keep class io.realm.internal.Keep
-keep @io.realm.internal.Keep class * { *; }

-keep class io.realm.internal.KeepMember
-keep @io.realm.internal.KeepMember class * { @io.realm.internal.KeepMember *; }

I wonder if our configuration is somehow not being applied? 🤔

@herisulistiyanto
Copy link
Author

herisulistiyanto commented Jun 30, 2021

Hmm, strange. Because our own configuration should account for that:

-keep class io.realm.internal.Keep
-keep @io.realm.internal.Keep class * { *; }

-keep class io.realm.internal.KeepMember
-keep @io.realm.internal.KeepMember class * { @io.realm.internal.KeepMember *; }

I wonder if our configuration is somehow not being applied? 🤔

Here's Realm DexGuard config i use :

-dontnote io.realm.RealmObject
-keep class * extends io.realm.RealmObject

-keep class **RealmProxy extends io.realm.RealmObject {
    public static <methods>;
}

-dontnote io.realm.ValidationList
-keepclassmembers class io.realm.ValidationList {
    public static java.util.List getProxyClasses();
}

-dontnote io.realm.exceptions.*
-dontnote io.realm.internal.*
-keep class io.realm.exceptions.RealmError       { *; }
-keep class io.realm.exceptions.RealmIOException { *; }
-keep class io.realm.internal.OutOfMemoryError   { *; }
-keep class io.realm.internal.ColumnType         { *; }
-keep class io.realm.internal.Mixed              { *; }
-keep class io.realm.internal.Row                { *; }
-keep class io.realm.internal.TableSpec          { *; }

-keepresourcefiles lib/**/librealm-jni.so
-keep class io.realm.internal.Keep
-keep,includedescriptorclasses @io.realm.internal.Keep class * { *; }

-keep @interface io.realm.annotations.RealmModule { *; }
-keep class io.realm.annotations.RealmModule { *; }
-keep class io.realm.annotations.RealmModule
-dontnote io.realm.annotations.RealmModule
-keep @io.realm.annotations.RealmModule class *

-keep class io.realm.internal.KeepMember
-keep @io.realm.internal.KeepMember class * { @io.realm.internal.KeepMember *; }

-keep class io.realm.RealmCollection
-keep class io.realm.OrderedRealmCollection
-keepclasseswithmembernames,includedescriptorclasses class io.realm.** { native <methods>; }

-keep class io.realm.internal.OsSharedRealm          { *; }
-keep class io.realm.internal.RealmNotifier          { *; }

the last two lines that solve the crash issue (other rules mostly the same rules from consumer-common.pro)

For the stripped annotated class, it seem there is workaround with DexGuard configuration on post processing.

It's already solved, thanks

closing the issue

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

No branches or pull requests

2 participants