From 88ef7a859897a84bd526b0cdeae034daf03ce1c2 Mon Sep 17 00:00:00 2001 From: Morgan Jones Date: Mon, 27 May 2024 03:15:47 -0700 Subject: [PATCH 1/5] {android-studio,androidenv}: add withSdk passthru and androidPkgs Rename androidPkgs_9_0 to androidPkgs, and treat it more like a "full" androidenv package. --- .../editors/android-studio/common.nix | 48 +++++++++++++++---- .../androidenv/compose-android-packages.nix | 4 +- .../development/mobile/androidenv/default.nix | 8 ++-- .../graphics/snapdragon-profiler/default.nix | 2 +- pkgs/tools/networking/gnirehtet/default.nix | 2 +- 5 files changed, 49 insertions(+), 15 deletions(-) diff --git a/pkgs/applications/editors/android-studio/common.nix b/pkgs/applications/editors/android-studio/common.nix index 291a280bdf0f..ac210d20d2f8 100644 --- a/pkgs/applications/editors/android-studio/common.nix +++ b/pkgs/applications/editors/android-studio/common.nix @@ -1,7 +1,7 @@ { channel, pname, version, sha256Hash }: { alsa-lib -, bash +, runtimeShell , buildFHSEnv , cacert , coreutils @@ -214,17 +214,48 @@ let '') ]; }; -in runCommand - drvName - { - startScript = '' - #!${bash}/bin/bash - ${fhsEnv}/bin/${drvName}-fhs-env ${androidStudio}/bin/studio.sh "$@" + mkAndroidStudioWrapper = {androidStudio, androidSdk ? null}: runCommand drvName { + startScript = let + hasAndroidSdk = androidSdk != null; + androidSdkRoot = lib.optionalString hasAndroidSdk "${androidSdk}/libexec/android-sdk"; + in '' + #!${runtimeShell} + ${lib.optionalString hasAndroidSdk '' + echo "=== nixpkgs Android Studio wrapper" >&2 + + # Default ANDROID_SDK_ROOT to the packaged one, if not provided. + ANDROID_SDK_ROOT="''${ANDROID_SDK_ROOT-${androidSdkRoot}}" + + if [ -d "$ANDROID_SDK_ROOT" ]; then + export ANDROID_SDK_ROOT + # Legacy compatibility. + export ANDROID_HOME="$ANDROID_SDK_ROOT" + echo " - ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT" >&2 + + # See if we can export ANDROID_NDK_ROOT too. + ANDROID_NDK_ROOT="$ANDROID_SDK_ROOT/ndk-bundle" + if [ ! -d "$ANDROID_NDK_ROOT" ]; then + ANDROID_NDK_ROOT="$(ls "$ANDROID_SDK_ROOT/ndk/"* 2>/dev/null | head -n1)" + fi + + if [ -d "$ANDROID_NDK_ROOT" ]; then + export ANDROID_NDK_ROOT + echo " - ANDROID_NDK_ROOT=$ANDROID_NDK_ROOT" >&2 + else + unset ANDROID_NDK_ROOT + fi + else + unset ANDROID_SDK_ROOT + unset ANDROID_HOME + fi + ''} + exec ${fhsEnv}/bin/${drvName}-fhs-env ${androidStudio}/bin/studio.sh "$@" ''; preferLocalBuild = true; allowSubstitutes = false; passthru = { unwrapped = androidStudio; + withSdk = androidSdk: mkAndroidStudioWrapper { inherit androidStudio androidSdk; }; }; meta = with lib; { description = "The Official IDE for Android (${channel} channel)"; @@ -261,4 +292,5 @@ in runCommand ln -s ${androidStudio}/bin/studio.png $out/share/pixmaps/${pname}.png ln -s ${desktopItem}/share/applications $out/share/applications - '' + ''; +in mkAndroidStudioWrapper { inherit androidStudio; } diff --git a/pkgs/development/mobile/androidenv/compose-android-packages.nix b/pkgs/development/mobile/androidenv/compose-android-packages.nix index 985ef9a8e23d..72dc64a7e0c2 100644 --- a/pkgs/development/mobile/androidenv/compose-android-packages.nix +++ b/pkgs/development/mobile/androidenv/compose-android-packages.nix @@ -11,8 +11,8 @@ , platformVersions ? [] , includeSources ? false , includeSystemImages ? false -, systemImageTypes ? [ "google_apis_playstore" ] -, abiVersions ? [ "armeabi-v7a" "arm64-v8a" ] +, systemImageTypes ? [ "google_apis" "google_apis_playstore" ] +, abiVersions ? [ "x86" "x86_64" "armeabi-v7a" "arm64-v8a" ] , cmakeVersions ? [ ] , includeNDK ? false , ndkVersion ? "26.3.11579264" diff --git a/pkgs/development/mobile/androidenv/default.nix b/pkgs/development/mobile/androidenv/default.nix index 3de6bf6e478c..6c6f974be706 100644 --- a/pkgs/development/mobile/androidenv/default.nix +++ b/pkgs/development/mobile/androidenv/default.nix @@ -15,9 +15,11 @@ rec { inherit composeAndroidPackages; }; - androidPkgs_9_0 = composeAndroidPackages { - platformVersions = [ "28" ]; - abiVersions = [ "x86" "x86_64"]; + androidPkgs = composeAndroidPackages { + platformVersions = [ "28" "29" "30" "31" "32" "33" "34" ]; + includeEmulator = true; + includeSystemImages = true; + includeNDK = true; }; test-suite = pkgs.callPackage ./test-suite.nix {}; diff --git a/pkgs/tools/graphics/snapdragon-profiler/default.nix b/pkgs/tools/graphics/snapdragon-profiler/default.nix index aa8477d5717d..a4ece4ae1ab2 100644 --- a/pkgs/tools/graphics/snapdragon-profiler/default.nix +++ b/pkgs/tools/graphics/snapdragon-profiler/default.nix @@ -52,7 +52,7 @@ stdenv.mkDerivation rec { cp -r * $out/lib/snapdragon-profiler makeWrapper "${mono}/bin/mono" $out/bin/snapdragon-profiler \ --add-flags "$out/lib/snapdragon-profiler/SnapdragonProfiler.exe" \ - --suffix PATH : ${lib.makeBinPath [ jre androidenv.androidPkgs_9_0.platform-tools coreutils ]} \ + --suffix PATH : ${lib.makeBinPath [ jre androidenv.androidPkgs.platform-tools coreutils ]} \ --prefix MONO_GAC_PREFIX : ${gtk-sharp-2_0} \ --suffix LD_LIBRARY_PATH : $(echo $NIX_LDFLAGS | sed 's/ -L/:/g;s/ -rpath /:/g;s/-rpath //') \ --chdir "$out/lib/snapdragon-profiler" # Fixes themes not loading correctly diff --git a/pkgs/tools/networking/gnirehtet/default.nix b/pkgs/tools/networking/gnirehtet/default.nix index 2281822d2e77..95ef1c7402d9 100644 --- a/pkgs/tools/networking/gnirehtet/default.nix +++ b/pkgs/tools/networking/gnirehtet/default.nix @@ -44,7 +44,7 @@ rustPlatform.buildRustPackage rec { postInstall = '' wrapProgram $out/bin/gnirehtet \ --set GNIREHTET_APK ${apk}/gnirehtet.apk \ - --set ADB ${androidenv.androidPkgs_9_0.platform-tools}/bin/adb + --set ADB ${androidenv.androidPkgs.platform-tools}/bin/adb ''; meta = with lib; { From 2ac0fcce4232bb501ae44c1a741da5f4b586eb90 Mon Sep 17 00:00:00 2001 From: Morgan Jones Date: Mon, 27 May 2024 03:19:29 -0700 Subject: [PATCH 2/5] android-studio: add numinit as maintainer --- pkgs/applications/editors/android-studio/common.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/applications/editors/android-studio/common.nix b/pkgs/applications/editors/android-studio/common.nix index ac210d20d2f8..b47c1ff9b0cd 100644 --- a/pkgs/applications/editors/android-studio/common.nix +++ b/pkgs/applications/editors/android-studio/common.nix @@ -276,9 +276,9 @@ let # source-code itself). platforms = [ "x86_64-linux" ]; maintainers = with maintainers; rec { - stable = [ alapshin ]; - beta = [ alapshin ]; - canary = [ alapshin ]; + stable = [ alapshin numinit ]; + beta = [ alapshin numinit ]; + canary = [ alapshin numinit ]; dev = canary; }."${channel}"; mainProgram = pname; From 859a6056d3311b4292b8585b86d3b35fbe483b9e Mon Sep 17 00:00:00 2001 From: Morgan Jones Date: Mon, 27 May 2024 03:21:50 -0700 Subject: [PATCH 3/5] android-studio-full: init This package provides Android Studio with a relatively complete set of SDK and emulator packages. --- pkgs/applications/editors/android-studio/common.nix | 8 ++++++-- pkgs/top-level/all-packages.nix | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pkgs/applications/editors/android-studio/common.nix b/pkgs/applications/editors/android-studio/common.nix index b47c1ff9b0cd..ca7c4aa1bbdd 100644 --- a/pkgs/applications/editors/android-studio/common.nix +++ b/pkgs/applications/editors/android-studio/common.nix @@ -65,6 +65,7 @@ , zlib , makeDesktopItem , tiling_wm # if we are using a tiling wm, need to set _JAVA_AWT_WM_NONREPARENTING in wrapper +, androidenv }: let @@ -253,9 +254,12 @@ let ''; preferLocalBuild = true; allowSubstitutes = false; - passthru = { - unwrapped = androidStudio; + passthru = let withSdk = androidSdk: mkAndroidStudioWrapper { inherit androidStudio androidSdk; }; + in { + unwrapped = androidStudio; + full = withSdk androidenv.androidPkgs.androidsdk; + inherit withSdk; }; meta = with lib; { description = "The Official IDE for Android (${channel} channel)"; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 84826faa30c9..1ca4c1dd9b46 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -4069,7 +4069,7 @@ with pkgs; adbfs-rootless = callPackage ../development/mobile/adbfs-rootless { }; adb-sync = callPackage ../development/mobile/adb-sync { - inherit (androidenv.androidPkgs_9_0) platform-tools; + inherit (androidenv.androidPkgs) platform-tools; }; amoco = callPackage ../tools/security/amoco { }; @@ -4085,7 +4085,7 @@ with pkgs; androidndkPkgs_23b = (callPackage ../development/androidndk-pkgs {})."23b"; androidndkPkgs_24 = (callPackage ../development/androidndk-pkgs {})."24"; - androidsdk_9_0 = androidenv.androidPkgs_9_0.androidsdk; + androidsdk = androidenv.androidPkgs.androidsdk; webos = recurseIntoAttrs { cmake-modules = callPackage ../development/mobile/webos/cmake-modules.nix { }; @@ -29556,6 +29556,7 @@ with pkgs; androidStudioPackages = recurseIntoAttrs (callPackage ../applications/editors/android-studio { }); android-studio = androidStudioPackages.stable; + android-studio-full = android-studio.full; antfs-cli = callPackage ../applications/misc/antfs-cli { }; From 7f03a67b0b4fa5743f3eccfa3eeaebe68e49b15e Mon Sep 17 00:00:00 2001 From: Morgan Jones Date: Mon, 27 May 2024 19:10:28 -0700 Subject: [PATCH 4/5] {doc/android,release-notes}: update android-studio and androidenv --- doc/languages-frameworks/android.section.md | 122 +++++++++++------- .../manual/release-notes/rl-2405.section.md | 4 + 2 files changed, 77 insertions(+), 49 deletions(-) diff --git a/doc/languages-frameworks/android.section.md b/doc/languages-frameworks/android.section.md index 1c5687f8ebf1..d6ed1f35cb0a 100644 --- a/doc/languages-frameworks/android.section.md +++ b/doc/languages-frameworks/android.section.md @@ -3,10 +3,36 @@ The Android build environment provides three major features and a number of supporting features. +## Using androidenv with Android Studio {#using-androidenv-with-android-studio} + +Use the `android-studio-full` attribute for a very complete Android SDK, including system images: + +```nix +buildInputs = [ android-studio-full ]; +``` + +This is identical to: + +```nix +buildInputs = [ androidStudioPackages.stable.full ]; +``` + +Alternatively, you can pass composeAndroidPackages to the `withSdk` passthru: + +```nix +buildInputs = [ + (android-studio.withSdk (androidenv.composeAndroidPackages { + includeNDK = true; + }).androidsdk) +]; +``` + +These will export ANDROID_SDK_ROOT and ANDROID_NDK_ROOT to the SDK and NDK directories +in the specified Android build environment. + ## Deploying an Android SDK installation with plugins {#deploying-an-android-sdk-installation-with-plugins} -The first use case is deploying the SDK with a desired set of plugins or subsets -of an SDK. +Alternatively, you can deploy the SDK separately with a desired set of plugins, or subsets of an SDK. ```nix with import {}; @@ -145,16 +171,14 @@ androidComposition.platform-tools ## Using predefined Android package compositions {#using-predefined-android-package-compositions} In addition to composing an Android package set manually, it is also possible -to use a predefined composition that contains all basic packages for a specific -Android version, such as version 9.0 (API-level 28). +to use a predefined composition that contains a fairly complete set of Android packages: -The following Nix expression can be used to deploy the entire SDK with all basic -plugins: +The following Nix expression can be used to deploy the entire SDK: ```nix with import {}; -androidenv.androidPkgs_9_0.androidsdk +androidenv.androidPkgs.androidsdk ``` It is also possible to use one plugin only: @@ -162,50 +186,9 @@ It is also possible to use one plugin only: ```nix with import {}; -androidenv.androidPkgs_9_0.platform-tools +androidenv.androidPkgs.platform-tools ``` -## Building an Android application {#building-an-android-application} - -In addition to the SDK, it is also possible to build an Ant-based Android -project and automatically deploy all the Android plugins that a project -requires. - - -```nix -with import {}; - -androidenv.buildApp { - name = "MyAndroidApp"; - src = ./myappsources; - release = true; - - # If release is set to true, you need to specify the following parameters - keyStore = ./keystore; - keyAlias = "myfirstapp"; - keyStorePassword = "mykeystore"; - keyAliasPassword = "myfirstapp"; - - # Any Android SDK parameters that install all the relevant plugins that a - # build requires - platformVersions = [ "24" ]; - - # When we include the NDK, then ndk-build is invoked before Ant gets invoked - includeNDK = true; -} -``` - -Aside from the app-specific build parameters (`name`, `src`, `release` and -keystore parameters), the `buildApp {}` function supports all the function -parameters that the SDK composition function (the function shown in the -previous section) supports. - -This build function is particularly useful when it is desired to use -[Hydra](https://nixos.org/hydra): the Nix-based continuous integration solution -to build Android apps. An Android APK gets exposed as a build product and can be -installed on any Android device with a web browser by navigating to the build -result page. - ## Spawning emulator instances {#spawning-emulator-instances} For testing purposes, it can also be quite convenient to automatically generate @@ -349,3 +332,44 @@ To update the expressions run the `generate.sh` script that is stored in the ```bash ./generate.sh ``` + +## Building an Android application with Ant {#building-an-android-application-with-ant} + +In addition to the SDK, it is also possible to build an Ant-based Android +project and automatically deploy all the Android plugins that a project +requires. Most newer Android projects use Gradle, and this is included for historical +purposes. + +```nix +with import {}; + +androidenv.buildApp { + name = "MyAndroidApp"; + src = ./myappsources; + release = true; + + # If release is set to true, you need to specify the following parameters + keyStore = ./keystore; + keyAlias = "myfirstapp"; + keyStorePassword = "mykeystore"; + keyAliasPassword = "myfirstapp"; + + # Any Android SDK parameters that install all the relevant plugins that a + # build requires + platformVersions = [ "24" ]; + + # When we include the NDK, then ndk-build is invoked before Ant gets invoked + includeNDK = true; +} +``` + +Aside from the app-specific build parameters (`name`, `src`, `release` and +keystore parameters), the `buildApp {}` function supports all the function +parameters that the SDK composition function (the function shown in the +previous section) supports. + +This build function is particularly useful when it is desired to use +[Hydra](https://nixos.org/hydra): the Nix-based continuous integration solution +to build Android apps. An Android APK gets exposed as a build product and can be +installed on any Android device with a web browser by navigating to the build +result page. diff --git a/nixos/doc/manual/release-notes/rl-2405.section.md b/nixos/doc/manual/release-notes/rl-2405.section.md index 072d4d7f779a..f4c5cf05d700 100644 --- a/nixos/doc/manual/release-notes/rl-2405.section.md +++ b/nixos/doc/manual/release-notes/rl-2405.section.md @@ -524,6 +524,10 @@ Use `services.pipewire.extraConfig` or `services.pipewire.configPackages` for Pi - to get previous behaviour of upstream defaults, set it to `null` - default value has changed from `[]` to `null`, in order to preserve default behaviour +- `androidenv.androidPkgs_9_0` has been removed, and replaced with `androidenv.androidPkgs` for a more complete Android SDK including support for Android 9 and later. + +- `gtest` package has been updated past v1.13.0, which requires C++14 or higher. + - `services.vikunja` systemd service now uses `vikunja` as dynamic user instead of `vikunja-api`. Database users might need to be changed. - `services.vikunja.setupNginx` setting has been removed. Users now need to set up the webserver configuration on their own with a proxy pass to the vikunja service. From c1adf2f6c0f59af2502ae5d8ce45cf679193fe17 Mon Sep 17 00:00:00 2001 From: Morgan Jones Date: Mon, 3 Jun 2024 23:03:05 -0700 Subject: [PATCH 5/5] android-studio: add sdk passthru --- pkgs/applications/editors/android-studio/common.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/applications/editors/android-studio/common.nix b/pkgs/applications/editors/android-studio/common.nix index ca7c4aa1bbdd..e18d19ad257f 100644 --- a/pkgs/applications/editors/android-studio/common.nix +++ b/pkgs/applications/editors/android-studio/common.nix @@ -260,6 +260,7 @@ let unwrapped = androidStudio; full = withSdk androidenv.androidPkgs.androidsdk; inherit withSdk; + sdk = androidSdk; }; meta = with lib; { description = "The Official IDE for Android (${channel} channel)";