Method of packaging Android application through command line under Linux

  • 2021-09-16 08:01:52
  • OfStack

This paper introduces the method of packaging Android application through command line under Linux, and shares it with you as follows:

Requirements

Ubuntu 16.04 sdk tools for linux Java 8

Prepare the environment

Installing Shell Tools


sudo apt install -y wget unzip git

Installing JDK


sudo apt install -y openjdk-8-jdk
#  View the results 
java -version

Initialize directory and environment variables


BUILD_BASE=`echo ~`

export ANDROID_HOME=$BUILD_BASE/android_sdk
mkdir -p $ANDROID_HOME

export REPO_BASE=$BUILD_BASE/repo
mkdir -p $REPO_BASE

export REPO_USERNAME=xxx
export REPO_PASSWORD=xxx

export PROJECT_HOME=$REPO_BASE/android-preference
export OUTPUT_RELEASE_DIR=$PROJECT_HOME/easy-preference/build/outputs/aar/release

Installing the SDK tool


cd $ANDROID_HOME

# download
wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip

# unzip
unzip sdk-tools-linux-4333796.zip

# export environment variables
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Configuring License


mkdir -p $ANDROID_HOME/licenses
echo -e "\nd56f5187479451eabf01fb78af6dfcb131a6481e" > $ANDROID_HOME/licenses/android-sdk-license

Download source code


cd $REPO_BASE
# clone
git clone -b develop 
git clone https://$REPO_USERNAME:$REPO_PASSWORD@github.com/hziee514/android-preference.git
# pull
git pull origin develop:develop
# branches
git branch
git checkout -b develop

Build

Dependencies need to be downloaded on the first run, which may take a long time


cd $PROJECT_HOME
chmod +x gradlew
./gradlew :easy-preference:assembleRelease

Output


$OUTPUT_RELEASE_DIR/easy-preference-release.aar

Related articles: