gluonhq / gluon-samples

Gluon sample projects
298 stars 167 forks source link

Black screen on Android 10 #38

Closed danielpeintner closed 3 years ago

danielpeintner commented 5 years ago

I updated today from Android 9 to Android 10 and all javafxports apps running before just fine are now showing a black screen.

I updated the gradle plugin to the latest version (1.3.17) and called gradlew androidInstall again with the same result. The app is installed on the device just fine but when starting it shows a black screen only.

I was thinking maybe the issue is caused by my source/configuration. However trying out other samples (e.g., https://github.com/gluonhq/gluon-samples/tree/master/rubiks-cube) show the same problem.

danielpeintner commented 5 years ago

FYI: looking at it with adb logcat I see

09-05 13:39:18.333 16910 16942 W System.err: Exception in Application start method
09-05 13:39:18.334 16910 16942 I System.out: QuantumRenderer: shutdown
09-05 13:39:18.335 16910 16936 W System.err: java.lang.reflect.InvocationTargetException
09-05 13:39:18.335 16910 16936 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
09-05 13:39:18.335 16910 16936 W System.err:    at javafxports.android.DalvikLauncher$1.run(DalvikLauncher.java:188)
09-05 13:39:18.335 16910 16936 W System.err:    at java.lang.Thread.run(Thread.java:919)
09-05 13:39:18.336 16910 16936 W System.err: Caused by: java.lang.RuntimeException: Exception in Application start method
09-05 13:39:18.336 16910 16936 W System.err:    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
09-05 13:39:18.336 16910 16936 W System.err:    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$138(LauncherImpl.java:182)
09-05 13:39:18.336 16910 16936 W System.err:    at com.sun.javafx.application.LauncherImpl.access$lambda$1(Unknown Source:8)
09-05 13:39:18.336 16910 16936 W System.err:    at com.sun.javafx.application.LauncherImpl$$Lambda$2.run(Unknown Source:13)
09-05 13:39:18.336 16910 16936 W System.err:    ... 1 more
09-05 13:39:18.338 16910 16936 W System.err: Caused by: java.lang.NoSuchMethodError: No static method newInstance(Ljava/lang/Class;)Ljava/lang/Object; in class Lsun/reflect/misc/ReflectUtil; or its super classes (declaration of 'sun.reflect.misc.ReflectUtil' appears in /apex/com.android.runtime/javalib/core-oj.jar)
09-05 13:39:18.338 16910 16936 W System.err:    at javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(FXMLLoader.java:1009)
09-05 13:39:18.338 16910 16936 W System.err:    at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:746)
09-05 13:39:18.338 16910 16936 W System.err:    at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
09-05 13:39:18.338 16910 16936 W System.err:    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
09-05 13:39:18.338 16910 16936 W System.err:    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
09-05 13:39:18.338 16910 16936 W System.err:    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
09-05 13:39:18.338 16910 16936 W System.err:    at org.peintner.myquiz.client.Main.start1(Main.java:51)
09-05 13:39:18.338 16910 16936 W System.err:    at org.peintner.myquiz.client.Main.start(Main.java:33)
09-05 13:39:18.338 16910 16936 W System.err:    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$145(LauncherImpl.java:863)
09-05 13:39:18.338 16910 16936 W System.err:    at com.sun.javafx.application.LauncherImpl.access$lambda$8(Unknown Source:4)
09-05 13:39:18.338 16910 16936 W System.err:    at com.sun.javafx.application.LauncherImpl$$Lambda$9.run(Unknown Source:7)
09-05 13:39:18.338 16910 16936 W System.err:    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$158(PlatformImpl.java:326)
09-05 13:39:18.338 16910 16936 W System.err:    at com.sun.javafx.application.PlatformImpl.access$lambda$6(Unknown Source:4)
09-05 13:39:18.338 16910 16936 W System.err:    at com.sun.javafx.application.PlatformImpl$$Lambda$7.run(Unknown Source:7)
09-05 13:39:18.338 16910 16936 W System.err:    at com.sun.javafx.application.PlatformImpl.lambda$null$156(PlatformImpl.java:295)
09-05 13:39:18.338 16910 16936 W System.err:    at com.sun.javafx.application.PlatformImpl.access$lambda$18(Unknown Source:2)
09-05 13:39:18.339 16910 16936 W System.err:    at com.sun.javafx.application.PlatformImpl$$Lambda$19.run(Unknown Source:4)
09-05 13:39:18.339 16910 16936 W System.err:    at java.security.AccessController.doPrivileged(AccessController.java:59)
09-05 13:39:18.339 16910 16936 W System.err:    at com.sun.javafx.application.PlatformImpl.lambda$runLater$157(PlatformImpl.java:294)
09-05 13:39:18.339 16910 16936 W System.err:    at com.sun.javafx.application.PlatformImpl.access$lambda$5(Unknown Source:4)
09-05 13:39:18.339 16910 16936 W System.err:    at com.sun.javafx.application.PlatformImpl$$Lambda$6.run(Unknown Source:7)
09-05 13:39:18.339 16910 16936 W System.err:    at com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:93)
09-05 13:39:18.339 16910 16936 W System.err:    at com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:52)
09-05 13:39:18.339 16910 16936 W System.err:    ... 1 more

