Skip to content
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

Crashing when updating android to api target 35 #2257

Closed
corbella83 opened this issue Jul 19, 2024 · 3 comments · Fixed by #2258
Closed

Crashing when updating android to api target 35 #2257

corbella83 opened this issue Jul 19, 2024 · 3 comments · Fixed by #2258
Assignees
Labels
Missing info The user didn't precise the problem enough Missing repro This issue need minimum repro scenario Platform: Android This issue is specific to Android

Comments

@corbella83
Copy link
Contributor

corbella83 commented Jul 19, 2024

Description

All versions of "react-native-screens" are crashing when targeting android app to api level 35 due to NoSuchMethodError:

java.lang.NoSuchMethodError: No interface method removeLast()Ljava/lang/Object; in class Ljava/util/List; or its super classes (declaration of 'java.util.List' appears in /apex/com.android.art/javalib/core-oj.jar)
at com.swmansion.rnscreens.ScreenStack.obtainDrawingOp(ScreenStack.kt:319)
at com.swmansion.rnscreens.ScreenStack.drawChild(ScreenStack.kt:303)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4538)

Is this line:
if (drawingOpPool.isEmpty()) DrawingOp() else drawingOpPool.**removeLast**()

And means that removeLast is not available anymore. Replacing it to this works well:

if (drawingOpPool.isEmpty()) DrawingOp() else drawingOpPool.removeAt(drawingOpPool.size - 1)

This is a known issue from android: official android documentation

Steps to reproduce

  1. Create a react-native project CLI, using 0.74.3 and add dependency of react-native-screens 3.32.0
  2. Configure compileSdkVersion and targetSdkVersion of the android project to use api level 34
  3. Execute android app and ensure everything is working
  4. Change compileSdkVersion and targetSdkVersion to use api level 35
  5. Execute android app and it will crash

Screens version

3.32.0

React Native version

0.74.3

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Paper (Old Architecture)

Build type

None

Device

Real device

Device model

Samsung Galaxy S22

Acknowledgements

Yes

@github-actions github-actions bot added the Missing repro This issue need minimum repro scenario label Jul 19, 2024
Copy link

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

@github-actions github-actions bot added the Platform: Android This issue is specific to Android label Jul 19, 2024
@corbella83 corbella83 mentioned this issue Jul 19, 2024
8 tasks
Copy link

Hey! 👋

It looks like you've omitted a few important sections from the issue template.

Please complete Snack or a link to a repository section.

@github-actions github-actions bot added the Missing info The user didn't precise the problem enough label Jul 19, 2024
@corbella83
Copy link
Contributor Author

corbella83 commented Jul 19, 2024

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

I'm not going to create a new project, configure it, and upload to github for that small change. Every project you have installed will behave the same if you use android api level35.
PR #2256

@kkafar kkafar self-assigned this Jul 20, 2024
kkafar added a commit that referenced this issue Jul 22, 2024
## Description

Initially reported & solution proposed by @corbella83.

Newer OpenJDK versions have introduced `List.removeLast` /
`List.removeFirst` methods, which haven't existed in JDK before and were
provided by Kotlin std lib `kotlin-std`. Android SDK 35 aligns with
recent OpenJDK versions & when compiling with SDK 35 the method call is
statically resolved to the function from JDK and not to the one from
`kotlin-std`. Thus when running on lower version of runtime (<= 34)
there is no such method available at runtime (at address resolved in
compile time) leading to runtime crash.

Section in Android docs describing this:
https://developer.android.com/about/versions/15/behavior-changes-15?hl=en#openjdk-api-changes

Fixes #2257

## Changes

* Replaced call to `drawingOpList.removeLast` with
`drawingOpList.removeAt(drawingOpList.lastIndex)`.
* Added comment to ensure no one refactors this code bu accident at some
later point.


## Test code and steps to reproduce

Bump sdk to 35 in Example / FabricExample & run the application. It
won't fail in runtime anymore.

## Checklist

- [x] Ensured that CI passes

CI fails sometimes with some `reanimated` / `gesture-handler` related
reasons:

<details><summary>Error message</summary>
<p>

```
> Task :react-native-gesture-handler:processDebugAndroidTestManifest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-gesture-handler:processDebugAndroidTestManifest'.
> Could not resolve all files for configuration ':react-native-gesture-handler:debugAndroidTestRuntimeClasspath'.
   > Failed to transform hermes-android-0.74.1-debug.aar (com.facebook.react:hermes-android:0.74.1) to match attributes {artifactType=android-manifest, com.android.build.api.attributes.BuildTypeAttr=debug, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for JetifyTransform: /home/runner/.gradle/caches/modules-2/files-2.1/com.facebook.react/hermes-android/0.74.1/16e198f2042f7758123b39bba3d5e3d6eb33ba8a/hermes-android-0.74.1-debug.aar.
         > Java heap space
```

</p>
</details> 

which seem unrelated to the PR, but might indicate either some issue
with other lib **or** insufficient java heap size.

Co-authored-by: Pau Corbella <corbella83@gmail.com>

Co-authored-by: Pau Corbella <corbella83@gmail.com>
ja1ns pushed a commit to WiseOwlTech/react-native-screens that referenced this issue Oct 9, 2024
…mansion#2258)

## Description

Initially reported & solution proposed by @corbella83.

Newer OpenJDK versions have introduced `List.removeLast` /
`List.removeFirst` methods, which haven't existed in JDK before and were
provided by Kotlin std lib `kotlin-std`. Android SDK 35 aligns with
recent OpenJDK versions & when compiling with SDK 35 the method call is
statically resolved to the function from JDK and not to the one from
`kotlin-std`. Thus when running on lower version of runtime (<= 34)
there is no such method available at runtime (at address resolved in
compile time) leading to runtime crash.

Section in Android docs describing this:
https://developer.android.com/about/versions/15/behavior-changes-15?hl=en#openjdk-api-changes

Fixes software-mansion#2257

## Changes

* Replaced call to `drawingOpList.removeLast` with
`drawingOpList.removeAt(drawingOpList.lastIndex)`.
* Added comment to ensure no one refactors this code bu accident at some
later point.


## Test code and steps to reproduce

Bump sdk to 35 in Example / FabricExample & run the application. It
won't fail in runtime anymore.

## Checklist

- [x] Ensured that CI passes

CI fails sometimes with some `reanimated` / `gesture-handler` related
reasons:

<details><summary>Error message</summary>
<p>

```
> Task :react-native-gesture-handler:processDebugAndroidTestManifest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-gesture-handler:processDebugAndroidTestManifest'.
> Could not resolve all files for configuration ':react-native-gesture-handler:debugAndroidTestRuntimeClasspath'.
   > Failed to transform hermes-android-0.74.1-debug.aar (com.facebook.react:hermes-android:0.74.1) to match attributes {artifactType=android-manifest, com.android.build.api.attributes.BuildTypeAttr=debug, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for JetifyTransform: /home/runner/.gradle/caches/modules-2/files-2.1/com.facebook.react/hermes-android/0.74.1/16e198f2042f7758123b39bba3d5e3d6eb33ba8a/hermes-android-0.74.1-debug.aar.
         > Java heap space
```

</p>
</details> 

which seem unrelated to the PR, but might indicate either some issue
with other lib **or** insufficient java heap size.

Co-authored-by: Pau Corbella <corbella83@gmail.com>

Co-authored-by: Pau Corbella <corbella83@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Missing info The user didn't precise the problem enough Missing repro This issue need minimum repro scenario Platform: Android This issue is specific to Android
Projects
None yet
2 participants