Status Update
Comments
ca...@careem.com <ca...@careem.com> #3
ze...@google.com <ze...@google.com> #4
ca...@careem.com <ca...@careem.com> #5
ze...@google.com <ze...@google.com> #6
Thanks for class name. The issue here is that R8 is optimizing better now and will remove additional methods that are statically known to not be called. The concrete change for this case was in CL:
In your case, there is no statically determined point that ever calls the constructor of InvitationCreditModel
and so R8 makes it abstract if possible or when not, as in the case of a constructor, it creates a throw null
method body. To avoid this you will need a keep rule on the class and its <init> method.
Now, the point I'm not sure about is that the keep rules for the members are active, namely:
-keepclassmembers class com.careem.acma.**.models.** {
<fields>;
}
which keeps the field names in place (verified that it does actually do that), then the default constructor should be kept too.
Your build is in R8 compatibility mode, which usually means that a keep rule will implicitly keep the default constructor, so it might be most consistent that when the above rule is active, it should imply the default constructor is kept too (in R8 compatibility mode only).
I'll get back to you once we have a resolution on that. For the time being, your amended rule is a good workaround and is R8 full-mode ready.
ca...@careem.com <ca...@careem.com> #7
Thanks for your detailed replied. That makes sense to me now.
For the time being, would you suggest I open an issue on GSON project to amend their R8 rules ?
ze...@google.com <ze...@google.com> #8
I'll take it up with the team and get back on that point as well.
ze...@google.com <ze...@google.com> #9
After some discussion, it appears to be an error that R8 in compatibility mode does not implicitly retain the default constructor <init>()
. We will look into a fix for this. In the meantime, the workaround will need to remain in place. We do not see a way of updating the GSON rules as the library does not give a way to quantify which types need their default constructors kept. It will need to be detailed by the applications using GSON.
ca...@careem.com <ca...@careem.com> #10
Thanks about this.
I agree from library side I dont see a way to update the gson rules within the library.
I meant the suggested rules in
ze...@google.com <ze...@google.com> #11
Looking further into this there are a few more details:
- Neither PG or R8 (compat) will keep the default constructor with the
keepclassmembers
rule. - The GSON library makes several attempts at finding an object allocator, first by looking for a default constructor, and if not found it creates an "unsafe" allocator using runtime internal allocation.
Due to 1. the shrinkers and rules are WAI, so there should not need to be any changes to the suggested GSON rules or to the interpretation of the rules. Due to 2. R8 will cause failures as it does not remove the default constructor but removes its body. Thus GSON thinks it has a valid constructor that then fails when invoked.
I filed
ap...@google.com <ap...@google.com> #12
Branch: main
commit eda0cc750ab5dba313433321a7c295560d270475
Author: Ian Zerny <zerny@google.com>
Date: Mon Sep 26 09:58:56 2022
Don't implicitly keep default constructors for keepclassmembers.
This change also disallows optimizing implicitly kept initializers
which was also an oversight as the callsite info for them is
incomplete.
Bug:
Bug:
Change-Id: I80d5afde0642d7061684551b30a295b0b5fcde93
M src/main/java/com/android/tools/r8/shaking/Enqueuer.java
M src/test/java/com/android/tools/r8/shaking/forceproguardcompatibility/defaultctor/KeepClassMembersDefaultCtorTest.java
A src/test/java/com/android/tools/r8/shaking/forceproguardcompatibility/defaultctor/KeepClassesWithMembersDefaultCtorTest.java
ap...@google.com <ap...@google.com> #13
Branch: main
commit 75f0c9c853e8b580d7edf9ede42ae64ec0224eac
Author: Ian Zerny <zerny@google.com>
Date: Fri Sep 23 11:20:12 2022
Regression test for removing default constructor.
Bug:
Bug:
Change-Id: Ia179d79e0d1261c82e7121aaa4086a13824b23e2
A src/test/java/com/android/tools/r8/shaking/forceproguardcompatibility/defaultctor/KeepClassMembersDefaultCtorTest.java
ap...@google.com <ap...@google.com> #14
Branch: 4.0
commit 79a8b336f277438a68e3fa7032b9796d3a63725e
Author: Ian Zerny <zerny@google.com>
Date: Mon Sep 26 12:22:44 2022
Version 4.0.30
Bug:
Bug:
Change-Id: I62c3526b3adc0ed49c5b6ec82037ac8a9459dd95
M src/main/java/com/android/tools/r8/Version.java
ap...@google.com <ap...@google.com> #15
Branch: 4.0
commit 0cd1cf28ffb9bb1739b6c90ad6868da18eb82d23
Author: Ian Zerny <zerny@google.com>
Date: Mon Sep 26 11:39:06 2022
Don't implicitly keep default constructors for keepclassmembers.
This change also disallows optimizing implicitly kept initializers
which was also an oversight as the callsite info for them is
incomplete.
Bug:
Bug:
Change-Id: I80d5afde0642d7061684551b30a295b0b5fcde93
M src/main/java/com/android/tools/r8/shaking/Enqueuer.java
M src/test/java/com/android/tools/r8/shaking/forceproguardcompatibility/defaultctor/KeepClassMembersDefaultCtorTest.java
A src/test/java/com/android/tools/r8/shaking/forceproguardcompatibility/defaultctor/KeepClassesWithMembersDefaultCtorTest.java
ap...@google.com <ap...@google.com> #16
Branch: 4.0
commit 8667680870d12d832ffc08aebddd8be520b35b74
Author: Ian Zerny <zerny@google.com>
Date: Mon Sep 26 11:38:58 2022
Regression test for removing default constructor.
Bug:
Bug:
Change-Id: Ia179d79e0d1261c82e7121aaa4086a13824b23e2
A src/test/java/com/android/tools/r8/shaking/forceproguardcompatibility/defaultctor/KeepClassMembersDefaultCtorTest.java
ap...@google.com <ap...@google.com> #17
Branch: 3.3
commit 007b645a73a89e0285924facc8c4c511efdc585b
Author: Ian Zerny <zerny@google.com>
Date: Mon Sep 26 11:35:06 2022
Version 3.3.81
Bug:
Bug:
Change-Id: I1710f7a4d22e66f9282fb8d5a20ac9bc8d5644ea
M src/main/java/com/android/tools/r8/Version.java
ap...@google.com <ap...@google.com> #18
Branch: 3.3
commit c6bd011d91d6230f30e8fe925afdc8880a0a584e
Author: Ian Zerny <zerny@google.com>
Date: Mon Sep 26 11:34:47 2022
Don't implicitly keep default constructors for keepclassmembers.
This change also disallows optimizing implicitly kept initializers
which was also an oversight as the callsite info for them is
incomplete.
Bug:
Bug:
Change-Id: I80d5afde0642d7061684551b30a295b0b5fcde93
M src/main/java/com/android/tools/r8/shaking/Enqueuer.java
M src/test/java/com/android/tools/r8/shaking/forceproguardcompatibility/defaultctor/KeepClassMembersDefaultCtorTest.java
A src/test/java/com/android/tools/r8/shaking/forceproguardcompatibility/defaultctor/KeepClassesWithMembersDefaultCtorTest.java
ap...@google.com <ap...@google.com> #19
Branch: 3.3
commit e321b451f76ae1b2f9a7694ec512b95c4788d0bb
Author: Ian Zerny <zerny@google.com>
Date: Mon Sep 26 11:32:02 2022
Regression test for removing default constructor.
Bug:
Bug:
Change-Id: Ia179d79e0d1261c82e7121aaa4086a13824b23e2
A src/test/java/com/android/tools/r8/shaking/forceproguardcompatibility/defaultctor/KeepClassMembersDefaultCtorTest.java
ap...@google.com <ap...@google.com> #20
Branch: 4.0
commit 0cd1cf28ffb9bb1739b6c90ad6868da18eb82d23
Author: Ian Zerny <zerny@google.com>
Date: Mon Sep 26 11:39:06 2022
Don't implicitly keep default constructors for keepclassmembers.
This change also disallows optimizing implicitly kept initializers
which was also an oversight as the callsite info for them is
incomplete.
Bug:
Bug:
Change-Id: I80d5afde0642d7061684551b30a295b0b5fcde93
M src/main/java/com/android/tools/r8/shaking/Enqueuer.java
M src/test/java/com/android/tools/r8/shaking/forceproguardcompatibility/defaultctor/KeepClassMembersDefaultCtorTest.java
A src/test/java/com/android/tools/r8/shaking/forceproguardcompatibility/defaultctor/KeepClassesWithMembersDefaultCtorTest.java
ap...@google.com <ap...@google.com> #21
Branch: 4.0
commit 8667680870d12d832ffc08aebddd8be520b35b74
Author: Ian Zerny <zerny@google.com>
Date: Mon Sep 26 11:38:58 2022
Regression test for removing default constructor.
Bug:
Bug:
Change-Id: Ia179d79e0d1261c82e7121aaa4086a13824b23e2
A src/test/java/com/android/tools/r8/shaking/forceproguardcompatibility/defaultctor/KeepClassMembersDefaultCtorTest.java
ze...@google.com <ze...@google.com> #22
A fix for this has landed on the R8 release branches. Let us know if it resolves the issue for you locally.
To update your AGP 7.3 based build, you can manually link to the R8 version 3.3.81 or above using:
pluginManagement {
buildscript {
repositories {
mavenCentral()
maven {
url = uri("https://storage.googleapis.com/r8-releases/raw")
}
}
dependencies {
classpath("com.android.tools:r8:3.3.81")
}
}
}
ca...@careem.com <ca...@careem.com> #23
tested. looks like the problem has been fixed from our side.
Thanks for the help and the detailed explanations. Appreciated!
op...@gmail.com <op...@gmail.com> #24
Hi everyone,
I am facing a very similar issue with AGP 7.3.1 (which is using r8 3.3.83).
My GSON rules are exactly same with
Fatal Exception: java.lang.RuntimeException: Failed to invoke public n5.b$d0() with no args
at com.google.gson.internal.ConstructorConstructor$9.construct(ConstructorConstructor.java:252)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:256)
at com.google.gson.Gson.fromJson(Gson.java:1058)
at com.google.gson.Gson.fromJson(Gson.java:1016)
at com.google.gson.Gson.fromJson(Gson.java:959)
On below model as one of its values is default.
class Model(
@SerializedName("first") val first: String? = null,
@SerializedName("second") val second: String
)
If I remove the default value, constructor remains ok after r8 optimization. Otherwise I need to keep init explicitly as mentioned above in the issue.
I have put this here since it seems related with the issue, but I can create another if it will be more appropriate.
ze...@google.com <ze...@google.com> #26
Thanks for reaching out. I filed a new issue
Description
Hi guys, we are investigating an issue that happened once we upgraded to AGP 7.3.0-rc.
One of our model class, accessed and instantiated by GSON using reflection started throwing an NPE at construction time, which sounded odd as the constructor is default-empty.
Here is the stacktrace:
I've tried using R8 "4.0.23-dev" and "3.3.75" (btw 3.3.75 is not tagged on the r8 git repo, but available on maven.google.com. I guess this is the version bound with AGP 7.3.0?) without any success.
I confirm that the GSON rules are following:https://r8.googlesource.com/r8/+/refs/heads/main/compatibility-faq.md
Checking the smali files in the apk I realized that the empty constructor the above class contained a 'throw p0' call.
Workaround I applied for now was to explicitly keep the empty constructor. after doing this the smali contained the correct code. (please refer to the screenshot from the smali files).
What can we do to help you debug this?