Status Update
Comments
ma...@gmail.com <ma...@gmail.com> #2
Also crashes in R8 version 8.5.35, 8.6.17, 8.7.2-dev
ra...@google.com <ra...@google.com>
pa...@gmail.com <pa...@gmail.com> #3
You cannot apply keep rules for classes synthesized by R8, but if you keep the implemented interfaces, the merging should not happen.
That said, checking the implementing class of a lambda might not be a good idea. The specification for java.lang.invoke.LambdaMetafactory
Capture may involve allocation of a new function object, or may return a suitable existing function object. The identity of a function object produced by capture is unpredictable, and therefore identity-sensitive operations (such as reference equality, object locking, and System.identityHashCode()) may produce different results in different implementations, or even upon different invocations in the same implementation.
If I understand this correctly the only guarantee is that the function object implements the interface(s) specified.
cc...@google.com <cc...@google.com> #4
The actual problem is that R8 deletes FunInterface1 and FunInterface2 classes, which are used for runtime di:
fun hello() {
val instance1 = FunInterface1 { println("Doing business") }
val instance2 = FunInterface2 { println("Starting the show") }
val map = mapOf(
FunInterface1::class.java to instance1,
FunInterface2::class.java to instance2,
)
check(map.size == 2) { "Map size is ${map.size}" }
}
So do I have to list all fun interfaces in my sdk using -keep? I might do that for ~100 of them that exist right now, but this won't save future developers from adding another fun interface and forgetting to list them in .pro file.
Description
Version used:1.2.2
Devices/Android versions reproduced on: Android 11
Error
java.lang.IllegalStateException: Check failed.
at androidx.benchmark.macro.CompilationMode$Companion.cmdPackageCompile$benchmark_macro_release(CompilationMode.kt:423)
at androidx.benchmark.macro.CompilationMode$Full.compileImpl$benchmark_macro_release(CompilationMode.kt:358)
at androidx.benchmark.macro.CompilationMode.resetAndCompile$benchmark_macro_release(CompilationMode.kt:112)
at androidx.benchmark.macro.MacrobenchmarkKt.macrobenchmark(Macrobenchmark.kt:184)
at androidx.benchmark.macro.MacrobenchmarkKt.macrobenchmarkWithStartupMode(Macrobenchmark.kt:367)
My Code
@RunWith(AndroidJUnit4::class)
class ExampleStartupBenchmark {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()
@Test
fun startupCompilationNone() = startup(CompilationMode.None())
@Test
fun startupCompilationPartial() = startup(CompilationMode.Partial())
@Test
fun startupCompilationFull() = startup(CompilationMode.Full())
fun startup(compilationMode: CompilationMode) = benchmarkRule.measureRepeated(
packageName = "com.masum.pdfreader",
metrics = listOf(StartupTimingMetric()),
iterations = 5,
compilationMode = CompilationMode.Full(), // Set the compilation mode
startupMode = StartupMode.COLD
) {
pressHome()
startActivityAndWait()
}