msupply-foundation / open-msupply

Open mSupply represents our most recent advancement in the Logistics Management Information System (LMIS), expanding on more than two decades of development inherited from the well-established legacy of the original mSupply.
https://msupply.foundation/open-msupply/
Other
20 stars 12 forks source link

Automate Android Build #4707

Open jmbrunskill opened 1 month ago

jmbrunskill commented 1 month ago

The suggestion

Use the NZ Mac Mini to automatically create an android build when a release tag being create. Alternatively we could do it in Jenkins, if that made it easier somehow?

Why should we invest time in this?

Would save time for release team creating a android release for every release Would ensure the full build process was defined in code, reducing the reliance on sharing knowledge & keys for production builds.

Are there any risks associated with this change?

Automating a process may take more time than running it manually.

How much effort is required?

Feels like a 2-4 day job? Could go faster potentially but I think it's worth spending a few days on it if needed.

Agreed Solution

mark-prins commented 4 weeks ago

Have added the android sdk & ndk to jenkins and successfully built the apk manually. Added some steps to the jenkins build process and am testing that now

mark-prins commented 2 weeks ago

Have rolled back the changes - it is mostly compiling now but fails trying to compile the icon:

error: failed to run custom build command for `server v0.1.0 (C:\Users\Administrator\AppData\Local\Jenkins\.jenkins\workspace\omSupplyMain\server\server)`

Caused by:
  process didn't exit successfully: `C:/Users/Administrator/AppData/Local/Jenkins/.jenkins/workspace/omSupplyMain/client/packages/android/server-lib\release\build\server-aef882159edae368\build-script-set_icon` (exit code: 101)
  --- stdout
  package.metadata does not exist
  "C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.19041.0\\x64\\rc.exe"
  "C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.22621.0\\x64\\rc.exe"

  --- stderr
  thread 'main' panicked at server\src/set_icon.rs:9:19:
  called `Result::unwrap()` on an `Err` value: Custom { kind: Other, error: "Can only compile resource file when target_env is \"gnu\" or \"msvc\"" }
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

to get to this point, the linker needs to be set explicitly in server/android/.cargo/config.toml

[target.aarch64-linux-android]
linker = "{NDK_BIN}/aarch64-linux-android22-clang.cmd"
[target.armv7-linux-androideabi]
linker = "{NDK_BIN}/armv7a-linux-androideabi22-clang.cmd"

it required the path and the .cmd In theory, setting by env vars like so should work:

export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="C:/android/ndk/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android22-clang.cmd"
export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="C:/android/ndk/toolchains/llvm/prebuilt/windows-x86_64/bin/armv7a-linux-androideabi22-clang.cmd"

but it didn't for me. My solution for an os dependent config was to run

copy C:\android\config.toml C:\Users\Administrator\AppData\Local\Jenkins\.jenkins\workspace\omSupplyMain\server\android\.cargo\ /y

before building