slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.62k stars 606 forks source link

Android Build with JDK21 fails with `java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null` #4973

Open HookedBehemoth opened 7 months ago

HookedBehemoth commented 7 months ago

Tried it on Windows and Linux, with x86_64- and aarch64-linux-android, slint 1.5.0, 1.5.1 and master. Generating the example apk from cargo-apk works fine.

The generated error is in the detail tag below.

environment

> javac --version
javac 21.0.2

SDK: Tried 30 and 34 via

[package.metadata.android.sdk]
min_sdk_version = 16
target_sdk_version = 30

NDK: 26.2.11394342

reproduction

cargo apk run -p todo --target x86_64-linux-android --lib

I'd love for this feature to work. Is there any more information I can provide to help you reproduce this?

error: failed to run custom build command for `i-slint-backend-android-activity v1.6.0 (Z:\slint\internal\backends\android-activity)`

Caused by:
  process didn't exit successfully: `Z:\slint\target\debug\build\i-slint-backend-android-activity-932c2c8243f3d28a\build-script-build` (exit code: 101)
  --- stdout
  cargo:rerun-if-env-changed=ANDROID_HOME
  cargo:rerun-if-env-changed=JAVA_HOME

  --- stderr
  thread 'main' panicked at internal\backends\android-activity\build.rs:111:9:
  Dex conversion failed: Error in Z:\slint\target\x86_64-linux-android\debug\build\i-slint-backend-android-activity-c5d1017c942e9e32\out\java\dev\slint\android-activity\SlintAndroidJavaHelper$1.class:
  java.lang.NullPointerException: Cannot invoke "String.length()" because "" is null
  Compilation failed with an internal error.
  Exception in thread "main" java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: Z:\slint\target\x86_64-linux-android\debug\build\i-slint-backend-android-activity-c5d1017c942e9e32\out\java\dev\slint\android-activity\SlintAndroidJavaHelper$1.class     
        at com.android.tools.r8.utils.R0.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:126)
        at com.android.tools.r8.D8.main(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:5)
  Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: Z:\slint\target\x86_64-linux-android\debug\build\i-slint-backend-android-activity-c5d1017c942e9e32\out\java\dev\slint\android-activity\SlintAndroidJavaHelper$1.class
        at Version.fakeStackEntry(Version_8.2.2-dev.java:0)
        at com.android.tools.r8.M.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:5)
        at com.android.tools.r8.utils.R0.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:81)
        at com.android.tools.r8.utils.R0.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:32)
        at com.android.tools.r8.utils.R0.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:31)
        at com.android.tools.r8.utils.R0.b(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:2)
        at com.android.tools.r8.D8.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:26)
        at com.android.tools.r8.D8.b(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:13)
        at com.android.tools.r8.D8.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:24)
        at com.android.tools.r8.utils.R0.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:113)
        ... 1 more
  Caused by: java.lang.NullPointerException: Cannot invoke "String.length()" because "" is null
        at com.android.tools.r8.graph.u2.(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:5)
        at com.android.tools.r8.graph.p1.c(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:3)
        at com.android.tools.r8.graph.Q3.b(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:10)
        at com.android.tools.r8.internal.Ga.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:873)
        at com.android.tools.r8.graph.T3.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:44)
        at com.android.tools.r8.utils.R0.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:129)
        at com.android.tools.r8.utils.R0.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:130)
        at com.android.tools.r8.utils.R0.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:128)
        at com.android.tools.r8.graph.T3.b(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:2)
        at com.android.tools.r8.dex.a.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:27)
        at java.base/java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1456)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)
        Suppressed: java.lang.RuntimeException: java.util.concurrent.ExecutionException: com.android.tools.r8.utils.T0: java.lang.NullPointerException: Cannot invoke "String.length()" because "" is null
                at com.android.tools.r8.dex.c.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:60)
                at com.android.tools.r8.dex.c.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:9)
                at com.android.tools.r8.dex.c.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:8)
                at com.android.tools.r8.D8.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:29)
                at com.android.tools.r8.D8.d(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:17)
                at com.android.tools.r8.D8.c(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:1)
                at com.android.tools.r8.utils.R0.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:28)
                at com.android.tools.r8.utils.R0.b(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:2)
                at com.android.tools.r8.D8.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:26)
                at com.android.tools.r8.D8.b(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:13)
                at com.android.tools.r8.D8.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:24)
                at com.android.tools.r8.utils.R0.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:113)
                at com.android.tools.r8.D8.main(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:5)
        Caused by: java.util.concurrent.ExecutionException: com.android.tools.r8.utils.T0: java.lang.NullPointerException: Cannot invoke "String.length()" because "" is null
                at java.base/java.util.concurrent.ForkJoinTask.reportExecutionException(ForkJoinTask.java:581)
                at java.base/java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:993)
                at com.android.tools.r8.utils.d3.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:64)
                at com.android.tools.r8.dex.c.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:41)
                ... 12 more
        Caused by: com.android.tools.r8.utils.T0: java.lang.NullPointerException: Cannot invoke "String.length()" because "" is null
                at com.android.tools.r8.utils.R0.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:149)
                at com.android.tools.r8.utils.R0.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:128)
                at com.android.tools.r8.graph.T3.b(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:2)
                at com.android.tools.r8.dex.a.a(R8_8.2.2-dev_53a55043254cc5be8ef500331bba25d1b4ca4bc2cd66c555d4358bf672a1f10a:27)
                at java.base/java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1456)
                at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
                at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
                at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
                at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
                at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)
        Caused by: [CIRCULAR REFERENCE: java.lang.NullPointerException: Cannot invoke "String.length()" because "" is null]

  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
