11 androidPlatformVersion = "34";
12 androidBuildToolsVersion = "34.0.0";
13 #androidCmakeVersion = "3.22.1";
15 #cmakeVersions = [ androidCmakeVersion ];
16 platformVersions = [ androidPlatformVersion ];
22 buildToolsVersions = [ androidBuildToolsVersion ];
24 includeEmulator = false;
26 includeSystemImages = true;
29 "google_apis_playstore"
35 #"android-sdk-preview-license"
36 #"android-googletv-license"
37 #"android-sdk-arm-dbt-license"
38 #"intel-android-extra-license"
39 #"intel-android-sysimage-license"
40 #"mips-android-sysimage-license"
43 androidEmulateAppArgs = rec {
44 name = "android-emulate-app";
45 androidUserHome = null;
46 #androidUserHome = "/var/lib/android";
47 deviceName = "device-${androidPlatformVersion}";
49 sdkExtraArgs = androidSdkArgs // {
50 includeEmulator = true;
52 platformVersion = androidPlatformVersion;
53 systemImageType = "google_apis_playstore";
55 # PortabilityNote: workaround `-gpu host` not working
56 # on my Vulkan system.
57 androidEmulatorFlags = "-gpu guest";
60 "hw.keyboard" = "yes";
61 #"sdcard.path" = "${androidUserHome}/avd/${deviceName}.sdcard.img";
62 # FixMe: Not working for me:
63 # WARNING | emuglConfig_get_vulkan_hardware_gpu: Failed to create vulkan instance error code: -9
64 # See https://issuetracker.google.com/issues/356896486
65 #"hw.gpu.enabled" = "yes";
68 ANDROID_SDK_ROOT = "${androidComposition.androidsdk}/libexec/android-sdk";
69 ANDROID_NDK_ROOT = "${androidComposition.androidsdk}/libexec/android-sdk/ndk-bundle";
70 androidComposition = pkgs.androidenv.composeAndroidPackages config.androidSdkArgs;
75 allowUnfreePredicate =
77 builtins.elem (lib.getName pkg) [
78 "android-sdk-build-tools"
79 "android-sdk-cmdline-tools"
81 "android-sdk-platform-tools"
82 "android-sdk-platforms"
85 "android-studio-stable"
94 "android-sdk-emulator"
95 "android-sdk-system-image-${config.androidPlatformVersion}-google_apis_playstore-x86_64"
96 "system-image-${config.androidPlatformVersion}-google_apis_playstore-x86_64"
97 "system-image-${config.androidPlatformVersion}-google_apis-x86_64"
98 "android-sdk-system-image-${config.androidPlatformVersion}-google_apis-x86_64"
102 nativeBuildInputs = [
103 (pkgs.android-studio.withSdk config.androidComposition.androidsdk)
104 config.androidComposition.androidsdk
105 config.androidComposition.platform-tools
106 config.androidComposition.emulator # For mksdcard
112 # ExplanationNote: ANDROID_HOME is deprecated. Use ANDROID_SDK_ROOT.
113 export ANDROID_SDK_ROOT="${config.ANDROID_SDK_ROOT}"
114 export ANDROID_NDK_ROOT="${config.ANDROID_NDK_ROOT}"
116 lib.concatStringsSep ":" [
117 #"$ANDROID_SDK_ROOT/cmake/${config.androidCmakeVersion}/bin"
118 "$ANDROID_SDK_ROOT/build-tools/${config.androidBuildToolsVersion}"
123 # Use the same androidBuildToolsVersion
124 # and a statically linked aapt2 to workaround a dynamic linking failure.
125 export GRADLE_OPTS="-Dorg.gradle.project.android.aapt2FromMavenOverride=$ANDROID_SDK_ROOT/build-tools/${config.androidBuildToolsVersion}/aapt2";
130 default = pkgs.stdenv.mkDerivation (finalAttrs: {
131 pname = "${mainLynxBundle.pname}-apk";
132 version = mainLynxBundle.version;
140 lib.any file.hasExt [
151 app/proguard-rules.pro
153 gradle/libs.versions.toml
161 nativeBuildInputs = [
166 mitmCache = config.gradle.fetchDeps {
167 pkg = finalAttrs.finalPackage;
168 # MaintenanceNote: nix -L run .#default.update-deps
173 update-deps = pkgs.writeShellApplication {
174 name = "update-deps.sh";
176 exec ${finalAttrs.finalPackage.mitmCache.updateScript}
181 # this is required for using mitm-cache on Darwin
182 __darwinAllowLocalNetworking = true;
185 "-Dfile.encoding=utf-8"
186 # Use the same androidBuildToolsVersion
187 # and a statically linked aapt2 to workaround a dynamic linking failure.
188 "-Dorg.gradle.project.android.aapt2FromMavenOverride=${config.ANDROID_SDK_ROOT}/build-tools/${config.androidBuildToolsVersion}/aapt2"
191 #gradleBuildTask = "shadowJar";
192 gradleBuildTask = "assemble";
194 # MaintenanceToDo: remove this `gradleUpdateScript`
195 # if https://github.com/NixOS/nixpkgs/pull/383115
197 gradleUpdateScript = ''
199 gradle help --write-verification-metadata sha256
202 # will run the gradleCheckTask (defaults to "test")
207 ${mainLynxBundle}/main.lynx.bundle \
208 app/src/main/assets/main.lynx.bundle
213 if finalAttrs.gradleBuildTask == "bundleRelease" then
214 "cp -RL app/build/outputs/bundle/release/*.aab $out"
216 "cp -RL app/build/outputs/apk/*/*.apk $out"
220 meta.sourceProvenance = with lib.sourceTypes; [
222 binaryBytecode # mitm cache
226 # Run the app into an Android emulator
227 android-emulator-x86_64 = pkgs.androidenv.emulateApp (
228 config.androidEmulateAppArgs
230 abiVersion = "x86_64";
231 # SecurityToDo: sign the APK
232 # See: https://stackoverflow.com/questions/18328730/how-to-create-a-release-signed-apk-file-using-gradle
233 app = "${default}/app-debug.apk";
234 #app = "${default}/app-release-unsigned.apk";
235 package = "com.lynx.javaemptyproject";
236 activity = ".MainActivity";