Status Update
Comments
ch...@gmail.com <ch...@gmail.com> #2
I can reproduce this (thanks for the repro project!)
It looks like the problem is that the desugared api list from r8 contains this entry:
java/util/Collection#removeIf(Ljava/util/function/Predicate;)Z
but the bytecode here doesn't match -- it's java/util/ArrayList. Collection isn't a directly implemented interface or a direct super class, it's an interface on the super super class. The most efficient thing runtime wise would be for the signature list to inline this method on all implemented subclasses. But I should probably at least for now go and make the desugared API lookup do something similar to what it does for API lookup -- search through all super classes and interfaces as well. This isn't a new problem, so I'm very surprised this hasn't come up before (or it has, and I've forgotten).
sg...@google.com <sg...@google.com> #3
(I have a pending CL that was working to improve the handling of fields now that r8 handles desugaring fields, I'll try to dust that off and combine the fix in there.)
ch...@gmail.com <ch...@gmail.com> #4
I went to implement this, and hooked up inheritance search when analyzing the source file containing the call.
However, lint also handles the case where the library being analyzed is not using core library desugaring (for example, it may be a plain Java library). But when that library is consumed in a downstream app module, where library desugaring is turned on, lint then processes the partial results from the library and filters each violation through the desugaring allowlist.
At this point, it's tricky to do the inheritance search -- this happens when we no longer have a compilation environment and can do class inheritance lookups. So there are three possible solutions.
First, we pay the cost up front -- even when you're not using core library desugaring, we record whether the method is potentially library desugared if turned on. (This is also tricky because at this point we don't know which exact desugaring library version is used, which determines the exact list of APIs).
Or, more expensively, for every API violation of this type we store all the potential super class and interface names for each result...
Or, we handle this in the code which generates the desugaring API list, inlining all subclasses affected. This could be quite a long list, but on the other hand this list is really only intended to be machine readable.
ch...@gmail.com <ch...@gmail.com> #5
This is partially fixed now; it's fully fixed for the sample project, but in the scenario I described in comment 4, it works if you also configure library desugaring to be on in the library.
ch...@gmail.com <ch...@gmail.com> #6
likely related:
Objects.requireNonNullElse
Objects.requireNonNullElseGet
are now also showing this same false positive warning.
Android Studio Koala | 2023.3.2 Canary 2 gradle 8.6 plugin: 8.3.1
sg...@google.com <sg...@google.com>
ch...@google.com <ch...@google.com> #7
This seems unrelated. Can you file a new bug?
Specifically, for Objects.requireNonNullElse
I am not seeing a lint API error, but I am seeing a warning from IntelliJ's built-in Java inspections. These should probably not show up in Android modules. I swear we've fixed that before but I'm assuming something changed to break that.
For Objects.requireNonNullElseGet
I do see a lint API warning for that. But, that's not a recent change, right? I looked at R8's desugaring list and that method is not there. So that method does crash at runtime, right?
ap...@google.com <ap...@google.com> #8
Can you file a new bug?
fair enough - will do.
I swear we've fixed that before but I'm assuming something changed to break that.
I'm not 100% sure whether it first occurred when I moved to 8.3.1, and/or to Koala Canary 2
So that method does crash at runtime, right?
funnily enough no, even when I run on Android 8.0 (in the emulator); In fact I seem to have been using that method for 2 years now and the first of those 2 years I ran it personally on a physical device (Samsung A5 2017 with Android 8.0 / other users on?) ... and yes, I am flabbergasted as well :)
I'll try and dig a little regarding the requireNonNullElseGet first as indeed I realise it should crash, and then will file a new bug (as requireNonNullElse should work regardless)
I'll add a reference here for your enjoyment :)
ap...@google.com <ap...@google.com> #9
Actually it looks like D8 is really backporting it; I wrote this test class:
public class JavaTest {
public void test(String s) {
Objects.requireNonNullElse(s, "test");
Objects.requireNonNullElseGet(s, new Supplier<String>() {
@Override
public String get() {
return null;
}
});
}
}
Built the APK and opened the APK analyzer, drilled to this method and invoked Show Bytecode and here's what I get:
# virtual methods
.method public test(Ljava/lang/String;)V
.registers 3
.param p1, "s" # Ljava/lang/String;
.line 8
const-string v0, "test"
invoke-static {p1, v0}, Lcom/example/myapplication/JavaTest$$ExternalSyntheticBackport0;->m(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
.line 9
new-instance v0, Lcom/example/myapplication/JavaTest$1;
invoke-direct {v0, p0}, Lcom/example/myapplication/JavaTest$1;-><init>(Lcom/example/myapplication/JavaTest;)V
invoke-static {p1, v0}, Lcom/example/myapplication/JavaTest$$ExternalSyntheticBackport1;->m(Ljava/lang/Object;Ljava/util/function/Supplier;)Ljava/lang/Object;
.line 15
return-void
.end method
So both methods are desugared.
Clement/Søren, I don't see this in the backport list:
$ java -cp $ANDROID_HOME/cmdline-tools/latest/lib/r8.jar com.android.tools.r8.BackportedMethodList --min-api 15 | grep requireNonNullElse
java/util/Objects#requireNonNullElse(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
(requireNonNullElse
is there, requireNonNullElseGet
is not.)
ap...@google.com <ap...@google.com> #10
aha - so requireNonNullElseGet is not magical after all :)
Please let me know if I should still file a new bug.
tx
ap...@google.com <ap...@google.com> #11
The method Objects.requireNonNullElseGet
is a bit special in terms of backporting, as it takes an argument of type Supplier
, which was added in API level 24. For pure backporting (no desugared library) this method can only be backported from API level 24:
$ java -cp $ANDROID_HOME/cmdline-tools/latest/lib/r8.jar com.android.tools.r8.BackportedMethodList --min-api 24 | grep requireNonNullElse
java/util/Objects#requireNonNullElse(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
java/util/Objects#requireNonNullElseGet(Ljava/lang/Object;Ljava/util/function/Supplier;)Ljava/lang/Object;
Setting minSdk
below 24 (without using desugared library) this is the DEX for the test code.
.method public test(Ljava/lang/String;)V
.locals 1
.param p1, "s" # Ljava/lang/String;
.line 8
const-string v0, "test"
invoke-static {p1, v0}, Ldk/gjesse/jdk11desugaredlibrary/ObjectsTest$$ExternalSyntheticBackport0;->m(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
.line 9
new-instance v0, Ldk/gjesse/jdk11desugaredlibrary/ObjectsTest$1;
invoke-direct {v0, p0}, Ldk/gjesse/jdk11desugaredlibrary/ObjectsTest$1;-><init>(Ldk/gjesse/jdk11desugaredlibrary/ObjectsTest;)V
invoke-static {p1, v0}, Ljava/util/Objects;->requireNonNullElseGet(Ljava/lang/Object;Ljava/util/function/Supplier;)Ljava/lang/Object;
.line 15
return-void
.end method
with only Objects.requireNonNullElse
getting backported.
With desugared library enabled this change, due to two things
- desugared library adds support for
Supplier
Objects
is no longer backported, but implemented by desugared library
The "tool" com.android.tools.r8.ir.desugar.desugaredlibrary.lint.DesugaredMethodsList
is used for desugared library:
java -cp $ANDROID_HOME/cmdline-tools/latest/lib/r8.jar com.android.tools.r8.ir.desugar.desugaredlibrary.lint.DesugaredMethodsList --min-api 15 --desugared-lib META-INF/desugar/d8/desugar.json --lib $ANDROID_HOME/platforms/android-34/android.jar --desugared-lib-jar desugar_jdk_libs-2.0.4.jar | grep Objects
java/util/Objects
(META-INF/desugar/d8/desugar.json
is from desugar_jdk_libs-2.0.4.jar
is
The line java/util/Objects
indicate that all methods of Objects
are supported.
With desugared library (for any minSdk
) this is the DEX for the test code:
# virtual methods
.method public test(Ljava/lang/String;)V
.locals 1
.param p1, "s" # Ljava/lang/String;
.line 8
const-string v0, "test"
invoke-static {p1, v0}, Lj$/util/Objects;->requireNonNullElse(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
.line 9
new-instance v0, Ldk/gjesse/jdk11desugaredlibrary/ObjectsTest$1;
invoke-direct {v0, p0}, Ldk/gjesse/jdk11desugaredlibrary/ObjectsTest$1;-><init>(Ldk/gjesse/jdk11desugaredlibrary/ObjectsTest;)V
invoke-static {p1, v0}, Lj$/util/Objects;->requireNonNullElseGet(Ljava/lang/Object;Ljava/util/function/Supplier;)Ljava/lang/Object;
.line 15
return-void
.end method
ap...@google.com <ap...@google.com> #12
Thanks for that explanation Søren.
So, when I tried this with the latest Koala canary, it looks like things are working correctly. For the following code:
Objects.requireNonNullElse
Objects.requireNonNullElseGet
Both AGP and Studio correctly will not flag the first call.
The second call is flagged as an API error. But if I turn on core library desugaring, then that warning also goes away, both in AGP and in Studio.
There is still the issue of the builtin Java 9 APIs inspection in IntelliJ -- again, not a lint bug, but it is a Studio bug. Original submitter, can you file that one? And can you confirm (if you're not seeing warnings for these) that you are in fact using library desugaring and a recent Studio?
ap...@google.com <ap...@google.com> #13
I've filed
ap...@google.com <ap...@google.com> #14
thanks for filing the bug!
using library desugaring and a recent Studio?
yes I am, I have desugaring in all modules + using Koala Canary 2 now.
I will have to switch back to Jelly fish anyhow due to Koala being (to put it mildly) a runaway memory and cpu lover... which makes it nearly unusable (but that's another issue) so I might not be able to follow up on the new bug in the short term.
ap...@google.com <ap...@google.com> #15
On studio-main I can still repro the following false positive from
- Create a new project
- Enable desugaring, run Gradle sync
- Add a usage of
java.util.Objects#requireNonNullElse
Lint warning:
Call requires API level 30 (current min is 26): java.util.Objects#requireNonNullElse
ch...@gmail.com <ch...@gmail.com> #16
Just tested this with Koala.1 Beta 1, and something seems to not be right with lint (see results below). Not exactly sure where the integration is not working.
Using the test from git clone sso://user/sgjesse/B327670482
minApi | desugared library | requireNonNullElse | equireNonNullElseGet |
---|---|---|---|
21 | No | No lint message | Call requires API level 30 (and Call requires API level 24 on Supplier ) |
24 | No | No lint message | Call requires API level 30 |
21 | Yes | Call requires API level 30 | Call requires API level 30 |
The expected messages should be:
minApi | desugared library | requireNonNullElse | equireNonNullElseGet |
---|---|---|---|
21 | No | No lint message | Call requires API level 30 (and Call requires API level 24 on Supplier ) |
24 | No | No lint message | No lint message |
21 | Yes | No lint message | No lint message |
Looking at the DEX after compiling the code it is desugared as expected:
minApi | desugared library | requireNonNullElse | equireNonNullElseGet |
---|---|---|---|
21 | No | Desugared (backport) | Call to java.util.Objects through an D8 outline |
24 | No | Desugared (backport) | Desugared (backport) |
21 | Yes | Desugared (to target j$.util.Objects ) |
Desugared (to target j$.util.Objects ) |
Running the command line version of the D8 lint info generation tool the output looks correct.
As far as I can see the BackportedMethodList
D8 tool generated the correct desugared methods:
minApi
21 no library desugaring:
java -cp build/libs/r8.jar com.android.tools.r8.BackportedMethodList --min-api 21 --lib third_party/android_jar/lib-v34/android.jar | grep Objects
java/util/Objects#checkFromIndexSize(III)I
java/util/Objects#checkFromIndexSize(JJJ)J
java/util/Objects#checkFromToIndex(III)I
java/util/Objects#checkFromToIndex(JJJ)J
java/util/Objects#checkIndex(II)I
java/util/Objects#checkIndex(JJ)J
java/util/Objects#isNull(Ljava/lang/Object;)Z
java/util/Objects#nonNull(Ljava/lang/Object;)Z
java/util/Objects#requireNonNullElse(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
requireNonNullElse
is desugared.
minApi
24 no library desugaring:
java -cp build/libs/r8.jar com.android.tools.r8.BackportedMethodList --min-api 24 --lib third_party/android_jar/lib-v34/android.jar | grep Objects
java/util/Objects#checkFromIndexSize(III)I
java/util/Objects#checkFromIndexSize(JJJ)J
java/util/Objects#checkFromToIndex(III)I
java/util/Objects#checkFromToIndex(JJJ)J
java/util/Objects#checkIndex(II)I
java/util/Objects#checkIndex(JJ)J
java/util/Objects#requireNonNullElse(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
java/util/Objects#requireNonNullElseGet(Ljava/lang/Object;Ljava/util/function/Supplier;)Ljava/lang/Object;
requireNonNullElse
and requireNonNullElseGet
are desugared.
minApi
21 with library desugaring:
java -cp build/libs/r8.jar com.android.tools.r8.BackportedMethodList --min-api 21 --lib third_party/android_jar/lib-v34/android.jar --desugared-lib src/library_desugar/jdk11/desugar_jdk_libs.json | grep Objects
java/util/Objects#checkFromIndexSize(JJJ)J
java/util/Objects#checkFromToIndex(JJJ)J
java/util/Objects#checkIndex(JJ)J```
Neither requireNonNullElse
nor requireNonNullElseGet
is mentioned, but META-INF/desugar/d8/lint/compile_api_level_30/desugared_apis_30_1.txt
from the desugared library configuration artifact contains:
java/util/Objects
So all of Objects
is desugared.
We need to track down where the information is lost.
ch...@google.com <ch...@google.com> #17
Shouldn't this be a P1 and Koala.1 RC blocker?
an...@google.com <an...@google.com> #18
not as far as I'm concerned - this is a warning only which I can just ignore. The app compiles and works perfectly fine.
Methinks you guys have more important P1's to fix. If you need inspiration, then look at #127100532 (not related to this one at all, I'm just being ... now)
an...@google.com <an...@google.com> #19
I think I found the problem.
Here's the desugaring files used in the IDE:
modelArtifact?.desugaredMethodsFiles = {ArrayList@83951} size = 2
0 = {File@84956} "/Users/tnorbye/.gradle/caches/transforms-4/5126fdfcbb5a995f09b8be45eb610aef/transformed/desugar_jdk_libs_configuration_nio-2.0.4-desugar-lint.txt"
1 = {File@84957} "/Users/tnorbye/.gradle/caches/transforms-4/fc5ceb7b5de2ee8487ba96f4a79c6608/transformed/D8BackportedDesugaredMethods.txt"
What we do with these files is to "merge" them. This was just reading all the signatures from both files and sorting them. When lint is checking methods it just does a binary search.
But in this case, we're getting these methods from the d8 backport list:
java/util/Objects#checkFromIndexSize(JJJ)J
java/util/Objects#checkFromToIndex(JJJ)J
java/util/Objects#checkIndex(JJ)J
And we're getting this method from the library desugaring list:
java/util/Objects
This means that we end up with this in the signature list:
java/util/Objects
java/util/Objects#checkFromIndexSize(JJJ)J
java/util/Objects#checkFromToIndex(JJJ)J
java/util/Objects#checkIndex(JJ)J
This is wrong; the first line implies that all the other three are included. But in a binary search, if our midpoint hits one of the specific methods, we'll conclude that the match must be later in the list, so we'll falsely decide the method isn't there.
I need to fix the merging of signature files to not just concatenate but to drop specific methods and fields if the other file lists the whole class.
I don't think this is a recent regression, but I think this is showing up now through a combination of the desugaring files including newly fully backported classes, and there's luck involved based on how binary search proceeds.
Description
Problem and Stack Trace
If I subclass LinearLayoutManager and run it thru R8, I get an exception when I run my app.
12-03 14:53:28.210 7267 7267 I System.out: ----------- [BusinessListActivity 1] [DEBUG] line: 1 buildContent() exited successfully.
12-03 14:53:28.210 7267 7267 I System.out: ----------- [BusinessListActivity 1] [DEBUG] line: 1 onCreate() exited successfully
Point of Breakage
12-03 14:53:28.221 7267 7336 W Parcel : Expecting binder but got null!
12-03 14:53:28.222 1946 4862 D CompatibilityChangeReporter: Compat change id reported: 168419799; UID 10429; state: DISABLED
12-03 14:53:28.222 1946 4862 D CompatibilityChangeReporter: Compat change id reported: 273564678; UID 10429; state: DISABLED
12-03 14:53:28.227 1946 4862 D CoreBackPreview: Window{10efe5a u0 com.spillikinaerospace.ourhangoutsapp/com.spillikinaerospace.ourhangoutsapp.ui.businesslistactivity.BusinessListActivity}: Setting back callback OnBackInvokedCallbackInfo{mCallback=android.window.IOnBackInvokedCallback$Stub$Proxy@f88d68, mPriority=0, mIsAnimationCallback=false}
12-03 14:53:28.228 7267 7267 D AndroidRuntime: Shutting down VM
12-03 14:53:28.228 7267 7267 E AndroidRuntime: FATAL EXCEPTION: main
12-03 14:53:28.228 7267 7267 E AndroidRuntime: Process: com.spillikinaerospace.ourhangoutsapp, PID: 7267
12-03 14:53:28.228 7267 7267 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.n(int, int)' on a null object reference
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at androidx.recyclerview.widget.RecyclerView$m.onMeasure(Unknown Source:2)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at androidx.recyclerview.widget.RecyclerView.onMeasure(Unknown Source:29)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.View.measure(View.java:27122)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.widget.LinearLayout.measureVertical(LinearLayout.java:1031)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.View.measure(View.java:27122)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7008)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at androidx.appcompat.widget.ContentFrameLayout.onMeasure(Unknown Source:159)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.View.measure(View.java:27122)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7008)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1608)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.widget.LinearLayout.measureVertical(LinearLayout.java:878)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.View.measure(View.java:27122)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7008)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.View.measure(View.java:27122)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7008)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1608)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.widget.LinearLayout.measureVertical(LinearLayout.java:878)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.View.measure(View.java:27122)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7008)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at com.android.internal.policy.DecorView.onMeasure(DecorView.java:750)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.View.measure(View.java:27122)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:4182)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2759)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3086)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2465)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9305)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1339)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1348)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.Choreographer.doCallbacks(Choreographer.java:952)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.Choreographer.doFrame(Choreographer.java:882)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1322)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:958)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:205)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.os.Looper.loop(Looper.java:294)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:8177)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
12-03 14:53:28.228 7267 7267 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
12-03 14:53:28.230 1946 7663 I DropBoxManagerService: add tag=data_app_crash isTagEnabled=true flags=0x2
12-03 14:53:28.231 1946 4862 W ActivityTaskManager: Force finishing activity com.spillikinaerospace.ourhangoutsapp/.ui.businesslistactivity.BusinessListActivity
------------------------------------------------------
Experiments.
1. Minimal subclass to demonstrate issue.
I created this minimal subclass which causes the app to crash when the activity that uses it is run.
When I remove the single method and keep only the constructors, the app runs just fine. If I add the method back in, the app crashes. I do not even need to call the method. (I'm thinking the JVM is doing some sort of optimization when it only sees constructors in the subclass.)
class SAOverscrollLLManagerTest : LinearLayoutManager {
constructor (context: Context) : super(context) {
}
constructor (context: Context, attributeSet: AttributeSet, int1: Int, int2: Int) :
super(context, attributeSet, int1, int2) {
}
constructor (context: Context, int: Int, boolean: Boolean) :
super(context, int, boolean) {
}
// Comment out this method and the app does not crash.
fun setRecyclerView(recyclerView: RecyclerView) {
// use this setting to improve performance if changes in content do not change
// layout size of RecyclerView
recyclerView.setHasFixedSize(true)
recyclerView.layoutManager = this
// recyclerView.overScrollMode = View.OVER_SCROLL_ALWAYS
// recyclerView.edgeEffectFactory = BounceEdgeEffectFactory()
}
}
2. R8 Keep settings
2.1 I tried this. App crashed under above conditions (subclass LinearLayoutManager)
Keep my app
-keep class com.spillikinaerospace.** { *; }
Keep RecyclerView (turned out not to be the issue)
-keep class androidx.recyclerview.widget.LinearLayoutManager { *; }
-keep class androidx.recyclerview.widget.GridLayoutManager { *; }
-keep class androidx.recyclerview.widget.RecyclerView { *; }
2.2 I tried this. App crashed under above conditions (subclass LinearLayoutManager)
Keep everything!
-keep class ** { *; }
------------------------------------------------------
Configuration Details.
1. proguard-rules.pro
In additino to Keep, I have these warning suppressions.
See
-dontwarn org.bouncycastle.jsse.BCSSLParameters
-dontwarn org.bouncycastle.jsse.BCSSLSocket
-dontwarn org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
-dontwarn org.conscrypt.Conscrypt$Version
-dontwarn org.conscrypt.Conscrypt
-dontwarn org.conscrypt.ConscryptHostnameVerifier
-dontwarn org.openjsse.javax.net.ssl.SSLParameters
-dontwarn org.openjsse.javax.net.ssl.SSLSocket
-dontwarn org.openjsse.net.ssl.OpenJSSE
2. build.gradle Module
defaultConfig {
applicationId "com.spillikinaerospace.ourhangoutsapp"
minSdkVersion 33
targetSdkVersion 34
...
}
release {
debuggable false
shrinkResources false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
3. gradle.properties
Generate as many Keeps as I can.
android.enableR8.fullMode=false
4. build.gradle Project
ext.kotlin_version = '1.8.20'
dependencies {
classpath 'com.android.tools.build:gradle:8.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10"
...
}
------------------------------------------------------
Android Studio Version
Android Studio Hedgehog | 2023.1.1
Build #AI-231.9392.1.2311.11076708, built on November 9, 2023
Runtime version: 17.0.7+0-17.0.7b1000.6-10550314 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 13.5
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 10
Metal Rendering is ON
Registry:
external.system.auto.import.disabled=true
ide.text.editor.with.preview.show.floating.toolbar=false