Merge pull request #315233 from numinit/android-studio-full

android-studio-full: init
This commit is contained in:
Pol Dellaiera 2024-06-16 08:35:21 +02:00 committed by GitHub
commit 4b2ef8f2f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 138 additions and 70 deletions

View File

@ -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 <nixpkgs> {};
@ -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 <nixpkgs> {};
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 <nixpkgs> {};
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 <nixpkgs> {};
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 <nixpkgs> {};
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.

View File

@ -534,6 +534,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.

View File

@ -1,7 +1,7 @@
{ channel, pname, version, sha256Hash }:
{ alsa-lib
, bash
, runtimeShell
, buildFHSEnv
, cacert
, coreutils
@ -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
@ -214,17 +215,52 @@ 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 = {
passthru = let
withSdk = androidSdk: mkAndroidStudioWrapper { inherit androidStudio androidSdk; };
in {
unwrapped = androidStudio;
full = withSdk androidenv.androidPkgs.androidsdk;
inherit withSdk;
sdk = androidSdk;
};
meta = with lib; {
description = "Official IDE for Android (${channel} channel)";
@ -245,9 +281,9 @@ in runCommand
# 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;
@ -261,4 +297,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; }

View File

@ -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"

View File

@ -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 {};

View File

@ -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

View File

@ -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; {

View File

@ -4068,7 +4068,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 { };
@ -4084,7 +4084,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 { };
@ -29515,6 +29515,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 { };