rust-mobile / rust-android-examples

Various standalone Rust Android examples
112 stars 21 forks source link

GameActivity fails with String `` is not a PID #11

Open Dispersia opened 1 year ago

Dispersia commented 1 year ago

Hello, trying to write a small game for android, however having issues with the GameActivity type. NativeActivity appears fine for me, however upon trying to use GameActivity, I get Error: String `` is not a PID. This happens even in running the examples such as:

https://github.com/Dispersia/rust-android-examples/tree/main/agdk-winit-wgpu (slightly modified to work with cargo apk run in my environment + proc_macro was broken in latest nightly)

I am using cargo apk run instead of what's in the instructions there, but I believe that does the same thing or is that wrong?

Verifying alignment of /home/dispe/development/rust-android-examples/agdk-winit-wgpu/target/debug/apk/hello.apk (4)...
      49 AndroidManifest.xml (OK - compressed)
     900 lib/armeabi-v7a/libagdk_winit_wgpu.so (OK)
99927512 lib/arm64-v8a/libagdk_winit_wgpu.so (OK)
Verification succesful
Signing `/home/dispe/development/rust-android-examples/agdk-winit-wgpu/target/debug/apk/hello.apk` with keystore `/home
/dispe/.android/debug.keystore`
Performing Incremental Install
Serving... 
All files should be loaded. Notifying the device.
Success
Install command complete in 8784 ms
Starting: Intent { act=android.intent.action.MAIN cmp=io.test.test/android.app.NativeActivity }  
Status: ok
LaunchState: UNKNOWN (0)
Activity: io.test.test/android.app.NativeActivity 
WaitTime: 564
Complete
Error: String `` is not a PID 

Caused by: 
    cannot parse integer from empty string

My environment is running off of Windows Subsystem for Android as I don't have access to an Android phone. If there is any other information I can provide let me know, I didn't know where to get logs that might explain more. Thanks!

MarijnS95 commented 1 year ago

Error: String `` is not a PID from cargo-apk means that the app either hasn't started yet (and we do not recheck this in a loop for some duration of time), or has already crashed.

The PID is only used to filter logs to the application that was built and installed as Android's unfiltered logs are ridiculously spammy, but you could use them to figure out the reason your app fails to start (adb logcat -v color):

I am using cargo apk run instead of what's in the instructions there, but I believe that does the same thing or is that wrong?

That is not a good assumption to make. While cargo apk and cargo ndk initially build an identical libagdk_winit_wgpu.so, cargo apk packages that up into an APK and installs it on the phone whereas the README clearly has more steps to build the Java counterpart of the app via gradle, and finally package the Rust library and Java counterpart into an APK to install it.

MarijnS95 commented 1 year ago

Transferring this to the examples repo as it seems to be an issue with reading and executing the documentation/README rather than GameActivity itself.