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

Keep annotation does not keep class's constructor #1904

Closed
skyisle opened this issue Dec 8, 2015 · 9 comments
Closed

Keep annotation does not keep class's constructor #1904

skyisle opened this issue Dec 8, 2015 · 9 comments
Assignees
Labels

Comments

@skyisle
Copy link
Contributor

skyisle commented Dec 8, 2015

Following crash reported for my app.

Fatal Exception: java.lang.NoSuchMethodError: no non-static method "Lio/realm/exceptions/RealmError;.<init>(Ljava/lang/String;)V"
       at io.realm.internal.TableQuery.nativeImportHandoverTableViewIntoSharedGroup(TableQuery.java)
       at io.realm.internal.TableQuery.importHandoverTableView(TableQuery.java:502)
       at io.realm.RealmResults.swapTableViewPointer(RealmResults.java:691)
       at io.realm.HandlerController.completedAsyncQueriesUpdate(HandlerController.java:223)
       at io.realm.HandlerController.handleMessage(HandlerController.java:307)
       at android.os.Handler.dispatchMessage(Handler.java:98)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5525)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 

I used recommended proguard options on https://realm.io/docs/java/latest/#proguard
I think options should be changed to include constructors.

Decompiled RealmError does not contain constructor

.class public Lio/realm/exceptions/RealmError;
.super Ljava/lang/Error;
.source "RealmError.java"


# annotations
.annotation build Lio/realm/internal/Keep;
.end annotation
@skyisle
Copy link
Contributor Author

skyisle commented Dec 8, 2015

I tried
-keep @io.realm.internal.Keep class * { <init>(...); }
it works fine.

@skyisle
Copy link
Contributor Author

skyisle commented Dec 8, 2015

However RealmException has all constructors. It's very comfusing

.class public Lio/realm/exceptions/RealmException;
.super Ljava/lang/RuntimeException;
.source "RealmException.java"


# annotations
.annotation build Lio/realm/internal/Keep;
.end annotation


# direct methods
.method public constructor <init>(Ljava/lang/String;)V
    .locals 0
    .param p1, "detailMessage"    # Ljava/lang/String;

    .prologue
    .line 28
    invoke-direct {p0, p1}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;)V

    .line 29
    return-void
.end method

.method public constructor <init>(Ljava/lang/String;Ljava/lang/Throwable;)V
    .locals 0
    .param p1, "detailMessage"    # Ljava/lang/String;
    .param p2, "exception"    # Ljava/lang/Throwable;

    .prologue
    .line 32
    invoke-direct {p0, p1, p2}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;Ljava/lang/Throwable;)V

    .line 33
    return-void
.end method

@kneth
Copy link
Member

kneth commented Dec 8, 2015

@skyisle It seems you have found a work-around. We'll examine and update the Proguard recommendations when we have a better solution.

@skyisle
Copy link
Contributor Author

skyisle commented Dec 9, 2015

I think intended behavior of Keep annotation is keep everything include all method and constructors.
So I changed options to this.

-keep @io.realm.internal.Keep class * { 
  <init>(...);
  *; 
}

http://proguard.sourceforge.net/manual/usage.html#keep

@kneth kneth removed the Pending label Dec 9, 2015
@kneth
Copy link
Member

kneth commented Dec 9, 2015

@skyisle Thanks for pointing us in the right direction. We'll update the documentation.

@zaki50
Copy link
Contributor

zaki50 commented Dec 9, 2015

@skyisle I confirmed your configuration keeps the constructors. I'll update out documentation. Thank you so much.

--- before/app-release-unsigned/smali/io/realm/exceptions/RealmError.smali  2015-12-09 18:04:57.000000000 +0900
+++ after/app-release-unsigned/smali/io/realm/exceptions/RealmError.smali   2015-12-09 18:03:07.000000000 +0900
@@ -5,3 +5,13 @@
 # annotations
 .annotation build Lio/realm/internal/Keep;
 .end annotation
+
+
+# direct methods
+.method public constructor <init>(Ljava/lang/String;)V
+    .locals 0
+
+    invoke-direct {p0, p1}, Ljava/lang/Error;-><init>(Ljava/lang/String;)V
+
+    return-void
+.end method

@zaki50
Copy link
Contributor

zaki50 commented Dec 9, 2015

@skyisle It seems that *; includes <init>(...);. So I think -keep @io.realm.internal.Keep class * { *; } is enough.

What do you think?

@zaki50
Copy link
Contributor

zaki50 commented Dec 9, 2015

I update our documentation.
https://realm.io/docs/java/latest/#proguard

If <init>(...); is needed in addition to *;, please reopen this issue.

Thank you so much!

@zaki50 zaki50 closed this as completed Dec 9, 2015
@zaki50 zaki50 removed the P1 label Dec 9, 2015
@skyisle
Copy link
Contributor Author

skyisle commented Dec 9, 2015

@zaki50 You are right. I rechecked configuration with whyareyoukeeping proguard option.

-whyareyoukeeping class io.realm.exceptions.RealmError { <init>(...); }

It explains that constructor is included by *; options.

22:18:44.939 [QUIET] [system.out] Explaining why classes and class members are being kept...
22:18:44.939 [QUIET] [system.out] Printing usage to [/Users/skyisle/workspace/Lev/app/build/outputs/mapping/devMinSdk16/release/usage.txt]...
22:18:47.291 [QUIET] [system.out] 
22:18:47.292 [QUIET] [system.out] io.realm.exceptions.RealmError
22:18:47.292 [QUIET] [system.out]   is kept by a directive in the configuration.
22:18:47.292 [QUIET] [system.out] 
22:18:47.292 [QUIET] [system.out] io.realm.exceptions.RealmError: RealmError(java.lang.String) (28:29)
22:18:47.292 [QUIET] [system.out]   is kept by a directive in the configuration.
22:18:47.292 [QUIET] [system.out] 

Thanks for quick response.

skyisle added a commit to skyisle/realm-java that referenced this issue Dec 9, 2015
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants