Status Update
Comments
fi...@gmail.com <fi...@gmail.com> #2
More info from build.gradle
:
Kotlin version: 1.3.72
Android Gradle Plugin: 4.0.0
Gradle wrapper: gradle-6.1.1
kotlinOptions => jvmTarget "1.8"
compileOptions => compatibility JavaVersion.VERSION_1_8
Kotlin stdlib dependency => org.jetbrains.kotlin:kotlin-stdlib-jdk8
mk...@google.com <mk...@google.com> #3
Thank you for posting an issue. Is it possible to share you demo-example? You can share it privately by sending it to
Also, are you shrinking the demo-app as well or is R8 only used for the library shrinking?
hq...@gmail.com <hq...@gmail.com> #4
I just encountered almost same issue except that I did not use @JvmStatic in my code.
This should have something to do with R8 staticization as described
mk...@google.com <mk...@google.com> #5
hqzxzwb@, can you potentially share an example and file a new issue with all the information (stack-trace etc)? The OP originally states that removing @JvmStatic will make the code work and it therefore seems like you are encountering a different issue but with the same error message. Having a separate issue will ensure that your problem is not overlooked while focusing on the original bug.
fi...@gmail.com <fi...@gmail.com> #7
Hello mk,
I have created a good sample project just to illustrate this problem. Unfortunately I couldn't zip and upload the project via Gmail due to security reasons.
I've now uploaded the project as github repo here:
Once you clone it, run this command at root level
./gradlew sdk:clean sdk:publishToMavenLocal
This will publish SDK 0.1.0-alpha.07
to local maven and app is already setup to use it. Just do gradle sync and run.
To answer your last question, I'm not shrinking the demo app and running debug
variant only.
Let me know if you need anymore help.
mk...@google.com <mk...@google.com> #8
Thank you for the detailed reproduction. This is a problem on the 2.0 branch where we do not handle the signature inside kotlin.Metadata correctly.
In the metadata, we rewrite the signature to:
signature: setPlaygroundDialogBlocker(Lkotlin/Function0;)V,
however, the signature should be:
signature: setPlaygroundDialogBlocker(Lkotlin/jvm/functions/Function0;)V,
This is no longer the behavior on our master branch and on our 2.1 branch. For libraries written in kotlin I would say version 2.1.35 is better than the version currently bundled with AGP 4.0, however, it is still an ongoing project which I hope we will wrap up soon. You can use version 2.1.35 by adding the following to your top-level build.gradle file:
buildscript {
repositories {
maven {
url 'https://storage.googleapis.com/r8-releases/raw'
}
}
dependencies {
classpath 'com.android.tools:r8:2.1.35' // Must be before the Gradle Plugin for Android.
classpath 'com.android.tools.build:gradle:X.Y.Z' // Your current AGP version.
}
}
However, I would wait a few days until we have resolved issue
ap...@google.com <ap...@google.com> #9
Branch: master
commit 651399abc6e31c914d11e636a8ae4c1cfb2d213d
Author: Morten Krogh-Jespersen <mkroghj@google.com>
Date: Tue Jun 09 12:48:37 2020
Add test for JvmStatic on functions, interfaces and props
Bug: 158393309
Change-Id: I258836c91b244452f40dc1ade2b7f5b2c98dd375
A src/test/java/com/android/tools/r8/kotlin/metadata/MetadataRewriteJvmStaticTest.java
A src/test/java/com/android/tools/r8/kotlin/metadata/jvmstatic_app/MainJava.java
A src/test/java/com/android/tools/r8/kotlin/metadata/jvmstatic_app/main.kt
A src/test/java/com/android/tools/r8/kotlin/metadata/jvmstatic_lib/lib.kt
fi...@gmail.com <fi...@gmail.com> #10
Hello @Mk,
Thank you for quick response.
We have somewhat urgency for releasing the SDK. Do you advise that it would be safe to use r8:2.1.35
version for time being and release the SDK if no other issues come up, or we should absolutely wait for issue b/158400283
to be fixed.
Also do you have any rough timeline for fix for b/158400283
?
mk...@google.com <mk...@google.com> #11
Version 2.1.X is used in 4.1 beta and in general it should work. The reason you may want to wait for
The fix for
A rough timeline is two weeks (the fix itself is already on ToT, but we have to make certain that porting all kotlin metadata changes to the 2.1 branch do not fail).
mk...@google.com <mk...@google.com> #12
Version 2.1.42 (which also fixes
buildscript {
repositories {
maven {
url 'https://storage.googleapis.com/r8-releases/raw'
}
}
dependencies {
classpath 'com.android.tools:r8:2.1.42' // Must be before the Gradle Plugin for Android.
classpath 'com.android.tools.build:gradle:X.Y.Z' // Your current AGP version.
}
}
fi...@gmail.com <fi...@gmail.com> #13
Thank you so much @Mk for all the help. I'll use this right away.
mk...@google.com <mk...@google.com> #14
You are welcome - and please do not hesitate to file new bugs if you find any problems.
Description
I have been having an issue dealing with R8/obfuscation with an Android library written in Kotlin.
Below is the sample code
Similar to above, I've a public API method which is annotated with
@JvmStatic
and that method takes a Lambda as parameter.When I release the library without
minification
, everything is fine and calling code (from app side) written inJava
andKotlin
can call this method and works as expected.Now if I enable
minification
and call same method from a demo app then I get a crashing error with message similar to belowWhat have I tried ?
@Jvmstatic
resolves the issue but it created ugly Java calling code as I would have to call likeMyApi.INSTANCE.setCallback()
@Jvmstatic
but removedLambda
by converting Lambda into anInterface with one method
and everything is working fine. UnfortunatelySAM for Kotlin classes
is not there yet, so callingKotlin
code looks ugly thenR8
via setting these lines ingradle.properties
which forcefully enabledProguard
and then everything work with both@Jvmstatic
andLambda
So my last try confirms that this problem has something to do with
R8
.Would you please help me out with this ?
Whether it's something wrong on my side as incorrect use of
R8
or it's genuineR8
bug ? I don't know.I posted ahttps://stackoverflow.com/questions/62249685/dealing-with-r8-jvmstatic-annotation-lambda-in-public-api-for-android-librar
Stackoverflow
question with same details here: