react native run on android Caused by: java.util.concurrent.ExecutionException: com.android.tools.r8.internal.Jj: java.lang.NullPointerException: Cannot invoke "String.length()" because "" is null

react native run on android Caused by: java.util.concurrent.ExecutionException: com.android.tools.r8.internal.Jj: java.lang.NullPointerException: Cannot invoke "String.length()" because "" is null
Photo by Libby Penner / Unsplash

Today I would like to continue my react native app development work. After I run npm start , I got below quite strange error. I build the app via android studio, no build issue. Quite strange problem.

Caused by: java.util.concurrent.ExecutionException: com.android.tools.r8.internal.Jj: java.lang.NullPointerException: Cannot invoke "String.length()" because "" is null

Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.
        at com.android.builder.dexing.D8DexArchiveBuilder.getExceptionToRethrow(D8DexArchiveBuilder.java:140)
        at com.android.builder.dexing.D8DexArchiveBuilder.convert(D8DexArchiveBuilder.java:117)
        at com.android.build.gradle.internal.dexing.DexWorkActionKt.process(DexWorkAction.kt:175)
        ... 39 more
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: /Users/qingyirongrong/Work/coca/coca/android/app/build/intermediates/javac/debug/classes/com/lengerrong/coca/ads/AppOpenAdManager$2.class
        at Version.fakeStackEntry(Version_3.3.83.java:0)
        at com.android.tools.r8.internal.Hj.a(R8_3.3.83_3e328a3bbd0c840823c96123eb0f6192f0adf17b30ae46f695be39af0bc3505e:75)
        at com.android.tools.r8.internal.Hj.a(R8_3.3.83_3e328a3bbd0c840823c96123eb0f6192f0adf17b30ae46f695be39af0bc3505e:28)
        at com.android.tools.r8.internal.Hj.a(R8_3.3.83_3e328a3bbd0c840823c96123eb0f6192f0adf17b30ae46f695be39af0bc3505e:27)
        at com.android.tools.r8.internal.Hj.b(R8_3.3.83_3e328a3bbd0c840823c96123eb0f6192f0adf17b30ae46f695be39af0bc3505e:2)
        at com.android.tools.r8.D8.run(R8_3.3.83_3e328a3bbd0c840823c96123eb0f6192f0adf17b30ae46f695be39af0bc3505e:11)
        at com.android.builder.dexing.D8DexArchiveBuilder.convert(D8DexArchiveBuilder.java:115)
        ... 40 more
Caused by: java.lang.NullPointerException


FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:dexBuilderDebug'.
> There were multiple failures while executing work items
   > A failure occurred while executing com.android.build.gradle.internal.dexing.DexWorkAction
      > Failed to process: /Users/qingyirongrong/Work/coca/coca/android/app/build/intermediates/javac/debug/classes
   > A failure occurred while executing com.android.build.gradle.internal.dexing.DexWorkAction
      > Failed to process: /Users/qingyirongrong/Work/coca/coca/android/app/build/intermediates/javac/debug/classes
   > A failure occurred while executing com.android.build.gradle.internal.dexing.DexWorkAction
      > Failed to process: /Users/qingyirongrong/Work/coca/coca/android/app/build/intermediates/javac/debug/classes
   > A failure occurred while executing com.android.build.gradle.internal.dexing.DexWorkAction
      > Failed to process: /Users/qingyirongrong/Work/coca/coca/android/app/build/intermediates/javac/debug/classes

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
java.lang.StackOverflowError (no error message)

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

BUILD FAILED in 6s

    at makeError (/Users/qingyirongrong/Work/coca/coca/node_modules/execa/index.js:174:9)
    at /Users/qingyirongrong/Work/coca/coca/node_modules/execa/index.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOnAllDevices (/Users/qingyirongrong/Work/coca/coca/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:82:7)
    at async Command.handleAction (/Users/qingyirongrong/Work/coca/coca/node_modules/@react-native-community/cli/build/index.js:108:9)
info Run CLI with --verbose flag for more details.

I realized I encounter the problems using higher JDK versions. My laptop OS upgraded, and the java version is now using JDK 21.

java -version 
openjdk version "21" 2023-09-19
OpenJDK Runtime Environment Zulu21.28+85-CA (build 21+35)
OpenJDK 64-Bit Server VM Zulu21.28+85-CA (build 21+35, mixed mode, sharing)
If you have already installed JDK on your system, we recommend JDK 17. You may encounter problems using higher JDK versions.
Setting up the development environment · React Native
This page will help you install and build your first React Native app.

Solution: Downgrade JDK to 17

brew tap homebrew/cask-versions
brew install --cask zulu17

# Get path to where cask was installed to double-click installer
brew info --cask zulu17

or via sdkman

sdk install java 17.0.1-zulu
sdk use java 17.0.1-zulu

check java version again.

java -version
openjdk version "17.0.1" 2021-10-19 LTS
OpenJDK Runtime Environment Zulu17.30+15-CA (build 17.0.1+12-LTS)
OpenJDK 64-Bit Server VM Zulu17.30+15-CA (build 17.0.1+12-LTS, mixed mode, sharing)

Happy Coding again with my reactive app

> Task :app:installDebug
Installing APK 'app-debug.apk' on 'Pixel_XL_API_31(AVD) - 12' for :app:debug
Installed on 1 device.
w: Detected multiple Kotlin daemon sessions at build/kotlin/sessions

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.5.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 45s
160 actionable tasks: 51 executed, 109 up-to-date
info Connecting to the development server...
8081
info Starting the app on "emulator-5554"...
Starting: Intent { cmp=com.lengerrong.coca/.MainActivity }
 BUNDLE  ./index.js 

 LOG  Running "Coca" with {"initialProps":{"launchAdStatus":"AdImpression"},"rootTag":11}

Subscribe to Post, Code and Quiet Time.

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe