本文介绍了在Linux下通过命令行打包Android应用的方法,分享给大家,具体如下:
Requirements
- Ubuntu 16.04
- sdk tools for linux
- Java 8
准备环境
安装Shell工具
1
|
sudo apt install -y wget unzip git |
安装JDK
1
2
3
|
sudo apt install -y openjdk-8-jdk # 查看结果 java -version |
初始化目录与环境变量
1
2
3
4
5
6
7
8
9
10
11
12
13
|
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 |
安装SDK工具
1
2
3
4
5
6
7
8
9
10
|
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 |
配置License
1
2
|
mkdir -p $ANDROID_HOME /licenses echo -e "\nd56f5187479451eabf01fb78af6dfcb131a6481e" > $ANDROID_HOME /licenses/android-sdk-license |
下载源码
1
2
3
4
5
6
7
8
9
|
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 |
构建
第一次运行时需要下载依赖项,可能要花很长时间
1
2
3
|
cd $PROJECT_HOME chmod +x gradlew . /gradlew :easy-preference:assembleRelease |
输出
1
|
$OUTPUT_RELEASE_DIR/easy-preference-release.aar |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://www.jianshu.com/p/6402dade94f3