On Android 9 it just works fine.

johanvos commented 5 years ago

Seems Android decided to make some changes in the core Java libs... ReflectUtil.newInstance is probably gone.

We can probably circumvent that in JavaFX 8, but it's about time we move to OpenJDK :)

danielpeintner commented 5 years ago

We can probably circumvent that in JavaFX 8, but it's about time we move to OpenJDK :)

Do you mean moving to a recent JDK with GraalVM as mentioned on https://github.com/gluonhq/client-samples ? Unfortunately there is no Android support yet but I really appreciate all your hard work!

johanvos commented 5 years ago

Yes, that is what I mean. There will be Android support "Soon". This recent change in Android is another motivation to move faster. We might have to create a patched version of JavaFXPorts 8 in the meantime though.

jperedadnr commented 4 years ago

Going through the Android 10 documentation, I found this:

In Android 10, the commands that you can use to enable access to non-SDK interfaces have changed. You can enable access to non-SDK interfaces on development devices by changing the API enforcement policy. To do so, use the following ADB command:

adb shell settings put global hidden_api_policy  1

So I plugged in my Android 10 device, typed that command, and voilà! all the Gluon Mobile apps I had installed started working again.

Of course, this would be a temporary workaround, and requires to set the phone in developer mode, plug it and run that command once...

@danielpeintner can you verify it works for you?

danielpeintner commented 4 years ago

Yes, it does work! Thanks! It works for my own apps and also others like the Devoxx app.

jperedadnr commented 4 years ago

Good to know, yes, that is a general setting that will let you disable this new restrictive policy in your device, for all existing and new apps.

deridex commented 4 years ago

Fyi, Devoxx posted a fix for this issue. It uses dalvik.system.VMRuntime.setHiddenApiExemptions() to unlock everything.

https://github.com/devoxx/MyDevoxxGluon/commit/a960b810e5688bd21d338cb47cf411c570078f73

PrathamSarankar24 commented 4 years ago

Going through the Android 10 documentation, I found this:

In Android 10, the commands that you can use to enable access to non-SDK interfaces have changed. You can enable access to non-SDK interfaces on development devices by changing the API enforcement policy. To do so, use the following ADB command:

adb shell settings put global hidden_api_policy  1

So I plugged in my Android 10 device, typed that command, and voilà! all the Gluon Mobile apps I had installed started working again.

Of course, this would be a temporary workaround, and requires to set the phone in developer mode, plug it and run that command once...

@danielpeintner can you verify it works for you?

Hey! I got java.lang.SecurityException

`D:\Android sdk\android-sdk\platform-tools>adb shell settings put global hidden_api_policy 1 Security exception: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS

java.lang.SecurityException: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS at com.android.providers.settings.SettingsProvider.enforceWritePermission(SettingsProvider.java:2340) at com.android.providers.settings.SettingsProvider.mutateGlobalSetting(SettingsProvider.java:1405) at com.android.providers.settings.SettingsProvider.insertGlobalSetting(SettingsProvider.java:1379) at com.android.providers.settings.SettingsProvider.call(SettingsProvider.java:556) at android.content.ContentProvider.call(ContentProvider.java:2162) at android.content.ContentProvider$Transport.call(ContentProvider.java:481) at com.android.providers.settings.SettingsService$MyShellCommand.putForUser(SettingsService.java:375) at com.android.providers.settings.SettingsService$MyShellCommand.onCommand(SettingsService.java:277) at android.os.ShellCommand.exec(ShellCommand.java:104) at com.android.providers.settings.SettingsService.onShellCommand(SettingsService.java:49) at android.os.Binder.shellCommand(Binder.java:881) at android.os.Binder.onTransact(Binder.java:765) at android.os.Binder.execTransactInternal(Binder.java:1021) at android.os.Binder.execTransact(Binder.java:994) `

jperedadnr commented 3 years ago

This is no longer an issue with the new Client plugin.

Upendra1806 commented 3 years ago

@jperedadnr Can you confirm which plugin? I am using the latest Gluon Plugin from Intellij but still have same issue.

jperedadnr commented 3 years ago

@Upendra1806 A black screen may happen for many reasons, not always related to this issue (Android 10 API changes). Are you using the Client plugin?

Upendra1806 commented 3 years ago

@jperedadnr Not using the Client plugin, working as a gradle project, Application is working for Android 8 and Android 9. The blank screen issue only with the Android 10.

ctoabidmaqbool commented 1 year ago

@jperedadnr Using above method, problem is solved for Android 10, can you please guide for Android 11 solutions

https://github.com/devoxx/MyDevoxxGluon/issues/326