at 22.05-pre 145 lines 4.6 kB view raw
1{ 2 # If you copy this example out of nixpkgs, use these lines instead of the next. 3 # This example pins nixpkgs: https://nix.dev/tutorials/towards-reproducibility-pinning-nixpkgs.html 4 /*nixpkgsSource ? (builtins.fetchTarball { 5 name = "nixpkgs-20.09"; 6 url = "https://github.com/NixOS/nixpkgs/archive/20.09.tar.gz"; 7 sha256 = "1wg61h4gndm3vcprdcg7rc4s1v3jkm5xd7lw8r2f67w502y94gcy"; 8 }), 9 pkgs ? import nixpkgsSource {}, 10 pkgs_i686 ? import nixpkgsSource { system = "i686-linux"; },*/ 11 12 # If you want to use the in-tree version of nixpkgs: 13 pkgs ? import ../../../../.. {}, 14 pkgs_i686 ? import ../../../../.. { system = "i686-linux"; }, 15 16 config ? pkgs.config 17}: 18 19# Copy this file to your Android project. 20let 21 # Declaration of versions for everything. This is useful since these 22 # versions may be used in multiple places in this Nix expression. 23 android = { 24 versions = { 25 tools = "26.1.1"; 26 platformTools = "31.0.2"; 27 buildTools = "30.0.3"; 28 ndk = [ 29 "22.1.7171670" 30 "21.3.6528147" # LTS NDK 31 ]; 32 cmake = "3.18.1"; 33 emulator = "30.6.3"; 34 }; 35 36 platforms = ["23" "24" "25" "26" "27" "28" "29" "30"]; 37 abis = ["armeabi-v7a" "arm64-v8a"]; 38 extras = ["extras;google;gcm"]; 39 }; 40 41 # If you copy this example out of nixpkgs, something like this will work: 42 /*androidEnvNixpkgs = fetchTarball { 43 name = "androidenv"; 44 url = "https://github.com/NixOS/nixpkgs/archive/<fill me in from Git>.tar.gz"; 45 sha256 = "<fill me in with nix-prefetch-url --unpack>"; 46 }; 47 48 androidEnv = pkgs.callPackage "${androidEnvNixpkgs}/pkgs/development/mobile/androidenv" { 49 inherit config pkgs pkgs_i686; 50 licenseAccepted = true; 51 };*/ 52 53 # Otherwise, just use the in-tree androidenv: 54 androidEnv = pkgs.callPackage ./.. { 55 inherit config pkgs pkgs_i686; 56 licenseAccepted = true; 57 }; 58 59 androidComposition = androidEnv.composeAndroidPackages { 60 toolsVersion = android.versions.tools; 61 platformToolsVersion = android.versions.platformTools; 62 buildToolsVersions = [android.versions.buildTools]; 63 platformVersions = android.platforms; 64 abiVersions = android.abis; 65 66 includeSources = true; 67 includeSystemImages = true; 68 includeEmulator = true; 69 emulatorVersion = android.versions.emulator; 70 71 includeNDK = true; 72 ndkVersions = android.versions.ndk; 73 cmakeVersions = [android.versions.cmake]; 74 75 useGoogleAPIs = true; 76 includeExtras = android.extras; 77 78 # If you want to use a custom repo JSON: 79 # repoJson = ../repo.json; 80 81 # If you want to use custom repo XMLs: 82 /*repoXmls = { 83 packages = [ ../xml/repository2-1.xml ]; 84 images = [ 85 ../xml/android-sys-img2-1.xml 86 ../xml/android-tv-sys-img2-1.xml 87 ../xml/android-wear-sys-img2-1.xml 88 ../xml/android-wear-cn-sys-img2-1.xml 89 ../xml/google_apis-sys-img2-1.xml 90 ../xml/google_apis_playstore-sys-img2-1.xml 91 ]; 92 addons = [ ../xml/addon2-1.xml ]; 93 };*/ 94 95 # Accepting more licenses declaratively: 96 extraLicenses = [ 97 # Already accepted for you with the global accept_license = true or 98 # licenseAccepted = true on androidenv. 99 # "android-sdk-license" 100 101 # These aren't, but are useful for more uncommon setups. 102 "android-sdk-preview-license" 103 "android-googletv-license" 104 "android-sdk-arm-dbt-license" 105 "google-gdk-license" 106 "intel-android-extra-license" 107 "intel-android-sysimage-license" 108 "mips-android-sysimage-license" 109 ]; 110 }; 111 112 androidSdk = androidComposition.androidsdk; 113 platformTools = androidComposition.platform-tools; 114 jdk = pkgs.jdk; 115in 116pkgs.mkShell rec { 117 name = "androidenv-demo"; 118 packages = [ androidSdk platformTools jdk pkgs.android-studio ]; 119 120 LANG = "C.UTF-8"; 121 LC_ALL = "C.UTF-8"; 122 JAVA_HOME = jdk.home; 123 124 # Note: ANDROID_HOME is deprecated. Use ANDROID_SDK_ROOT. 125 ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk"; 126 ANDROID_NDK_ROOT = "${ANDROID_SDK_ROOT}/ndk-bundle"; 127 128 # Ensures that we don't have to use a FHS env by using the nix store's aapt2. 129 GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${ANDROID_SDK_ROOT}/build-tools/${android.versions.buildTools}/aapt2"; 130 131 shellHook = '' 132 # Add cmake to the path. 133 cmake_root="$(echo "$ANDROID_SDK_ROOT/cmake/${android.versions.cmake}"*/)" 134 export PATH="$cmake_root/bin:$PATH" 135 136 # Write out local.properties for Android Studio. 137 cat <<EOF > local.properties 138# This file was automatically generated by nix-shell. 139sdk.dir=$ANDROID_SDK_ROOT 140ndk.dir=$ANDROID_NDK_ROOT 141cmake.dir=$cmake_root 142EOF 143 ''; 144} 145