-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java 17 incompatibility - UnsupportedOperationException: class redefinition failed: attempted to delete a method
#384
Comments
Tried on Java 17, and ran into https://youtrack.jetbrains.com/issue/KT-45545. So gotta bump Kotlin-Compose first. |
I also wanted to give Paparazzi a try. As it claims to not use any emulator I wanted to use it in a unit test with fragment-testing library, but I got a similar error executing my proof of concept test with AndroidJunit4.
It just fails with an empty test. And the exception is:
|
Makes sense. At the moment, support is upper-limited to JDK 15. |
Ah I forgot to say that even though I have java 17 installed this is run on Android Studio that has its own JDK 11 embedded, and Gradle also is configured to compile and make it compatible with java 1.8:
I also tried with VERSION_11 with the same result |
I recently encountered something similar trying to learn more about this issue and when I hit Cmd-, and went to Gradle settings, I found that Android Studio was still pointing to JDK 17. That's the workaround for the moment, unfortunately. |
This is something I already tried, and it was promising at the beginning making the test to pass. It even created a report in build directory. But I made some minor changes and subsequent executions failed. I reverted to the same code but since then I always got that error. No matters what I do, still happens the same. Right now I have changed my JDK to JDK 17 with no luck. After that I also changed my |
Maybe mine is not the same problem and I should open a new issue. But the point with my sample is that it works when I don't use the AndroidJUnit4 runner |
I couldn't get it to work with JDK 11 either, I suspect it's a compatibility issue with Robolectric. Write down the reproduction procedure. First, check the JDK version.@RunWith(AndroidJUnit4::class)
class ExampleUnitTest {
// @get:Rule
// val paparazzi = Paparazzi()
@Test
fun addition_isCorrect() {
println(System.getProperty("java.version"))
}
} ./gradlew testDebug 16.0.2 brew install openjdk@11 11.0.15 reproduction procedure@RunWith(AndroidJUnit4::class)
class ExampleUnitTest {
@get:Rule
val paparazzi = Paparazzi() // ← Comment in !!
@Test
fun addition_isCorrect() {
println(System.getProperty("java.version"))
}
} ./gradlew -Dorg.gradle.java.home="/opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk/Contents/Home" testDebugUnitTest com.example.paparazziwithrobolectric.ExampleUnitTest > jvm FAILED
Repository |
I had the same error
I fixed it by removing this line from my test class.
|
Try running from terminal. Android Studio might still be using JDK > 11 for its runtime. That's what worked for me. |
The latest 8.0 alphas of AGP now require JDK 17, meaning that there is an upcoming incompatibility with Paparazzi and AGP. |
AGP will require JDK 17, which means that tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "11" // lower byte-code level so that Test can load classes.
}
tasks.named("test").configure {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(11)
}
} |
Woah, that's really cool! Can confirm with the above workaround that Paparazzi will run with the latest AGP alpha, using JDK 17 for |
Thanks for sharing the workaround @TWiStErRob . I'm trying to use paparazzi for one of the project. As @alexvanyo mentioned above Android Studio Flamingo will be using JDK 17 by default. I'm requesting to see whether there is any planned update to support JDK 17? |
Running JDK 17:
JDK 11:
For JDK 11 configuring toolchain like this:
|
I'm not able to get the workaround working but one can continue to use AGP |
The workaround also doesn't work for us |
Another workaround that doesn't require JDK 11: android {
testOptions {
unitTests.all {
useJUnitPlatform {
// TODO: Remove when https://github.com/cashapp/paparazzi/issues/384 is fixed
if (JavaVersion.current() >= JavaVersion.VERSION_13) {
jvmArgs "-XX:+AllowRedefinitionToAddDeleteMethods"
}
}
}
}
} |
so based on all the input, the issue here is using I'm going to leave this issue open for a bit until the PR above is merged, but paparazzi is now on AGP 8.0 and built with Java 17 and is working as expected. |
I still had the problem using jdk 17, kotlin 1.8.21, gradle 8 and paparazzi 1.3.0. Removing this fixed it:
|
I am still seeing the same error even after removing test Coverage flags and the test does not have @RunWith(AndroidJUnit4::class) or Robolectric I am using JDK 17, kotlin 1.8.21, Gradle 8.1.1, AGP 8.0.2, paparazzi 1.3.0.
|
Removing jacoco plugin solves this for me. Not clear how to solve this with jacoco enabled though. |
👋
I wanted to give Paparazzi a try and I after first couple of bumps I think I got into a point I can say I have proper setup. Which:
a) if used with default theme - records png file with placeholder over places where material views should be
b) if used with Material Theme - results in #380
So I assume that's expected at this point.
The results above I got only after downgrading Java to previous LTS version (11). If I use current LTS (17) I get:
Looking at your CI config you don't support anything above java 15. I couldn't find the stack trace nor issue mentioning java 17 so I thought it's worth reporting here.
Version used: 1.0.0-20220311.182942-63.pom
compileSdk
31gradle
7.4.1agp
7.1.2The text was updated successfully, but these errors were encountered: