gluonhq / attach

GNU General Public License v3.0
49 stars 26 forks source link

Version 4.0.16 causes black screen on startup #341

Closed nlisker closed 1 year ago

nlisker commented 1 year ago

Original question on SO for reference: https://stackoverflow.com/questions/74091196/gluon-attach-4-0-16-causes-black-screen-on-startup.

Full POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.demo</groupId>
    <artifactId>demo-client</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <name>Demo</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <minimum-maven-version>3.8.4</minimum-maven-version>
        <versions-maven-plugin-version>2.12.0</versions-maven-plugin-version>
        <maven-enforcer-plugin-version>3.1.0</maven-enforcer-plugin-version>
        <maven-compiler-plugin-version>3.10.1</maven-compiler-plugin-version>
        <maven-surefire-plugin-version>3.0.0-M6</maven-surefire-plugin-version>
        <javafx-maven-plugin-version>0.0.8</javafx-maven-plugin-version>
        <gluonfx-maven-plugin-version>1.0.16-SNAPSHOT</gluonfx-maven-plugin-version>

        <java-version>17</java-version>
        <javafx-version>19</javafx-version>
        <jackson-version>2.14.0-rc2</jackson-version>
        <charm-version>6.2.2</charm-version>
        <attach-version>4.0.16</attach-version>

        <lombok-version>1.18.24</lombok-version>
        <junit-version>5.7.0</junit-version>

        <main.class>com.demo.MyApplication</main.class>
        <app.identifier>${main.class}</app.identifier>
        <app.description>The Demo app</app.description>
        <package.type />
        <mac.app.store />
        <mac.signing.user.name />
        <bundle.version />
        <bundle.short.version />
        <version.code />
        <provided.keystore.path />
        <provided.keystore.password />
        <provided.key.alias />
        <provided.key.alias.password />
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok-version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${javafx-version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-media</artifactId>
            <version>${javafx-version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson-version}</version>
        </dependency>

        <dependency>
            <groupId>com.gluonhq</groupId>
            <artifactId>charm-glisten</artifactId>
            <version>${charm-version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>display</artifactId>
            <version>${attach-version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>lifecycle</artifactId>
            <version>${attach-version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>statusbar</artifactId>
            <version>${attach-version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>storage</artifactId>
            <version>${attach-version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>position</artifactId>
            <version>${attach-version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>accelerometer</artifactId>
            <version>${attach-version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>magnetometer</artifactId>
            <version>${attach-version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>audio</artifactId>
            <version>${attach-version}</version>
        </dependency>
        <dependency>
            <groupId>com.gluonhq.attach</groupId>
            <artifactId>util</artifactId>
            <version>${attach-version}</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>Gluon</id>
            <url>https://nexus.gluonhq.com/nexus/content/repositories/releases</url>
        </repository>
        <repository>
            <id>snapshot</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>snapshot</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        </pluginRepository>
    </pluginRepositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>${maven-enforcer-plugin-version}</version>
                <executions>
                    <execution>
                        <id>enforce-maven</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <requireMavenVersion>
                                    <version>${minimum-maven-version}</version>
                                </requireMavenVersion>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>${versions-maven-plugin-version}</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin-version}</version>
                <configuration>
                    <release>${java-version}</release>
                    <compilerArgs>
                        <!-- <arg>add a  - -enable-preview</arg> -->
                    </compilerArgs>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>${javafx-maven-plugin-version}</version>
                <configuration>
                    <mainClass>${main.class}</mainClass>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.gluonhq</groupId>
                <artifactId>gluonfx-maven-plugin</artifactId>
                <version>${gluonfx-maven-plugin-version}</version>
                <configuration>
                    <verbose>true</verbose>
                    <javafxStaticSdkVersion>${javafx-version}</javafxStaticSdkVersion>
                    <target>${gluonfx.target}</target>
                    <attachList>
                        <list>display</list>
                        <list>lifecycle</list>
                        <list>statusbar</list>
                        <list>storage</list>
                        <list>position</list>
                        <list>accelerometer</list>
                        <list>magnetometer</list>
                        <list>audio</list>
                    </attachList>
                    <resourcesList>
                        <item>.*/LongBeep.wav$</item>
                        <item>.*/ShortBeep.wav$</item>
                    </resourcesList>
                    <mainClass>${main.class}</mainClass>
                    <appIdentifier>${app.identifier}</appIdentifier>
                    <releaseConfiguration>
                        <vendor>Gluon</vendor>
                        <description>${app.description}</description>
                        <packageType>${package.type}</packageType>
                        <!-- for macOS/iOS -->
                        <macAppStore>${mac.app.store}</macAppStore>
                        <bundleShortVersion>${bundle.short.version}</bundleShortVersion>
                        <bundleVersion>${bundle.version}</bundleVersion>
                        <!-- for Android -->
                        <versionCode>${version.code}</versionCode>
                        <providedKeyStorePath>${provided.keystore.path}</providedKeyStorePath>
                        <providedKeyStorePassword>${provided.keystore.password}</providedKeyStorePassword>
                        <providedKeyAlias>${provided.key.alias}</providedKeyAlias>
                        <providedKeyAliasPassword>${provided.key.alias.password}</providedKeyAliasPassword>
                    </releaseConfiguration>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>desktop</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <gluonfx.target>host</gluonfx.target>
            </properties>
        </profile>
        <profile>
            <id>mac</id>
            <properties>
                <package.type>pkg</package.type>
                <mac.app.store>false</mac.app.store>
                <bundle.version>${env.GITHUB_RUN_NUMBER}</bundle.version>
                <bundle.short.version>1.0</bundle.short.version>
            </properties>
        </profile>
        <profile>
            <id>macstore</id>
            <properties>
                <package.type>pkg</package.type>
                <mac.app.store>true</mac.app.store>
                <bundle.version>1.${env.GITHUB_RUN_NUMBER}</bundle.version>
                <bundle.short.version>1.6</bundle.short.version>
            </properties>
        </profile>
        <profile>
            <id>ios</id>
            <properties>
                <gluonfx.target>ios</gluonfx.target>
                <bundle.version>${env.GITHUB_RUN_NUMBER}</bundle.version>
                <bundle.short.version>1.0</bundle.short.version>
            </properties>
        </profile>
        <profile>
            <id>android</id>
            <properties>
                <gluonfx.target>android</gluonfx.target>
                <app.identifier>com.my.demo</app.identifier>
                <version.code>${env.GITHUB_RUN_NUMBER}</version.code>
                <provided.keystore.path>${env.GLUON_ANDROID_KEYSTOREPATH}</provided.keystore.path>
                <provided.keystore.password>${env.GLUON_ANDROID_KEYSTORE_PASSWORD}</provided.keystore.password>
                <provided.key.alias>${env.GLUON_ANDROID_KEYALIAS}</provided.key.alias>
                <provided.key.alias.password>${env.GLUON_ANDROID_KEYALIAS_PASSWORD}</provided.key.alias.password>
            </properties>
        </profile>
        <profile>
            <id>pi</id>
            <properties>
                <gluonfx.target>linux-aarch64</gluonfx.target>
            </properties>
        </profile>
    </profiles>
</project>

Using graalvm-svm-java17-linux-gluon-22.1.0.1-Final.

Causes the following error from adb logcat:

10-17 15:04:24.966 26884 26908 D GluonAttach: Util :: Load className com/gluonhq/helloandroid/DalvikDisplayService
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504] JNI DETECTED ERROR IN APPLICATION: JNI NewStringUTF called with pending exception java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   at void android.os.Handler.<init>(android.os.Handler$Callback, boolean) (Handler.java:203)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   at void android.os.Handler.<init>() (Handler.java:117)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   at void android.content.ClipboardManager$2.<init>(android.content.ClipboardManager) (ClipboardManager.java:84)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   at void android.content.ClipboardManager.<init>(android.content.Context, android.os.Handler) (ClipboardManager.java:84)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   at android.content.ClipboardManager android.app.SystemServiceRegistry$12.createService(android.app.ContextImpl) (SystemServiceRegistry.java:379)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   at java.lang.Object android.app.SystemServiceRegistry$12.createService(android.app.ContextImpl) (SystemServiceRegistry.java:377)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   at java.lang.Object android.app.SystemServiceRegistry$CachedServiceFetcher.getService(android.app.ContextImpl) (SystemServiceRegistry.java:1402)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   at java.lang.Object android.app.SystemServiceRegistry.getSystemService(android.app.ContextImpl, java.lang.String) (SystemServiceRegistry.java:1354)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   at java.lang.Object android.app.ContextImpl.getSystemService(java.lang.String) (ContextImpl.java:1695)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   at java.lang.Object android.view.ContextThemeWrapper.getSystemService(java.lang.String) (ContextThemeWrapper.java:171)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   at java.lang.Object android.app.Activity.getSystemService(java.lang.String) (Activity.java:6008)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   at void com.gluonhq.helloandroid.Util.<init>(android.app.Activity) (Util.java:53)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]     in call to NewStringUTF
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504] "Thread-6" daemon prio=5 tid=16 Runnable
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   | group="main" sCount=0 dsCount=0 flags=0 obj=0x12e80000 self=0x7e74f27800
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   | sysTid=26908 nice=0 cgrp=default sched=0/0 handle=0x7e604ff4f0
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   | state=R schedstat=( 106877037 2373803 92 ) utm=9 stm=1 core=2 HZ=100
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   | stack=0x7e60405000-0x7e60407000 stackSize=1005KB
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   | held mutexes= "mutator lock"(shared held)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   native: #00 pc 00000000003973ec  /system/lib64/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv+212)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   native: #01 pc 000000000045dba0  /system/lib64/libart.so (_ZNK3art6Thread9DumpStackERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEbP12BacktraceMapb+348)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   native: #02 pc 00000000002d57b8  /system/lib64/libart.so (_ZN3art9JavaVMExt8JniAbortEPKcS2_+1040)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   native: #03 pc 00000000002d5c38  /system/lib64/libart.so (_ZN3art9JavaVMExt9JniAbortVEPKcS2_St9__va_list+116)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   native: #04 pc 0000000000108878  /system/lib64/libart.so (_ZN3art11ScopedCheck6AbortFEPKcz+148)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   native: #05 pc 00000000001083a4  /system/lib64/libart.so (_ZN3art11ScopedCheck11CheckThreadEP7_JNIEnv+536)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   native: #06 pc 0000000000106840  /system/lib64/libart.so (_ZN3art11ScopedCheck5CheckERNS_18ScopedObjectAccessEbPKcPNS_12JniValueTypeE+856)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   native: #07 pc 00000000000fd004  /system/lib64/libart.so (_ZN3art8CheckJNI12NewStringUTFEP7_JNIEnvPKc+648)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   native: #08 pc 00000000019c07f0  /data/app/com.gps.demo-vSN-YTEtwQ1kgcyL1xFIMg==/lib/arm64/libsubstrate.so (registerDalvikClass+448)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   native: #09 pc 00000000019be2e4  /data/app/com.gps.demo-vSN-YTEtwQ1kgcyL1xFIMg==/lib/arm64/libsubstrate.so (initializeDisplayDalvikHandles+36)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   native: #10 pc 00000000019bde90  /data/app/com.gps.demo-vSN-YTEtwQ1kgcyL1xFIMg==/lib/arm64/libsubstrate.so (JNI_OnLoad_display+140)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   native: #11 pc 00000000002e2ea8  /data/app/com.gps.demo-vSN-YTEtwQ1kgcyL1xFIMg==/lib/arm64/libsubstrate.so (JNILibraryInitializer_callOnLoadFunction_7833a452cbe2b969eec248ff45fd5fe129f3cbdc+104)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]   (no managed stack frames)
10-17 15:04:24.982 26884 26908 F zygote64: java_vm_ext.cc:504]

Happens with GluonFX 1.0.15 as well. Attach 4.0.15 works fine.

Device details: Samsung Galaxy S7 Screenshot_20221017-163019_Settings

nlisker commented 1 year ago

Can't upload an APK directly because the APKs that are produced are ~25MB from the get-go. Here is a share link: https://drive.google.com/file/d/1znRO8LCCoUwaYk2fp1tczJfZLXUXzuhu/view?usp=sharing

nlisker commented 1 year ago

On OnePlus 8T with Android 12 there is no issue.

jperedadnr commented 1 year ago

It seems it fails only for Android 8, which might indicate that the call:

Util.clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);

requires some extra code for such Android level.

See related https://stackoverflow.com/questions/9027629/android-clipboard-code-that-works-on-all-api-levels/12946228#12946228

nlisker commented 1 year ago

I have just tested with Attach 4.0.18 and the problem still exists. We can't upgrade attach beyond 4.0.15 without breaking our Android 8 clients.

jperedadnr commented 1 year ago

@nlisker Is it possible that you build yourself Attach with this patch and test?

diff --git a/modules/util/src/main/native/android/dalvik/Util.java b/modules/util/src/main/native/android/dalvik/Util.java
index 2e76019..e63b66d 100644
--- a/modules/util/src/main/native/android/dalvik/Util.java
+++ b/modules/util/src/main/native/android/dalvik/Util.java
@@ -50,8 +50,14 @@ public class Util {
         Util.activity = activity;
         Log.v(TAG, "Util <init>");
         if (activity != null) {
-            Util.clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
-            syncClipboardFromOS();
+            new Handler(Util.activity.getMainLooper()).postDelayed(new Runnable() {
+
+                @Override
+                public void run() {
+                    Util.clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
+                    syncClipboardFromOS();
+                }
+            }, 0);
         }
     }

(with the Android toolchain installed, run sh gradlew build publishToMavenLocal to build and install Attach 4.0.19-SNAPSHOT)

nlisker commented 1 year ago

Where do I downloaded the toolchain from? There are the command line tools at https://developer.android.com/studio/index.html#command-line-tools-only and the NDK at https://developer.android.com/ndk/downloads. Neither contain the required android.jar.

jperedadnr commented 1 year ago

If you have the Android SDK/NDK for GluonFX/Substrate, then that's all you need. Just make sure you have ANDROID_SDK and ANDROID_NDK defined.

nlisker commented 1 year ago

I have the ones from the links above. What are the ones for GluonFX/Substrate? Are there instructions somewhere? Attach's README doesn't show any.

jperedadnr commented 1 year ago

If you deploy for Android with the GluonFX plugin on Linux, you need ANDROID_SDK and ANDROID_NDK. If you don't set them, the plugin manages to download and install them for you, at ~/.gluon/substrate/Android

Then, to build Attach, you would just need to set: ANDROID_SDK=/your user path/.gluon/substrate/Android ANDROID_NDK=/your user path/.gluon/substrate/Android/ndk

nlisker commented 1 year ago

Ah, alright. I use WSL. I'll try it out later.

nlisker commented 1 year ago

Thanks, I set the env variables. Now I'm getting an error with the new code in Util:

error: local variable activity is accessed from within inner class; needs to be declared final

   Util.clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
                                       ^
jperedadnr commented 1 year ago

That shouldn’t happen, set JAVA_HOME to JDK 11 or 17? Check also the GitHub action workflow

nlisker commented 1 year ago

JAVA_HOME is set to 17 and java --version gives openjdk 17.0.3 2022-04-19.

nlisker commented 1 year ago

I tried ./gradlew -i nativeBuild as the action workflow does, same issue.

nlisker commented 1 year ago

I deleted some caches and restarted the gradle daemon. Now I'm getting another error during :accelerometer:androidBuild:

Could not write standard input to Gradle build daemon.
java.io.IOException: Stream closed
        at java.base/java.lang.ProcessBuilder$NullOutputStream.write(ProcessBuilder.java:445)
        at java.base/java.io.OutputStream.write(OutputStream.java:162)
        at java.base/java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:81)
        at java.base/java.io.BufferedOutputStream.flush(BufferedOutputStream.java:142)
        at org.gradle.process.internal.streams.ExecOutputHandleRunner.forwardContent(ExecOutputHandleRunner.java:68)
        at org.gradle.process.internal.streams.ExecOutputHandleRunner.run(ExecOutputHandleRunner.java:53)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)

FAILURE: Build failed with an exception.

* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/7.5/userguide/gradle_daemon.html
Process command line: /usr/lib/jvm/java-17-openjdk-amd64/bin/java -XX:MaxPermSize=1024m -XX:MaxMetaspaceSize=1g --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -Xms512M -Xmx4g -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/nlisker/.gradle/wrapper/dists/gradle-7.5-bin/7u84gh846ok982rnccbf0jshgv/gradle-7.5/lib/gradle-launcher-7.5.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 7.5
Please read the following process output to find out more:
-----------------------
Unrecognized VM option 'MaxPermSize=1024m'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Indeed, in Java 17 that option was removed. Any idea where it comes from?

jperedadnr commented 1 year ago

See https://github.com/gluonhq/attach/blob/master/gradle/android_project/gradle.properties#L3 you can simply edit the file and remove -XX:MaxPermSize=1024m, or use JDK 11.

nlisker commented 1 year ago

Thanks, I managed to build Attach and build the client using the snapshot version. Unfortunately, I'm still getting a black screen, and after a few seconds I get a message that the app has stopped.

jperedadnr commented 1 year ago

Can you post the stack trace from logcat?

nlisker commented 1 year ago

This looks like the relevant part, if you need something before or after I will paste here.

05-02 22:57:04.479 24401 24426 D GluonAttach: [Display Service] Initializing native Display from OnLoad
05-02 22:57:04.479 24401 24426 D GraalGluon: ATTACH_DALVIK, tid = 24426, existed? 1, dalvikEnv at 0x73480b6500
05-02 22:57:04.479 24401 24426 D GluonAttach: Util :: Load className com/gluonhq/helloandroid/DalvikDisplayService
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504] JNI DETECTED ERROR IN APPLICATION: JNI NewStringUTF called with pending exception java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   at void android.os.Handler.<init>(android.os.Handler$Callback, boolean) (Handler.java:203)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   at void android.os.Handler.<init>() (Handler.java:117)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   at void android.content.ClipboardManager$2.<init>(android.content.ClipboardManager) (ClipboardManager.java:84)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   at void android.content.ClipboardManager.<init>(android.content.Context, android.os.Handler) (ClipboardManager.java:84)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   at android.content.ClipboardManager android.app.SystemServiceRegistry$12.createService(android.app.ContextImpl) (SystemServiceRegistry.java:379)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   at java.lang.Object android.app.SystemServiceRegistry$12.createService(android.app.ContextImpl) (SystemServiceRegistry.java:377)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   at java.lang.Object android.app.SystemServiceRegistry$CachedServiceFetcher.getService(android.app.ContextImpl) (SystemServiceRegistry.java:1402)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   at java.lang.Object android.app.SystemServiceRegistry.getSystemService(android.app.ContextImpl, java.lang.String) (SystemServiceRegistry.java:1354)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   at java.lang.Object android.app.ContextImpl.getSystemService(java.lang.String) (ContextImpl.java:1695)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   at java.lang.Object android.view.ContextThemeWrapper.getSystemService(java.lang.String) (ContextThemeWrapper.java:171)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   at java.lang.Object android.app.Activity.getSystemService(java.lang.String) (Activity.java:6008)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   at void com.gluonhq.helloandroid.Util.<init>(android.app.Activity) (Util.java:53)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]     in call to NewStringUTF
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504] "Thread-6" daemon prio=5 tid=16 Runnable
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   | group="main" sCount=0 dsCount=0 flags=0 obj=0x12d00000 self=0x7357739600
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   | sysTid=24426 nice=0 cgrp=default sched=0/0 handle=0x7341dff4f0
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   | state=R schedstat=( 111957394 5913075 67 ) utm=9 stm=2 core=3 HZ=100
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   | stack=0x7341d05000-0x7341d07000 stackSize=1005KB
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   | held mutexes= "mutator lock"(shared held)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   native: #00 pc 00000000003973ec  /system/lib64/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv+212)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   native: #01 pc 000000000045dba0  /system/lib64/libart.so (_ZNK3art6Thread9DumpStackERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEbP12BacktraceMapb+348)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   native: #02 pc 00000000002d57b8  /system/lib64/libart.so (_ZN3art9JavaVMExt8JniAbortEPKcS2_+1040)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   native: #03 pc 00000000002d5c38  /system/lib64/libart.so (_ZN3art9JavaVMExt9JniAbortVEPKcS2_St9__va_list+116)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   native: #04 pc 0000000000108878  /system/lib64/libart.so (_ZN3art11ScopedCheck6AbortFEPKcz+148)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   native: #05 pc 00000000001083a4  /system/lib64/libart.so (_ZN3art11ScopedCheck11CheckThreadEP7_JNIEnv+536)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   native: #06 pc 0000000000106840  /system/lib64/libart.so (_ZN3art11ScopedCheck5CheckERNS_18ScopedObjectAccessEbPKcPNS_12JniValueTypeE+856)
05-02 22:57:04.494 24401 24426 F zygote64: java_vm_ext.cc:504]   native: #07 pc 00000000000fd004  /system/lib64/libart.so (_ZN3art8CheckJNI12NewStringUTFEP7_JNIEnvPKc+648)
jperedadnr commented 1 year ago

