下载地址
安装步骤 安装shell工具sudo apt install -y wget unzip git
安装JDK
sudo apt install -y openjdk-8-jdk
# 查看结果
java -version
初始化目录与环境变量
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
# set java environment
export JAVA_HOME=/home/william/下载/jdk-8u181-linux-x64/jdk1.8.0_181
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
# set gradle environment
export GRADLE_HOME=/home/william/.gradle/wrapper/dists/gradle-4.6-all/bcst21l2brirad8k2ben1letg/gradle-4.6
export PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin:${GRADLE_HOME}/bin:${JAVA_HOME}:${PATH}
# set groovy environment
export GROOVY_HOME="/home/william/公共的/apache-groovy-sdk-2.5.3/groovy-2.5.3"
export PATH=$GROOVY_HOME/bin:$PATH
# set androd sdk environment
export ANDROID_SDK=/home/hwilliamgo/Android/Sdk
export PATH=$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$PATH
# set android ndk environment
export ANDROID_SDK=/home/hwilliamgo/Android/Sdk
export PATH=$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$PATH
或 sudo gedit /etc/profile
安装SDK工具
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
$ android //验证配置是否成功
gradle下载
博客
android ndk 安装下载地址
下载后复制到Linux下的目录下,直接unzip android-ndk-r17b-linux-x86_64.zip来解压。
Linux命令行下输入vi /etc/profile
在文件末尾添加如下内容:
#android NDK
export ANDROID_NDK="/home/fanx/ANDROID_NDK/android-ndk-r17b"
export PATH="$ANDROID_NDK:$PATH"
$ ndk-build -v //检测
wget https://services.gradle.org/distributions/gradle-4.10.2-bin.zip -P /tmp
## 配置License
mkdir -p $ANDROID_HOME/licenses
echo -e “\nd56f5187479451eabf01fb78af6dfcb131a6481e” > $ANDROID_HOME/licenses/android-sdk-license
## 下载源码
cd $REPO_BASE
clonegit clone -b develop
git clone https://REPOUSERNAME:REPO_USERNAME:REPOUSERNAME:REPO_PASSWORD@github.com/hziee514/android-preference.git
git pull origin develop:develop
branchesgit branch
git checkout -b develop
``
gradle wrapper --gradle-version 2.13// 版本号改成自己的版本号 生成 build.sh文件
chmod +x gradlew
./gradlew build 执行
问题一
ubuntu下运行android程序的时候总是报错,错误信息如下:
Error:Execution failed for task ‘:compileDebugAidl’.
java.lang.RuntimeException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘/home/zrp/software/android/android-sdk-linux/build-tools/23.0.1/aidl’’ finished with non-zero exit value 127
gradle console中的错误信息:
build-tools/23.0.1/aidl: error while loading shared libraries: libgcc_s.so.1: cannot open shared object file: No such file or directory
google找到一篇文章:http://askubuntu.com/questions/409905/apt-get-error-loading-libgcc-s-so-1
解决方式:sudo apt-get install gcc-multilib,即可编译通过。
但是按照如上步骤解决编译问题之后,运行安装包的时候出现了另一个问题:
Exception in thread “png-cruncher_18” java.lang.RuntimeException: Timed out while waiting for slave aapt process, make sure the aapt execute at /home/zrp/software/android/android-sdk-linux/build-tools/23.0.1/aapt can run successfully (some anti-virus may block it) or try setting environment variable SLAVE_AAPT_TIMEOUT to a value bigger than 5 seconds
at com.android.builder.png.AaptProcess.waitForReady(AaptProcess.java:108)
at com.android.builder.png.QueuedCruncher$1.creation(QueuedCruncher.java:110)
at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:203)
at java.lang.Thread.run(Thread.java:745)
问题描述及解决链接:https://code.google.com/p/android/issues/detail?id=188627
问题二
FAILURE: Build failed with an exception.
Execution failed for task ‘:compileDebugJavaWithJavac’.
Unexpected lock protocol found in lock file. Expected 3, found 0.
Try:Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
解决方式:http://stackoverflow.com/questions/31743942/errorunexpected-lock-protocol-found-in-lock-file-expected-3-found-0
删除项目文件夹下的.gradle文件夹并重新编译即可。
问题三
ubuntu下连接手机的时候报错:insufficient permissions for device,就是手机连接到电脑之后adb一直显示null,无法进行软件安装等。
找到如下解决方式:http://itsfoss.com/fix-error-insufficient-permissions-device/
解决办法如下:
adb kill-server
sudo adb start-server
敲完如上命令之后,手机上会弹出确认adb调试的弹框,确认连接即可。
问题四
ubuntu下安装android studio之后,studio无法关联源码,经过多方搜索,最终找到了奇葩的问题原因:SDK的文件夹名称中包含-字符或者路径名过长!修改文件夹名称之后关联到了源码
作者:Piston_zg