linux安装gradle环境编译android项目

下载gradle包

wget https://services.gradle.org/distributions/gradle-5.4.1-all.zip

下载android-sdk

wget https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz

  • 解释一下android-sdk的版本,不知道为什么android只提供到这个版本的SDK,如果需要目标版本需要安装后去更新

分别解压

unzip gradle-5.4.1-all.zip

tar xvzf android-sdk_r24.4.1-linux.tgz

进入解压后的android-sdk-linux/tools目录

输入./android update sdk --no-ui

同意开始更新

配置环境变量:

vim /etc/profile

export PATH=/yourpath/gradle-5.4.1/bin:$PATH

export PATH=/yourpath/android-sdk-linux/tools:$PATH

上传android项目工程

在工程根目录进行出包测试:assembleRelease

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileReleaseJavaWithJavac'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/data/SJSDK-For-H5/BasePackage/BridgeTest/local.properties'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings

SDK location not found,修改local.properties中的sdk指向

重新测试

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileReleaseJavaWithJavac'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
 build-tools;28.0.3 Android SDK Build-Tools 28.0.3
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

Using Android SDK: /root/download/android-sdk-linux

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 9s

Build-Tools 28.0.3没有license

执行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 rc1
   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

可以看出匹配的是 8

执行 android update sdk -u -a -t 8 询问时输入 “y” 并耐心等待

January 16, 2019
Do you accept the license 'android-sdk-license-e6a904e8' [y/n]: y

Installing Archives:
  Preparing to install archives
  Downloading Android SDK Build-tools, revision 28.0.3
  Installing Android SDK Build-tools, revision 28.0.3
    Installed Android SDK Build-tools, revision 28.0.399%)
  Done. 1 package installed.

再次尝试,如果报错再重复以上操作

Observed package id 'build-tools;30.0.0-rc1' in inconsistent location '/root/download/android-sdk-linux/build-tools/30.0.0-preview' (Expected '/root/download/android-sdk-linux/build-tools/30.0.0-rc1')

看样子是没有30.0.0-rc1,去到我们的目录底下看,果然只有30.0.0-preview

android update sdk -u -a -t 3

没有出现30.0.0-rc1

重新编译之后是可以的


关注我的公众号(不是技术号),让你的职业发展除技术外,多一种可能

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值