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
113 # ExplanationNote: ANDROID_HOME is deprecated. Use ANDROID_SDK_ROOT.
114 export ANDROID_SDK_ROOT="${config.ANDROID_SDK_ROOT}"
115 export ANDROID_NDK_ROOT="${config.ANDROID_NDK_ROOT}"
117 lib.concatStringsSep ":" [
118 #"$ANDROID_SDK_ROOT/cmake/${config.androidCmakeVersion}/bin"
119 "$ANDROID_SDK_ROOT/build-tools/${config.androidBuildToolsVersion}"
124 # Use the same androidBuildToolsVersion
125 # and a statically linked aapt2 to workaround a dynamic linking failure.
126 export GRADLE_OPTS="-Dorg.gradle.project.android.aapt2FromMavenOverride=$ANDROID_SDK_ROOT/build-tools/${config.androidBuildToolsVersion}/aapt2";
131 default = pkgs.stdenv.mkDerivation (finalAttrs: {
132 pname = "${mainLynxBundle.pname}-apk";
133 version = mainLynxBundle.version;
141 lib.any file.hasExt [
152 app/proguard-rules.pro
154 gradle/libs.versions.toml
162 nativeBuildInputs = [
167 mitmCache = config.gradle.fetchDeps {
168 pkg = finalAttrs.finalPackage;
169 # MaintenanceNote: nix -L run .#default.update-deps
174 update-deps = pkgs.writeShellApplication {
175 name = "update-deps.sh";
177 exec ${finalAttrs.finalPackage.mitmCache.updateScript}
182 # this is required for using mitm-cache on Darwin
183 __darwinAllowLocalNetworking = true;
186 "-Dfile.encoding=utf-8"
187 # Use the same androidBuildToolsVersion
188 # and a statically linked aapt2 to workaround a dynamic linking failure.
189 "-Dorg.gradle.project.android.aapt2FromMavenOverride=${config.ANDROID_SDK_ROOT}/build-tools/${config.androidBuildToolsVersion}/aapt2"
192 #gradleBuildTask = "shadowJar";
193 gradleBuildTask = "assemble";
195 # MaintenanceToDo: remove this `gradleUpdateScript`
196 # if https://github.com/NixOS/nixpkgs/pull/383115
198 gradleUpdateScript = ''
200 gradle help --write-verification-metadata sha256
203 # will run the gradleCheckTask (defaults to "test")
208 ${mainLynxBundle}/main.lynx.bundle \
209 app/src/main/assets/main.lynx.bundle
214 if finalAttrs.gradleBuildTask == "bundleRelease" then
215 "cp -RL app/build/outputs/bundle/release/*.aab $out"
217 "cp -RL app/build/outputs/apk/*/*.apk $out"
221 meta.sourceProvenance = with lib.sourceTypes; [
223 binaryBytecode # mitm cache
227 # Run the app into an Android emulator
228 android-emulator-x86_64 = pkgs.androidenv.emulateApp (
229 config.androidEmulateAppArgs
231 abiVersion = "x86_64";
232 # SecurityToDo: sign the APK
233 # See: https://stackoverflow.com/questions/18328730/how-to-create-a-release-signed-apk-file-using-gradle
234 app = "${default}/app-debug.apk";
235 #app = "${default}/app-release-unsigned.apk";
236 package = "com.lynx.javaemptyproject";
237 activity = ".MainActivity";