Created
July 24, 2020 01:51
-
-
Save Abdillah/e605e961caf2d6946bcc0e1d23a6199c to your computer and use it in GitHub Desktop.
Building environment of Android app in NixOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
tar -czf ./build/source.tar --exclude='./dev' --exclude='./build' ../appname |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import <nixpkgs> { | |
config.android_sdk.accept_license = true; | |
overlays = [ | |
(self: super: rec { | |
os = if super.stdenv.system == "x86_64-linux" then "linux" | |
else if super.stdenv.system == "x86_64-darwin" then "macosx" | |
else throw "No Android SDK tarballs are available for system architecture: ${super.stdenv.system}"; | |
androidPkgs_base = super.androidenv.composeAndroidPackages { | |
platformVersions = [ "21" "27" ]; | |
platformToolsVersion = "28.0.1"; | |
buildToolsVersions = [ "26.0.2" ]; | |
abiVersions = [ "x86" "x86_64"]; | |
includeEmulator = true; | |
emulatorVersion = "27.3.10"; | |
}; | |
androidPkgs = let | |
# Function that automatically links a plugin for which only one version exists | |
linkPlugin = {name, plugin, check ? true}: | |
super.lib.optionalString check '' | |
for f in $(ls ${plugin}/libexec/android-sdk); do | |
echo "$ PWD=$PWD; ln -snf ${plugin}/libexec/android-sdk/$f ${name};"; | |
ln -snf ${plugin}/libexec/android-sdk/$f ${name}; | |
done; | |
ls -lah . | |
''; | |
fetchurl = super.fetchurl; | |
in rec { | |
patcher = androidPkgs_base.deployAndroidPackage { | |
inherit os; | |
package = { | |
name = "patcher"; | |
path = "patcher/v4"; | |
revision = "1"; | |
displayName = "SDK Patch Applier v4"; | |
archives = { | |
all = fetchurl { | |
url = "https://dl.google.com/android/repository/3534162-studio.sdk-patcher.zip"; | |
sha1 = "046699c5e2716ae11d77e0bad814f7f33fab261e"; | |
}; | |
}; | |
}; | |
}; | |
platform-tools = import <nixpkgs/pkgs/development/mobile/androidenv/platform-tools.nix> { | |
inherit (self) autoPatchelfHook pkgs lib os; | |
inherit (androidPkgs_base) deployAndroidPackage; | |
package = { | |
name = "platform-tools"; | |
path = "platform-tools"; | |
revision = "30.0.3"; | |
displayName = "Android SDK Platform-Tools"; | |
archives = { | |
macosx = fetchurl { | |
url = "https://dl.google.com/android/repository/73f3f0b3034f61563f787bef8ebf51f38df457de.platform-tools_r30.0.3-darwin.zip"; | |
sha1 = "c0ec4b0177e31eab1ef7f7e04c1ab783d71bb12a"; | |
}; | |
linux = fetchurl { | |
url = "https://dl.google.com/android/repository/platform-tools_r30.0.3-linux.zip"; | |
sha1 = "3aa611654e163fae7e3dbd73b5c04e12dfe1e07b"; | |
}; | |
}; | |
}; | |
}; | |
androidsdk = androidPkgs_base.androidsdk.overrideAttrs (oldAttrs: { | |
installPhase = oldAttrs.installPhase + '' | |
${linkPlugin { name = "platform-tools"; plugin = platform-tools; }} | |
${linkPlugin { name = "patcher"; plugin = patcher; }} | |
mkdir -p "$out/libexec/android-sdk/licenses"; | |
echo -e "\n24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$out/libexec/android-sdk/licenses/android-sdk-license"; | |
echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$out/libexec/android-sdk/licenses/android-sdk-preview-license"; | |
''; | |
}); | |
}; | |
}) | |
]; | |
} }: | |
(pkgs.buildFHSUserEnv { | |
name = "android-sdk-env"; | |
targetPkgs = pkgs: (with pkgs; | |
[ | |
jdk | |
androidPkgs.androidsdk | |
glibc | |
]); | |
runScript = "./dev/setup.sh ${pkgs.androidPkgs.androidsdk}/libexec/android-sdk"; | |
}).env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
export ANDROID_HOME=$1 | |
export ANDROID_SDK=/home/user/.config/android | |
export ANDROID_SDK_HOME=/home/user/.config/android | |
/usr/bin/env bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment