ubuntu下android环境配置
ubuntu下android环境配置一、windows10配置ubuntu linux环境漠天515:windows10配置ubuntu linux环境二、android环境配置1、安装jdk1.82、安装sdk3、安装gradle4、环境变量统一配置5、测试android项目编译,报错的信息我这边把压缩包统一放入/usr/local文件夹下(大家可以自行选择),进行统一环境变量配置1、安装jdk
ubuntu下android环境配置
一、windows10配置ubuntu linux环境
漠天515:windows10配置ubuntu linux环境
二、android环境配置
1、安装jdk1.8
2、安装sdk
3、安装gradle
4、环境变量统一配置
5、测试android项目编译,报错的信息
我这边把压缩包统一放入/usr/local文件夹下(大家可以自行选择),进行统一环境变量配置
1、安装jdk1.8
# 下载linux环境下的jdk:
[jdk-8u271-linux-x64.tar.gz]
下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
# linux安装jdk :
https://blog.csdn.net/pdsu161530247/article/details/81582980
//放到/usr/local目录下
cp jdk-8u271-linux-x64.tar.gz /usr/local
//解压jdk
tar -zxvf jdk-8u181-linux-x64.tar.gz
//顺手删掉jdk源压缩包
rm -f jdk-8u181-linux-x64.tar.gz
# 环境变量配置:(** 结尾有配置完的统一配置 ** )
打开配置环境文件:
# vim /etc/profile ,配置下面的环境变量:
export ANDROID_ROOT=/usr/local
########################### JAVA PATH ##############################
export JAVA_HOME=${ANDROID_ROOT}/jdk1.8.0_271
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
##### PATH #####
export PATH=$PATH:$JAVA_PATH
:wq //保存退出
# 让环境变量立即生效需要执行如下命令:
[root@localhost local]#source /etc/profile
2、安装sdk
【第一种sdk配置】:
[android-sdk_r24.4.1-linux.tgz]
参考:https://qianngchn.github.io/wiki/8.html#%E5%AE%89%E8%A3%85-android-sdk
帖子可能是有些早了,15年的帖子写的很详细,但是ubuntu下配置好后,build编译项目不通过,
sdkmanager和licenses文件没有,所以我这边采用第二种方法实现
(1)android指令不可用:
在配置完sdk的环境变量后,执行:source /etc/profile
就可以使用了
(2)列出sdk:
android list sdk --all
Packages available for installation or update: 235
1- Android SDK Tools, revision 25.2.5 (Obsolete)
2- Android SDK Platform-tools, revision 29.0.6
3- Android SDK Build-tools, revision 30 rc2
4- Android SDK Build-tools, revision 29.0.3
5- Android SDK Build-tools, revision 29.0.2
6- Android SDK Build-tools, revision 29.0.1
7- Android SDK Build-tools, revision 29
8- Android SDK Build-tools, revision 28.0.3
9- Android SDK Build-tools, revision 28.0.2
10- Android SDK Build-tools, revision 28.0.1
11- Android SDK Build-tools, revision 28
12- Android SDK Build-tools, revision 27.0.3
13- Android SDK Build-tools, revision 27.0.2
14- Android SDK Build-tools, revision 27.0.1
15- Android SDK Build-tools, revision 27
16- Android SDK Build-tools, revision 26.0.3
17- Android SDK Build-tools, revision 26.0.2
18- Android SDK Build-tools, revision 26.0.1
19- Android SDK Build-tools, revision 26
20- Android SDK Build-tools, revision 25.0.3
21- Android SDK Build-tools, revision 25.0.2
22- Android SDK Build-tools, revision 25.0.1
23- Android SDK Build-tools, revision 25
24- Android SDK Build-tools, revision 24.0.3
25- Android SDK Build-tools, revision 24.0.2
(3)安装sdk:
//安装25.2.5、29.0.6、30 rc2、29.0.3、29.0.2、
android update sdk -u -a -t 1,2,3,4,5
(4)找不到sdkmanager和licenses not accept
所以采用第二种【***** 也可能是我这边配置的有问题,大家作为参考 *****】
【第二种sdk配置】:
(1)在/usr/local/ 创建linuxAndroidSDK目录,用来放sdk相关的文件
(2)首先下载 commandlinetools-linux-6609375_latest.zip
wget https://dl.google.com/android/repository/commandlinetools-linux-6609375_latest.zip?hl=zh_cn
然后重命名:commandlinetools-linux-6609375_latest.zip去掉?hl=zh_cn便于解压
//进入到linuxAndroidSDK
[root@localhost local]#cd linuxAndroidSDK
//解压,会出现tools文件夹,包括里面的文件,解压完成会出现tools文件夹
[root@localhost local]#unzip commandlinetools-linux-6609375_latest.zip
//删除压缩包
[root@localhost local]#rm commandlinetools-linux-6609375_latest.zip
(3)进入到linuxAndroidSDK/tools 文件夹
****执行sdkmanager一定要加 --sdk_root 要不会报错,下载SDK的相关文件****
[root@localhost local]#bin/sdkmanager "platform-tools" --sdk_root=/usr/local/linuxAndroidSDK
[root@localhost local]#bin/sdkmanager "platforms;android-30" --sdk_root=/usr/local/linuxAndroidSDK
[root@localhost local]#bin/sdkmanager "platform-tools" --sdk_root=/usr/local/linuxAndroidSDK
(4)配置环境变量 (** 结尾有配置完的统一配置 ** )
[root@localhost local]#vi /etc/profile
..........................................................................
export ANDROID_ROOT=/usr/local
########################### ANDROID PATH #####################################
export ANDROID_SKD_HOME=${ANDROID_ROOT}/linuxAndroidSDK
export ANDROID_PATH=${ANDROID_SDK_HOME}/platform-tools:${ANDROID_SDK_HOME}/platforms:${ANDROID_SDK_HOME}/emulator:${ANDROID_ROOT}/tools
##### PATH #####
export PATH=$PATH:$ANDROID_PATH
........................................................................................
让环境变量立即生效需要执行如下命令:
[root@localhost local]#source /etc/profile
3、安装 Gradle
(1)我这边下载gradle最新的文件包
root@USER-4N0CJC555Q:/usr/local#wget https://services.gradle.org/distributions/gradle-6.5-bin.zip
(2)释放到本地Home目录,创建名字为gradle的符号链接,符号连接的好处是方便版本更新,有了新的版本直接修改符号链接即可。
root@USER-4N0CJC555Q:/usr/local#unzip gradle-6.5-all.zip
root@USER-4N0CJC555Q:/usr/local#ln -s gradle-6.5 gradle
(3)配置gradle环境变量并使其生效,编辑 ~/.profile 文件增加下面内容
export ANDROID_ROOT=/usr/local
########################## GRADLE PATH ####################################
export GRADLE_HOME=${ANDROID_ROOT}/gradle-6.5
export GRADLE_PATH=${GRADLE_HOME}/bin
##### PATH #####
export PATH=$PATH:$GRADLE_PATH
(4)保存后使环境变量使其生效
[root@localhost local]#source /etc/profile
(5)环境变量生效后你可以在终端敲入gradle命令并运行用以检测gradle是否安装成功。
gradle
如果安装配置的没有问题将会提示类似下面的信息
:help
Welcome to Gradle 2.12
To run a build, run gradle <task> ...
To see a list of available tasks, run gradle tasks
To see a list of command-line options, run gradle --help
BUILD SUCCESSFUL
4、环境变量统一配置后:
修改profile文件:
[root@localhost local]#vi /etc/profile
..........................................................................
export ANDROID_ROOT=/usr/local
########################### JAVA PATH ##############################
export JAVA_HOME=${ANDROID_ROOT}/jdk1.8.0_271
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
########################### ANDROID PATH #####################################
export ANDROID_SKD_HOME=${ANDROID_ROOT}/linuxAndroidSDK
export ANDROID_PATH=${ANDROID_SDK_HOME}/platform-tools:${ANDROID_SDK_HOME}/platforms:${ANDROID_SDK_HOME}/emulator:${ANDROID_ROOT}/tools
########################## GRADLE PATH ####################################
export GRADLE_HOME=${ANDROID_ROOT}/gradle-6.5
export GRADLE_PATH=${GRADLE_HOME}/bin
##### PATH #####
export PATH=$PATH:$ANDROID_PATH
........................................................................................
让环境变量立即生效需要执行如下命令:
[root@localhost local]#source /etc/profile
5、测试android项目编译,报错的信息
(1) linux下的android项目,需要配置下SDK路径
比如: sdk.dir= /usr/local/linuxAndroidSDK
(2)直接编译
root@USER-4N0CJC555Q:/home/bai/Desktop/LinuxAndroidApp# gradle build
//第一次编译会耗时下载一些初始的东西,耐心等待
root@USER-4N0CJC555Q:/home/bai/Desktop/LinuxAndroidApp# gradle build
File /root/.android/repositories.cfg could not be loaded.
Checking the license for package Android SDK Build-Tools 29.0.2 in /usr/local/linuxAndroidSDK/licenses
License for package Android SDK Build-Tools 29.0.2 accepted.
Preparing "Install Android SDK Build-Tools 29.0.2 (revision: 29.0.2)".
"Install Android SDK Build-Tools 29.0.2 (revision: 29.0.2)" ready.
Installing Android SDK Build-Tools 29.0.2 in /usr/local/linuxAndroidSDK/build-tools/29.0.2
"Install Android SDK Build-Tools 29.0.2 (revision: 29.0.2)" complete.
"Install Android SDK Build-Tools 29.0.2 (revision: 29.0.2)" finished.
Checking the license for package Android SDK Platform 29 in /usr/local/linuxAndroidSDK/licenses
License for package Android SDK Platform 29 accepted.
Preparing "Install Android SDK Platform 29 (revision: 5)".
"Install Android SDK Platform 29 (revision: 5)" ready.
Installing Android SDK Platform 29 in /usr/local/linuxAndroidSDK/platforms/android-29
"Install Android SDK Platform 29 (revision: 5)" complete.
"Install Android SDK Platform 29 (revision: 5)" finished.
> Task :app:lint
Ran lint on variant debug: 3 issues found
Ran lint on variant release: 3 issues found
Wrote HTML report to file:///home/bai/Desktop/LinuxAndroidApp/app/build/reports/lint-results.html
Wrote XML report to file:///home/bai/Desktop/LinuxAndroidApp/app/build/reports/lint-results.xml
BUILD SUCCESSFUL in 11m 45s
60 actionable tasks: 60 executed
编译过程中会下载一些东西,如果报错,那就是android的环境或者项目问题,自己排查
(2)执行gradlew权限不够
[root@localhost local]: ./gradlew
: Permission denied*****
[root@localhost local]# chmod +x gradlew
(3)执行./gradlew会下载gradle-6.5-bin.zip,报错的话:Exception in thread "main" java.util.zip.ZipException: error in opening zip file 下载不完全
### 下载失败,重新下载
查看错误日志中的路径,比如:Unzipping /root/.gradle/wrapper/dists/gradle-6.5-bin/6nifqtx7604sqp1q6g8wikw7p/gradle-6.5-bin.zip
切换管理员权限
xxxxxx@USER-4N0CJC555Q:~$ su root
然后删除/root/.gradle/wrapper/dists/gradle-6.5-bin
[root@localhost local]#rm -rf .gradle/wrapper/dists/gradle-6.5-bin
### 单独下载
再次失败,单独下载:https://services.gradle.org/distributions/gradle-6.5-bin.zip 然后放到固定的路径【/root/.gradle/wrapper/dists/gradle-6.5-bin/6nifqtx7604sqp1q6g8wikw7p】
删除之前下载失败的残留文件:rm -rf .gradle/wrapper/dists/gradle-6.5-bin/6nifqtx7604sqp1q6g8wikw7p/gradle-6.5-bin.zip
把下载的gradle-6.5-bin.zip放入.gradle: cp gradle-6.5-bin.zip /../../../root/.gradle/wrapper/dists/gradle-6.5-bin/6nifqtx7604sqp1q6g8wikw7p/
### 执行./gradlew报错:
: not found2: ./gradlew:
: not found18: ./gradlew:
: not found24: ./gradlew:
./gradlew: 68: ./gradlew: Syntax error: word unexpected (expecting "in")
它只是UNIX和Windows处理行尾字符之间的区别,因此只需键入即可轻松解决,sed -i.bak 's/\r$//' gradlew它将替换回车符。
(使用选项-i,将在原位编辑文件,并将原始文件备份为gradlew.bak)
# sed -i.bak 's/\r$//' gradlew
(4)可以再次执行
[root@localhost local]#./gradlew assembleRelease
更多推荐
所有评论(0)