Hmm, looks like the same logcat you already posted earlier:

at void com.gluonhq.helloandroid.Util.<init>(android.app.Activity) (Util.java:53)

means that there are no changes in Util... Are you sure you are using the Attach snapshot? Did you build, package and deploy again?

nlisker commented 1 year ago

I have <attach-version>4.0.19-SNAPSHOT</attach-version> in my pom and I ran mvn -Pandroid gluonfx:build gluonfx:package. I can also see in the local maven repository that the 4.0.19-SNAPSHOT directory was created after I ran the publishToMavenLocal command on attach. I can try to clean / delete caches.

jperedadnr commented 1 year ago

Just to be sure, add some printouts (Log.v(TAG, "Util <init> 1");, Log.v(TAG, "Util <init> 2"); ... ) and see that you get them before the exception?

nlisker commented 1 year ago

The error with the non-final variable repeats after I clear the caches and builds. If I try to build again then it somehow succeeds. However, I noticed that when building the application, it takes the 4.0.19-SNAPSHOT build from the online repository, which is why the JNI error repeated itself. I tried to change the gradle.properties version to 4.0.20-SNAPSHOT to make sure it doesn't come from a remote repo. Then I built the client again and got this exception:

05-03 18:53:30.230 18526 18546 D GraalCompiled: Exception in Application start method
05-03 18:53:30.231 18526 18546 D GraalCompiled: QuantumRenderer: shutdown
05-03 18:53:30.231 18526 18546 D GraalCompiled: Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
05-03 18:53:30.233 18526 18546 D GraalCompiled:         at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:893)
05-03 18:53:30.233 18526 18546 D GraalCompiled:         at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
05-03 18:53:30.233 18526 18546 D GraalCompiled:         at java.lang.Thread.run(Thread.java:833)
05-03 18:53:30.233 18526 18546 D GraalCompiled:         at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:704)
05-03 18:53:30.233 18526 18546 D GraalCompiled:         at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)
05-03 18:53:30.233 18526 18546 D GraalCompiled: Caused by: java.lang.UnsatisfiedLinkError: no util in java.library.path
05-03 18:53:30.233 18526 18546 D GraalCompiled:         at com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibraryRelative(NativeLibrarySupport.java:132)
05-03 18:53:30.233 18526 18546 D GraalCompiled:         at java.lang.ClassLoader.loadLibrary(ClassLoader.java:47)
05-03 18:53:30.233 18526 18546 D GraalCompiled:         at java.lang.Runtime.loadLibrary0(Runtime.java:818)
05-03 18:53:30.233 18526 18546 D GraalCompiled:         at java.lang.System.loadLibrary(System.java:1989)
05-03 18:53:30.233 18526 18546 D GraalCompiled:         at com.gluonhq.attach.util.Platform.<clinit>(Platform.java:83)
05-03 18:53:30.234 18526 18546 D GraalCompiled:         at com.gluonhq.attach.util.impl.DefaultServiceFactory.getInstance(DefaultServiceFactory.java:56)
05-03 18:53:30.234 18526 18546 D GraalCompiled:         at com.gluonhq.attach.util.Services.get(Services.java:85)
05-03 18:53:30.234 18526 18546 D GraalCompiled:         at com.gluonhq.attach.display.DisplayService.create(DisplayService.java:95)
05-03 18:53:30.234 18526 18546 D GraalCompiled:         at com.gluonhq.impl.charm.glisten.util.DeviceSettings.hasNotch(DeviceSettings.java:27)
05-03 18:53:30.234 18526 18546 D GraalCompiled:         at com.gluonhq.impl.charm.glisten.util.DeviceSettings.setup(DeviceSettings.java:45)
05-03 18:53:30.234 18526 18546 D GraalCompiled:         at com.gluonhq.impl.charm.glisten.util.DeviceSettings.dedicatedSetup(DeviceSettings.java:38)
05-03 18:53:30.234 18526 18546 D GraalCompiled:         at com.gluonhq.charm.glisten.control.AppBar.<init>(AppBar.java:127)
05-03 18:53:30.234 18526 18546 D GraalCompiled:         at com.gluonhq.charm.glisten.application.AppManager.start(AppManager.java:258)

So I suspect there really is a problem in building Util.

jperedadnr commented 1 year ago

I've raised a PR for this #361 Once merged you will be able to test the snapshot from Sonatype.

nlisker commented 1 year ago

Is 4.0.19-SNAPSHOT updated or should I wait some time?

jperedadnr commented 1 year ago

Just wait until the github action finishes (10 minutes or so), then it will be ready from Sonatype.

nlisker commented 1 year ago

I delete my maven cache and cleaned the project. Now when I run mvn -Pandroid gluonfx:build gluonfx:package using 4.0.19-SNAPSHOT I get this error, which I have never gotten before:

[INFO] --- gluonfx-maven-plugin:1.0.15:compile (default-cli) @ gps-demo-client ---
java.lang.IllegalStateException: Duplicate key display (attempted merging values com.gluonhq.attach:display:jar:android:4.0.19-SNAPSHOT:compile and com.gluonhq.attach:display:jar:android:4.0.19-SNAPSHOT:compile)
        at java.base/java.util.stream.Collectors.duplicateKeyException(Collectors.java:135)
        at java.base/java.util.stream.Collectors.lambda$uniqKeysMapAccumulator$1(Collectors.java:182)
        at java.base/java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
        at java.base/java.util.stream.DistinctOps$1$2.accept(DistinctOps.java:174)
        at java.base/java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1707)
        at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
        at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:276)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
        at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
        at com.gluonhq.attach.AttachArtifactResolver.findArtifactsForTarget(AttachArtifactResolver.java:79)
        at com.gluonhq.NativeBaseMojo.getAttachDependencies(NativeBaseMojo.java:315)
        at com.gluonhq.NativeBaseMojo.getClasspathElements(NativeBaseMojo.java:238)
        at com.gluonhq.NativeBaseMojo.getProjectClasspath(NativeBaseMojo.java:223)
        at com.gluonhq.NativeBaseMojo.createSubstrateConfiguration(NativeBaseMojo.java:163)
        at com.gluonhq.NativeBaseMojo.createSubstrateDispatcher(NativeBaseMojo.java:158)
        at com.gluonhq.NativeCompileMojo.execute(NativeCompileMojo.java:53)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
        at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:370)
        at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:351)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:215)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:171)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:163)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:294)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:960)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:293)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:196)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
jperedadnr commented 1 year ago

Hmm, never seen that one either.

(Unrelated probably, why are you still with plugin 1.0.15? 1.0.18 is the latest one)

Next: what is your maven version? there is an issue with 3.9.0+ and the (latest) plugin requires a lower version, like 3.8.8.

Have you checked that the 4.0.19-SNAPSHOT files in your .m2 come from Sonatype?

Have you checked your pom for duplicated runtime dependency entries?

nlisker commented 1 year ago

(Unrelated probably, why are you still with plugin 1.0.15? 1.0.18 is the latest one)

I'm using the maven versions plugin that is supposed to tell me when an updated version of a plugin exists. It insists that 1.0.15 is the latest. I changed it to 1.0.18.

Next: what is your maven version? there is an issue with 3.9.0+ and the (latest) plugin requires a lower version, like 3.8.8.

3.8.6

Have you checked that the 4.0.19-SNAPSHOT files in your .m2 come from Sonatype?

I deleted the attach cache there, so I don't know where else it could come from. The _remote.repositories file (under util, for example) which is supposed to contain that info is

#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Fri May 05 14:05:23 IDT 2023
util-4.0.19-20230505.104751-6.pom>snapshot=
util-4.0.19-20230505.104751-6.jar>snapshot=

so I'm not sure where it's from.

