下载android-sdk:http://tools.android-studio.org/index.php/sdk/
linux:
wget http://dl.google.com/android/android-sdk_r24.4.1-linux.tgz
mac:
wget http://dl.google.com/android/android-sdk_r24.4.1-macosx.zip
windows:
wget http://dl.google.com/android/android-sdk_r24.4.1-windows.zip
解压:
tar xzvf android-sdk_r24.4.1-linux.tgz
设置环境变量:
export ANDROID_HOME=${PWD}/android-sdk-linux
export PATH=${ANDROID_HOME}/tools:${PATH}
export PATH=${ANDROID_HOME}/build-tools/30.0.0-preview:${PATH}
更新SDK:
# 显示当前安装的sdk
android list sdk
# 更新sdk
android update sdk --no-ui
创建一个android工程:
android --verbose create project --name TestApp --activity MainActivity --package com.test --target 21 --path TestApp
生成R.java:
cd TestApp
mkdir gen
aapt package -v -f -S res -J gen -M AndroidManifest.xml -I $ANDROID_HOME/platforms/android-21/android.jar
cat gen/R.java
编译代码:
mkdir obj
javac -verbose -d obj -classpath $ANDROID_HOME/platforms/android-21/android.jar -sourcepath src src/com/test/MainActivity.java gen/R.java
创建 DEX 文件:
Android 系统使用 Dalvik Virtual Machine 来运行字节码。Dalvik 并不认识 .class 格式的字节码,因此,需要把 .class 文件翻译成 Dalvik 可以识别的字节码格式:
dx --dex --verbose --output=bin/classes.dex obj libs
生成 APK 文件:
aapt package -v -f -M AndroidManifest.xml -S res -I $ANDROID_HOME/platforms/android-21/android.jar -F bin/TestApp-unaligned.unsigned.apk bin
给 APK 签名:
mkdir keystores
keytool -v -genkeypair -validity 10000 -dname "CN=company_name,OU=organisational_unit,O=organisation,L=location,S=state,C=country_code" -keystore keystores/testapp.keystore -storepass store_password -keypass key_password -alias key_alias -keyalg RSA
给APK打签名:
jarsigner -verbose -keystore keystores/testapp.keystore -keypass key_password -signedjar bin/TestApp-unaligned.signed.apk bin/TestApp-unaligned.unsigned.apk key_alias
ZIP 对齐:
zipalign -v -f 4 bin/TestApp-unaligned.signed.apk bin/TestApp.apk
#!/bin/bash
ANDROID_HOME=/Users/yangxiaokai/baidu/tmp/android-sdk-linux
export PATH=${ANDROID_HOME}/tools:${PATH}
export PATH=${ANDROID_HOME}/build-tools/30.0.0-preview:${PATH}
PROJECT_NAME=TestApp
# 显示当前安装的sdk
android list sdk
# 更新sdk
android update sdk --no-ui
android --verbose create project --name ${PROJECT_NAME} --activity MainActivity --package com.test --target 21 --path ${PROJECT_NAME}
cd ${PROJECT_NAME}
mkdir gen
aapt package -v -f -S res -J gen -M AndroidManifest.xml -I $ANDROID_HOME/platforms/android-21/android.jar
cat gen/R.java
mkdir obj
javac -verbose -d obj -classpath $ANDROID_HOME/platforms/android-21/android.jar -sourcepath src src/com/test/MainActivity.java gen/R.java
dx --dex --verbose --output=bin/classes.dex obj libs
aapt package -v -f -M AndroidManifest.xml -S res -I $ANDROID_HOME/platforms/android-21/android.jar -F bin/${PROJECT_NAME}-unaligned.unsigned.apk bin
#mkdir keystores
#keytool -v -genkeypair -validity 10000 -dname "CN=company_name,OU=organisational_unit,O=organisation,L=location,S=state,C=country_code" -keystore keystores/testapp.keystore -storepass store_password -keypass key_password -alias key_alias -keyalg RSA
#jarsigner -verbose -keystore keystores/testapp.keystore -keypass key_password -signedjar bin/${PROJECT_NAME}-unaligned.signed.apk bin/${PROJECT_NAME}-unaligned.unsigned.apk key_alias