Error: Command `cargo build --package todo --lib --target x86_64-linux-android` had a non-zero exit code.

HookedBehemoth commented 7 months ago

Using jdk 17 makes it work with the slint master branch. From the repository I get a different error about the copyright sign not being ASCII.

error: failed to run custom build command for `i-slint-backend-android-activity v1.5.1`

Caused by:
  process didn't exit successfully: `/home/behemoth/source/timetracker/target/debug/build/i-slint-backend-android-activity-2b756c32d0ff7e66/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=ANDROID_HOME
  cargo:rerun-if-env-changed=JAVA_HOME

  --- stderr
  thread 'main' panicked at /home/behemoth/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-backend-android-activity-1.5.1/build.rs:59:9:
  Java compilation failed: java/SlintAndroidJavaHelper.java:1: error: unmappable character (0xC2) for encoding US-ASCII
  // Copyright ?? SixtyFPS GmbH <info@slint.dev>
               ^
  java/SlintAndroidJavaHelper.java:1: error: unmappable character (0xA9) for encoding US-ASCII
  // Copyright ?? SixtyFPS GmbH <info@slint.dev>
ogoffart commented 7 months ago

Thanks for reporting an issue.

The ASCII thing was fixed in https://github.com/slint-ui/slint/commit/2b7834e7c9ba41cf9ddac8b26ab08d631dfdcaa2

Regarding the first issue, it looks like the d8 script, which is part of the android sdk fails for some reason. But i'm not really understanding why. You're saying that downgrading Java SDK helps? Maybe there is an incompatibility with D8 and the new JDK? Or perhpas Slint's build script is not invoking the d8 script properly?

ogoffart commented 7 months ago

(Was also reported in #5029 with similar error:

  Dex conversion failed: Error in /home/bronson/Projects/bike-aid/bike-aid-app/target/aarch64-linux-android/debug/build/i-slint-backend-android-activity-5584ba82a1156d20/out/java/dev/slint/android-activity/SlintInputView$1.class:
  java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null
  Compilation failed with an internal error.
  Exception in thread "main" java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: /home/bronson/Projects/bike-aid/bike-aid-app/target/aarch64-linux-android/debug/build/i-slint-backend-android-activity-5584ba82a1156d20/out/java/dev/slint/android-activity/SlintInputView$1.class
  ...

Looks like there is some incompatibility with the android SDK and the java JDK 21. Googling this error show other result, but none of these link have any solutions:

I'm not sure what we should do here. Maybe we can find out what version of the android SDK and JDK are incompatibles and detect that in the build script. Or perhaps there is a better way to invoke D8 that doesn't have this error.

ogoffart commented 2 months ago

For now, the issue is being "worked around" by printing a message in the debug telling to downgrade Java.