Have you checked your pom for duplicated runtime dependency entries?

Yes. If I change the attach version to 4.0.15 everything builds fine. The pom is the same as I posted above, only with some version changes.

jperedadnr commented 1 year ago

https://github.com/gluonhq/gluonfx-maven-plugin and https://central.sonatype.com/search?q=g:com.gluonhq%20%20a:gluonfx-maven-plugin&smo=true show 1.0.18, not sure about what that plugin is doing.

Can you post

mvn dependency:tree

(see if there are duplicated entries for com.gluonhq.attach:display)

Also, can you try

mvn -U -Pandroid gluonfx:build gluonfx:package

If it builds fine, uninstall the app from your mobile before installing again.

nlisker commented 1 year ago

This is the dependency tree:

[INFO] com.demo:demo-client:jar:1.0.0-SNAPSHOT
[INFO] +- org.projectlombok:lombok:jar:1.18.26:provided
[INFO] +- org.openjfx:javafx-controls:jar:20:compile
[INFO] |  +- org.openjfx:javafx-controls:jar:linux:20:compile
[INFO] |  \- org.openjfx:javafx-graphics:jar:20:compile
[INFO] |     +- org.openjfx:javafx-graphics:jar:linux:20:compile
[INFO] |     \- org.openjfx:javafx-base:jar:20:compile
[INFO] |        \- org.openjfx:javafx-base:jar:linux:20:compile
[INFO] +- org.openjfx:javafx-media:jar:20:compile
[INFO] |  \- org.openjfx:javafx-media:jar:linux:20:compile
[INFO] +- com.gluonhq:charm-glisten:jar:6.2.3:compile
[INFO] +- com.gluonhq.attach:display:jar:4.0.19-SNAPSHOT:compile
[INFO] +- com.gluonhq.attach:lifecycle:jar:4.0.19-SNAPSHOT:compile
[INFO] +- com.gluonhq.attach:statusbar:jar:4.0.19-SNAPSHOT:compile
[INFO] +- com.gluonhq.attach:storage:jar:4.0.19-SNAPSHOT:compile
[INFO] +- com.gluonhq.attach:position:jar:4.0.19-SNAPSHOT:compile
[INFO] +- com.gluonhq.attach:accelerometer:jar:4.0.19-SNAPSHOT:compile
[INFO] +- com.gluonhq.attach:magnetometer:jar:4.0.19-SNAPSHOT:compile
[INFO] +- com.gluonhq.attach:audio:jar:4.0.19-SNAPSHOT:compile
[INFO] \- com.gluonhq.attach:util:jar:4.0.19-SNAPSHOT:compile
jperedadnr commented 1 year ago

Nothing wrong there.

The snapshot seems fine: 20230505.104751-6 is the latest version, see: https://oss.sonatype.org/content/repositories/snapshots/com/gluonhq/attach/display/4.0.19-SNAPSHOT/display-4.0.19-20230505.104751-6.jar

I've clear my Attach cache as well, building a regular HelloGluon (with a TextField control) for Android works fine for me. Can you maybe try that?

nlisker commented 1 year ago

I cloned HelloGluon, changed to attach 4.0.19-SNAPSHOT and added the snapshot repository. It built and ran fine. Then I built my project without any changes and it also built and ran fine (including the clipboard). I'm guessing the HelloGluon build unstuck something, but I have no idea what since I cleaned everything previously as well.

So it looks like the problem is resolved. Thanks for all the help!