This repository has no description
2.4 kB
71 lines
1{
2 stdenvNoCC,
3 androidenv,
4 fetchurl,
5 jdk17_headless,
6 unzip,
7 zip,
8 icon,
9 # CI sets them per run; Android only installs updates with a higher versionCode.
10 versionCode ? 1,
11 versionName ? "1",
12}:
13let
14 sdk = androidenv.composeAndroidPackages {
15 platformVersions = [ "36" ];
16 buildToolsVersions = [ "36.0.0" ];
17 includeEmulator = false;
18 includeSystemImages = false;
19 includeNDK = false;
20 };
21 sdkRoot = "${sdk.androidsdk}/libexec/android-sdk";
22 buildTools = "${sdkRoot}/build-tools/36.0.0";
23 androidJar = "${sdkRoot}/platforms/android-36/android.jar";
24 # WebRTC for Android (LiveKit's build of Google's libwebrtc): the Java API
25 # and the native library, which needs none of the AAR's other files.
26 webrtc = fetchurl {
27 url = "https://repo1.maven.org/maven2/io/github/webrtc-sdk/android/150.7871.01/android-150.7871.01.aar";
28 hash = "sha256-ChYnsaSMK8F9mkDWL8R71FFm9EoxHpWRfxR8QC3jebA=";
29 };
30in
31# Unsigned release APK; tools/hermes-voice/flake-module.nix has the signer.
32# arm64 only: the app runs on Pixels.
33stdenvNoCC.mkDerivation {
34 pname = "hermes-voice-android";
35 version = versionName;
36 src = ./.;
37 nativeBuildInputs = [
38 jdk17_headless
39 unzip
40 zip
41 ];
42 buildPhase = ''
43 runHook preBuild
44 unzip -q ${webrtc} classes.jar 'jni/arm64-v8a/*' -d webrtc
45
46 mkdir -p res/mipmap-xxxhdpi
47 cp ${icon}/icon-192.png res/mipmap-xxxhdpi/ic_launcher.png
48 ${buildTools}/aapt2 compile --dir res -o res.zip
49 ${buildTools}/aapt2 link -o unsigned.apk -I ${androidJar} \
50 --manifest AndroidManifest.xml res.zip \
51 --min-sdk-version 34 --target-sdk-version 36 \
52 --version-code ${toString versionCode} --version-name ${versionName}
53
54 javac -source 8 -target 8 -Xlint:-options -encoding UTF-8 \
55 -bootclasspath ${androidJar} -cp webrtc/classes.jar \
56 -d classes $(find src -name '*.java')
57 ${buildTools}/d8 --release --min-api 34 --lib ${androidJar} --output . \
58 $(find classes -name '*.class') webrtc/classes.jar
59
60 mkdir -p lib/arm64-v8a
61 cp webrtc/jni/arm64-v8a/*.so lib/arm64-v8a/
62 touch -d @315532800 classes*.dex lib/arm64-v8a/*.so
63 TZ=UTC zip -X -D unsigned.apk classes*.dex
64 TZ=UTC zip -X -D -0 unsigned.apk lib/arm64-v8a/*.so
65 runHook postBuild
66 '';
67 installPhase = ''
68 install -Dm444 unsigned.apk $out/hermes-voice-android-unsigned.apk
69 '';
70 passthru = { inherit buildTools; };
71}