Ubuntu环境使用Gradle编译打包APK

Ubuntu环境使用Gradle编译打包APK

参考:

1,Prepare

  • gradle:
不需要单独下载,在某个项目中执行./gradlew会下载项目需要的gradle版本,最终会下载到.gradle/dist/下面,根据ZT Android APP环境规范,下载3.3-all即可。
  • JDK:单独安装Java7
apt-get install openjdk-7-jdk
  • 安装JAVA 8
下载
scp -P 10622 jdk-8u131-linux-x64.tar.gz xugangfeng@aly.zerotech.top:~/misc/
  • android-sdk:
新的sdk都是打包在android studio工具里面,但我们又不需要。我们可以先通过下载一个老的版本sdk,然后通过这个sdk里面的工具android命令下载新的sdk版本和build tools。
 tar xf android-sdk_r24.4.1-linux.tgz
完成之后,就可以使用android命令了
列出远程可以下载的sdk和tools版本
android list sdk –all
  1. 9- Android SDK Build-tools, revision 24.0.2
  2. 10- Android SDK Build-tools, revision 24.0.1
  3. ...
  4. 37- SDK Platform Android 7.0, API 24, revision 2
  5. 38- SDK Platform Android 6.0, API 23, revision 3
  6. 39- SDK Platform Android 5.1.1, API 22, revision 2
  7. 40- SDK Platform Android 5.0.1, API 21, revision 2
下载对应平台的,我下载build-tools 24.0.2和 sdk版本为22.
android update sdk -a -u -t 1,2,6,7,36,42,37
  • 更新环境变量
  1. #android sdk
  2. ANDROID_HOME=/home/andbase/workspace/misc/android-sdk-linux
  3. export ANDROID_HOME
  4. GRADLE_HOME=/home/andbase/.gradle/wrapper/dists/gradle-3.3-all/55gk2rcmfc6p2dg9u9ohc3hw9/gradle-3.3/
  5. export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$GRADLE_HOME/bin

2,Ready Go

  • 进入项目目录,Gradle版本确认,确认gradle版本为3.3
  1. andbase@vm-10-142-132-78:ZerotechDemo$ ./gradlew -v
  2. ------------------------------------------------------------
  3. Gradle 3.3
  4. ------------------------------------------------------------
  5. Build time: 2017-01-03 15:31:04 UTC
  6. Revision: 075893a3d0798c0c1f322899b41ceca82e4e134b
  7. Groovy: 2.4.7
  8. Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
  9. JVM: 1.7.0_85 (Oracle Corporation 24.85-b03)
  10. OS: Linux 3.16.0-30-generic amd64
  • 配置好java
根据sdk版本,选择java, update-alternatives –config java/javac
  • 设置Liecense
如果不设置,否则会有这样的错误
  1. * What went wrong:
  2. A problem occurred configuring project ':app'.
  3. > You have not accepted the license agreements of the following SDK components:
  4. [Android SDK Platform-Tools].
  5. Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
  6. Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html
android list sdk –all   列出当前的platform-tools
2- Android SDK Platform-tools, revision 26
android update sdk -a -u -t 1,2
November 20, 2015
Do you accept the license ‘android-sdk-license-c81a61d9′ [y/n]: y
另外,外部依赖包constraint-layout需要使用sdkmanager命令来添加License确认
sdkmanager “extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.2″
  • lint检查错误

在编译脚本文件app/build.gradle中的android切点添加参数

    lintOptions {
        abortOnError false
    }
同时也可以使用assembleDebug的task,忽略Lint的检查
  • 开始编译
不进行Lint检查:
gradle –daemon  assembleDebug

3,TroubleShooting

TBD
Comments are closed.
TOP