2.9 file system sync on Android

I cloned the dev branch and successfully built and installed the Android apk, but the app shows an error of "unable to load script ...". like shown here. I googled and this seems a common error related to react native. Wonder if anyone has encountered the same and how was it resolved?

My env is:

$ react-native info
info Fetching system and libraries information...
System:
    OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
    CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
    Memory: 4.48 GB / 7.67 GB
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
    Yarn: 3.3.1 - ~/.nvm/versions/node/v18.12.1/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 30, 31, 32, 33
      Build Tools: 30.0.2, 30.0.3, 32.0.0, 33.0.0, 33.0.1
      Android NDK: Not Found
  IDEs:
    Android Studio: Not Found
  Languages:
    Java: 18.0.2-ea - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: Not Found
    react-native: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

The reason I tried to build it from source is that I recently updated to 2.9.8 on Android 12 and Filesystem sync still has the issue related to permissions with /storage/emulated/0/Joplin/locks/{somename}.json. (the same path works on Android 9, not sure if it should be a different one on Android 12?) Since the release note of 2.9 says that this has been resolved, I wonder maybe 2.9.8 is not the most updated version, so I tried to build 2.9.17 from source.

Most likely you've built debug version instead of release

Yes, I built a debug version.

This is what I did:

$ cd packages/app-mobile/android
$ ./gradlew
$ ./gradlew assembleDebug

Then I copied app-debug.apk from packages/app-mobile/android/app/build/outputs/apk/debug/ to my phone, and installed the apk on the phone, ran the app and got the error.

Tried on both an Android 12 phone and an Android 9 phone, same error

To use the debug version you need to connect your phone to your pc and run the server there. If you want it to work like a normal app you need the release variant.
Check out BUILD.md for details

I went again, now strictly following the BUILD.md.

from the root of the project, run:
$ yarn install

$ cd packages/app-mobile/android
$ ./gradlew installDebug

It didn't work, got the error.

The md says "Normally the bundler should start automatically with the application", but it didn't start in my case.

Then I tried:
from the root of the project, run:

$ yarn install
$ cd packages/app-mobile:
$ yarn start

in separate terminal:

$ cd packages/app-mobile/android
$ ./gradlew installDebug

It didn't work. In the Metro terminal I get some error on failing to construct transformer, ...

Somewhere on the web someone suggested trying with Node.js 16 (I had 18.12.1). So I got 16.19.0, and tried the above, and it worked.

And filesystem sync works. It's nice now that there is a UI to choose the path. And actually it also works with 2.9.8 when I set the correct path (the path I had there was from previous versions and is no long valid for Android 12)

I'm surprised that the debug version is working for you. You still might want to try building a proper release (gradlew assembleRelease but you'd need to set up signing keys first) to enable optimizations.

Why are you surprised that the debug version works?

It works on real device (Galaxy S21).

I also tried to get it to Waydroid. The app was installed with the same process above through adb. But when I ran it, the bundler doesn't seem to connect and hence I get the original error.

I thought it needed a server running on your computer to work. But maybe it only needs to load it once, not sure.

On the first startup of the app, while the USB is still connected, the app connects to the Metro server on the computer to do the bundling. It takes quite a few minutes though to complete. Then the app works on its own.

I see when building the release version, the bundling is done so the release apk includes all those. Right?

Yes. Plus I believe both the bundle and native code will be better optimized.