Last active
February 17, 2023 12:39
-
-
Save itzurabhi/48ff574757404380d3c49eebbe1eed3c to your computer and use it in GitHub Desktop.
This file contains 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> {} }: | |
with pkgs; | |
let | |
# Define the required packages | |
androidSdk = androidsdk; | |
androidNdk = androidndk; | |
openjdk = adoptopenjdk11; | |
buildToolsVersion = "30.0.3"; | |
# Define the environment variables required by the Android SDK and NDK | |
androidSdkEnv = { | |
ANDROID_HOME = "${androidSdk}/share/android-sdk"; | |
ANDROID_NDK_HOME = "${androidNdk}/share/android-ndk"; | |
}; | |
in | |
mkShell { | |
# Specify the required inputs | |
buildInputs = [ | |
androidSdk | |
androidNdk | |
openjdk | |
git | |
wget | |
unzip | |
zipalign | |
apksigner | |
]; | |
# Set the required environment variables and accept the Android SDK licenses | |
shellHook = '' | |
export ${androidSdkEnv.ANDROID_HOME} | |
export ${androidSdkEnv.ANDROID_NDK_HOME} | |
yes | ${androidSdk}/bin/sdkmanager --licenses | |
''; | |
# Define a function to build the APK from source | |
buildApk = packageName: { | |
# Clone the project from Git | |
git clone https://github.com/user/project.git | |
cd project | |
# Download and extract the required dependencies | |
wget https://downloads.gradle-dn.com/distributions/gradle-7.2-bin.zip | |
unzip gradle-7.2-bin.zip | |
# Build the APK | |
${androidSdk}/bin/sdkmanager --update | |
${androidSdk}/bin/sdkmanager "platform-tools" "build-tools;${buildToolsVersion}" | |
${androidSdk}/bin/sdkmanager "platforms;android-30" | |
export PATH=$PWD/gradle-7.2/bin:$PATH | |
./gradlew assembleRelease | |
# Sign the APK | |
apksigner sign --ks /path/to/keystore --ks-key-alias mykey --out app-release-signed.apk app-release-unsigned.apk | |
# Align the APK | |
zipalign -v 4 app-release-signed.apk app-release-aligned.apk | |
# Clean up | |
rm app-release-unsigned.apk | |
rm app-release-signed.apk | |
}; | |
# Build the APK for the specified package name | |
buildApk "com.example.app"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment