Status Update
Comments
ag...@google.com <ag...@google.com>
sg...@google.com <sg...@google.com> #2
Thank you for the report and for using library desugaring. However I was not able to reproduce this issue in a simple setting (see below). Do you have a reproduction that you can share, or can you maybe otherwise share the APK
where this is failing at runtime? You can share it privately with
- What version of AGP and desugared library are you using (I tried to repro on AGP 4.0.0 with desugared library 1.0.5)?
- Can you share the exact runtime error and stack trace?
- Is this failing on all devices/emulators you have tested on?
For reproduction I added the following lines to onCreate
of the main activity:
System.out.println(java.time.ZoneId.getAvailableZoneIds().size());
System.out.println(java.time.ZoneOffset.getAvailableZoneIds().size());
That resulted on two lines with 577 in logcat
. Tested release mode on both an Android 10 (API 29) and KitKat (API 19) emulator.
The compiled code contained the two static calls:
...
invoke-static {}, Lj$/time/ZoneId;->getAvailableZoneIds()Ljava/util/Set;
...
invoke-static {}, Lj$/time/ZoneOffset;->getAvailableZoneIds()Ljava/util/Set;
...
and the keep rules for the desugared library contained:
-keep class j$.time.ZoneOffset {
java.util.Set getAvailableZoneIds();
}
-keep class j$.time.ZoneId {
java.util.Set getAvailableZoneIds();
}
and the desugared library DEX
contained class j$.time.ZoneOffset
extending j$.time.ZoneId
.
tu...@gmail.com <tu...@gmail.com> #3
Err: java.lang.NoSuchMethodError: No static method systemDefault()Lj$/time/ZoneId; in class Lj$/time/ZoneOffset (declaration of 'j$.time.ZoneOffset' appears in base.apk:classes2.dex)
My environment:
- coreDesugaringLibrary 1.0.4
- AGP 4.0.0
Devices:
- Xiaomi Mi A2, API 29, May 2020 update
- Emulator API 29
- Emulator API 21
I used this method in kotlin extension method, used in Rx zip func, that runs in flatMap on Rx.io thread
sg...@google.com <sg...@google.com> #4
Thanks you for the detailed information on how to reproduce that you have shared over email. Looking into it I feel pretty stupid, as the simple reproduction is to have only:
System.out.println(java.time.ZoneOffset.getAvailableZoneIds().size());
it the test app. That generates the keep rule
-keep class j$.time.ZoneOffset {
java.util.Set getAvailableZoneIds();
}
Which not keep getAvailableZoneIds()
on the super class j$.time.ZoneId
causing the exception
java.lang.NoSuchMethodError: No static method getAvailableZoneIds()Ljava/util/Set; in class Lj$/time/ZoneOffset; or its super classes
ap...@google.com <ap...@google.com> #5
Branch: master
commit f2ef806be12271ba7b5ede5c5a172cebdc36238c
Author: Søren Gjesse <sgjesse@google.com>
Date: Wed Jun 17 12:24:29 2020
Use compat mode for shrinking the desugared library
Full mode does not currently trace static targets on super classes,
Bug: 158815562
Change-Id: I6c5772162f2e4f3b68f640eefde8cc75493c0667
M src/main/java/com/android/tools/r8/L8Command.java
M src/test/java/com/android/tools/r8/desugar/desugaredlibrary/JavaTimeTest.java
ap...@google.com <ap...@google.com> #6
Branch: 2.0
commit ca716d63d1ba213da226142c83ec0f3f7e4ae826
Author: Søren Gjesse <sgjesse@google.com>
Date: Wed Jun 17 13:11:34 2020
Version 2.0.87
Cherry-pick: Use compat mode for shrinking the desugared library
CL:
Bug: 158815562
Change-Id: I5bf5490ed41b4dfdf08e3c58090087c6f4b7dda1
M src/main/java/com/android/tools/r8/L8Command.java
M src/main/java/com/android/tools/r8/Version.java
M src/test/java/com/android/tools/r8/desugar/desugaredlibrary/JavaTimeTest.java
sg...@google.com <sg...@google.com> #7
This should now be fixed, and is included in R8 version 2.0.87 and above. You test it by adding the following to you top level build.gradle
file:
buildscript {
repositories {
maven {
url 'https://storage.googleapis.com/r8-releases/raw'
}
}
dependencies {
classpath 'com.android.tools:r8:2.0.87' // Must be before the Gradle Plugin for Android.
classpath 'com.android.tools.build:gradle:4.0.0'
}
}
ap...@google.com <ap...@google.com> #8
Branch: 2.1
commit ecaaac6f0ff91a44fda837a5fe2a1f63aca649b6
Author: Søren Gjesse <sgjesse@google.com>
Date: Wed Jun 17 16:40:41 2020
Version 2.1.42
Cherry-pick: Use compat mode for shrinking the desugared library
CL:
Cherry-pick: Collect desugared library types used in check-cast and instanceof
CL:
Cherry-pick: Collect desugared library exception types used in try/catch
CL:
Cherry-pick: Provide access to try/catch guards in code inspector
CL:
Cherry-pick: Add reproduction of duplicate methods due to staticizer
CL:
Cherry-pick: Disable moving not processed members to host for
staticizer
CL:
Bug: 158815562
Bug: 158417777
Bug: 157966650
Bug: 158018192
Change-Id: I32cdfc36dd24db48deb4b3e692bbbbb68d89a28e
M src/main/java/com/android/tools/r8/L8Command.java
M src/main/java/com/android/tools/r8/Version.java
M src/main/java/com/android/tools/r8/code/CheckCast.java
M src/main/java/com/android/tools/r8/code/InstanceOf.java
M src/main/java/com/android/tools/r8/code/Instruction.java
M src/main/java/com/android/tools/r8/dex/DexOutputBuffer.java
M src/main/java/com/android/tools/r8/dex/FileWriter.java
M src/main/java/com/android/tools/r8/ir/optimize/staticizer/StaticizingProcessor.java
M src/test/java/com/android/tools/r8/desugar/desugaredlibrary/JavaTimeTest.java
A src/test/java/com/android/tools/r8/ir/optimize/staticizer/HostWithStaticMethodTest.java
M src/test/java/com/android/tools/r8/ir/optimize/staticizer/InstanceInsideCompanionTest.java
M src/test/java/com/android/tools/r8/ir/optimize/staticizer/InvokeStaticWithNullOutvalueTest.java
M src/test/java/com/android/tools/r8/utils/codeinspector/CfTryCatchSubject.java
M src/test/java/com/android/tools/r8/utils/codeinspector/CodeInspector.java
M src/test/java/com/android/tools/r8/utils/codeinspector/DexTryCatchSubject.java
M src/test/java/com/android/tools/r8/utils/codeinspector/MethodSubject.java
M src/test/java/com/android/tools/r8/utils/codeinspector/TryCatchSubject.java
Description
ZoneId.getAvailableZoneIds()
works as expected, but
ZoneOffset.getAvailableZoneIds()
works at compile time, but throws a "static method not found" exception on runtime (at least in release builds).