Jenkins Build Android APK手顺以及遇到问题的解决方案


 

Install Gradle

Step 1: download

https://services.gradle.org/distributions/

Step 2: select version 

gradle-3.3-bin.zip

Step 3: upload and unzip

### login Jenkins server

bash-4.1$ cd /var/lib/jenkins

bash-4.1$ scp xxx@xxx:/home/xxx/gradle-3.3-bin.zip .

bash-4.1$ unzip gradle-3.3-bin.zip

Step 4: Jenkins config

Jenkins → manage → Global Tool Configuration → Gradle setting as following:

name : gradle3.3

GRADLE_HOME : /var/lib/jenkins/gradle-3.3

Create Jenkins Build Job

Run Build Job

Error 1: jcenter.bintray.com:443 connection time out

* What went wrong:

A problem occurred configuring root project 'social-depot-mobile-app-release-build'. > Could not resolve all dependencies for configuration ':classpath'. > Could not resolve com.android.tools.build:gradle:2.3.0. Required by: project : > Could not resolve com.android.tools.build:gradle:2.3.0. > Could not get resource 'https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.3.0/gradle-2.3.0.pom'. > Could not GET 'https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.3.0/gradle-2.3.0.pom'. > Connect to repo1.maven.org:443 [repo1.maven.org/151.101.52.209] failed: Connection timed out (Connection timed out) > Could not resolve com.android.tools.build:gradle:2.3.0. > Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/2.3.0/gradle-2.3.0.pom'. > Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/2.3.0/gradle-2.3.0.pom'. > Connect to jcenter.bintray.com:443 [jcenter.bintray.com/75.126.118.188] failed: Connection timed out (Connection timed out) * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED

Error 1 Solution:

Setting proxy for gradle on Jenkins server

bash-4.1$ cd /var/lib/jenkins/.gradle

bash-4.1$ touch gradle.properties

bash-4.1$ vi gradle.properties

systemProp.http.proxyHost=xxxx

systemProp.http.proxyPort=xxxx

systemProp.https.proxyHost=xxxx

systemProp.https.proxyPort=xxxx

gradle.properties (END)

-- save

Error 2: SDK not found 

* What went wrong:

A problem occurred configuring project ':app'.> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

Error 2 Solution:

Install SDK on Jenkins server

Step 1: download

https://developer.android.com/studio/index.html

Step 2: select version 

sdk-tools-linux-3859397.zip

Step 3: upload and unzip

### login jenkins server

bash-4.1$ cd /var/lib/jenkins

bash-4.1$ mkdir android-sdk

bash-4.1$ cd android-sdk

bash-4.1$ scp xxxx@xxxx:/home/xxxx/sdk-tools-linux-3859397.zip .

bash-4.1$ unzip sdk-tools-linux-3859397.zip

bash-4.1$ ls -l

drwxr-xr-x 6 jenkins jenkins 4096 Jan 9 03:35 tools

Step 4: Jenkins config

Jenkins → manage → configure → Global properties → Environment variables as following:

Add Key-Value List

Key : ANDROID_HOME

Value : /var/lib/jenkins/android-sdk

Error 3: Wrong NDK dependency

* What went wrong:

Starting a Gradle Daemon (subsequent builds will be faster)NDK is missing a "platforms" directory.If you are using NDK, verify the ndk.dir is set to a valid NDK directory.  It is currently set to /var/lib/jenkins/android-7.1.1/ndk-bundle.If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.

Error 3 Solution:

Change gradle build plugin version from com.android.tools.build:gradle:2.3.3  to  2.2.2

Reference:https://stackoverflow.com/questions/44730178/getting-warning-ndk-is-missing-a-platforms-directory-with-no-ndk

Error 4: Not accepted license agreements of the SDK

FAILURE: Build failed with an exception. 

* What went wrong:A problem occurred configuring project ':app'.> You have not accepted the license agreements of the following SDK components:  [Android SDK Build-Tools 25, Android SDK Platform 25].  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.  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

Error 4 Solution:

### login Jenkins server

bash-4.1$ cd /var/lib/jenkins/android-sdk/tools

bash-4.1$ bin/sdkmanager --licenses --no_https --proxy=http --proxy_host=proxy --proxy_port=9501

5 of 5 SDK package licenses not accepted.

Review licenses that have not been accepted (y/N)? y

All SDK package licenses accepted

done

Error 5: ConstraintLayout not install

Preparing "Install Solver for ConstraintLayout 1.0.2"."Install Solver for ConstraintLayout 1.0.2" ready.Finishing "Install Solver for ConstraintLayout 1.0.2"Installing Solver for ConstraintLayout 1.0.2 in /var/lib/jenkins/android-sdk/extras/m2repository/com/android/support/constraint/constraint-layout-solver/1.0.2"Install Solver for ConstraintLayout 1.0.2" failed.Preparing "Install ConstraintLayout for Android 1.0.2"."Install ConstraintLayout for Android 1.0.2" ready.Finishing "Install ConstraintLayout for Android 1.0.2"Installing ConstraintLayout for Android 1.0.2 in /var/lib/jenkins/android-sdk/extras/m2repository/com/android/support/constraint/constraint-layout/1.0.2"Install ConstraintLayout for Android 1.0.2" failed.FAILURE: Build failed with an exception.* What went wrong:A problem occurred configuring project ':app'.> Failed to install the following SDK components:  [ConstraintLayout for Android 1.0.2, Solver for ConstraintLayout 1.0.2]  Please install the missing components using the SDK manager in Android Studio.

Error 5 Solution:

### login Jenkins server

bash-4.1$ cd /var/lib/jenkins/android-sdk/tools

bash-4.1$ bin/sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2" --no_https --proxy=http --proxy_host=proxy --proxy_port=9501

done

Error 6: Linux glibc api version not support build tool

:app:mergeDebugResourcesAAPT err(Facade for 340845695): /var/lib/jenkins/android-sdk/build-tools/25.0.0/aapt: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /var/lib/jenkins/android-sdk/build-tools/25.0.0/aapt)AAPT err(Facade for 340845695): /var/lib/jenkins/android-sdk/build-tools/25.0.0/aapt: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /var/lib/jenkins/android-sdk/build-tools/25.0.0/lib64/libc++.so)Exception while processing task java.lang.RuntimeException: AAPT process not ready to receive commandsThread(png-cruncher_2): Broken pipejava.io.IOException: Broken pipeat java.io.FileOutputStream.writeBytes(Native Method)at java.io.FileOutputStream.write(FileOutputStream.java:326)at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:297)at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)at com.android.builder.png.AaptProcess.shutdown(AaptProcess.java:143)at com.android.builder.png.QueuedCruncher$1.destruction(QueuedCruncher.java:144)at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:245)at java.lang.Thread.run(Thread.java:745)AAPT err(Facade for 321808217): /var/lib/jenkins/android-sdk/build-tools/25.0.0/aapt: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /var/lib/jenkins/android-sdk/build-tools/25.0.0/aapt)AAPT err(Facade for 321808217): /var/lib/jenkins/android-sdk/build-tools/25.0.0/aapt: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /var/lib/jenkins/android-sdk/build-tools/25.0.0/lib64/libc++.so)AAPT err(Facade for 1671206652): /var/lib/jenkins/android-sdk/build-tools/25.0.0/aapt: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /var/lib/jenkins/android-sdk/build-tools/25.0.0/aapt)AAPT err(Facade for 2028725799): /var/lib/jenkins/android-sdk/build-tools/25.0.0/aapt: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /var/lib/jenkins/android-sdk/build-tools/25.0.0/aapt)AAPT err(Facade for 2028725799): /var/lib/jenkins/android-sdk/build-tools/25.0.0/aapt: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /var/lib/jenkins/android-sdk/build-tools/25.0.0/lib64/libc++.so)AAPT err(Facade for 1289475567): /var/lib/jenkins/android-sdk/build-tools/25.0.0/aapt: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /var/lib/jenkins/android-sdk/build-tools/25.0.0/aapt)AAPT err(Facade for 1289475567): /var/lib/jenkins/android-sdk/build-tools/25.0.0/aapt: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /var/lib/jenkins/android-sdk/build-tools/25.0.0/lib64/libc++.so)AAPT err(Facade for 1671206652): /var/lib/jenkins/android-sdk/build-tools/25.0.0/aapt: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /var/lib/jenkins/android-sdk/build-tools/25.0.0/lib64/libc++.so)Exception while processing task java.lang.RuntimeException: AAPT process not ready to receive commandsException while processing task java.lang.RuntimeException: AAPT process not ready to receive commandsThread(png-cruncher_1): Broken pipe

Error 6 Solution:

这是因为sdk build tools 25.0.0编译依赖glibc2.14,glibc是linux系统底层api,几乎其它任何运行库都会依赖于glibc。所以如果不是很确定的话,不要轻易更改系统glibc。可以选择升级linux系统,但这显然也不是一个省事儿的办法,那么怎么办呢。

我们可以自己重新编译一个glibc2.14放在其他目录。

Step 1: download 

bash-4.1$ cd /var/lib/jenkins/

bash-4.1$ wget -e "http_proxy=http://proxy:80" http://ftp.gnu.org/gnu/glibc/glibc-2.14.tar.gz

--2018-01-09 14:55:45--  http://ftp.gnu.org/gnu/glibc/glibc-2.14.tar.gzResolving proxy... xxxxConnecting to proxy|xxxx|:9501... connected.Proxy request sent, awaiting response... 200 OKLength: 20897040 (20M) [application/x-gzip]Saving to: “glibc-2.14.tar.gz”100%[==================================================================================================================================================================================================>] 20,897,040  4.80M/s  in 5.4s   2018-01-09 14:55:51 (3.72 MB/s) - “glibc-2.14.tar.gz” saved [20897040/20897040]

Step 2: unzip and install

bash-4.1$ tar zxvf glibc-2.14.tar.gz

bash-4.1$ cd glibc-2.14

bash-4.1$ mkdir build

bash-4.1$ cd build

bash-4.1$ ../configure -prefix=/var/lib/jenkins/glibc/glibc-2.14

bash-4.1$ make -j4      //will take 3mins

bash-4.1$ make install

bash-4.1$ cd /var/lib/jenkins/glibc/glibc-2.14/

bash-4.1$ ls -l

total 28

drwxr-xr-x  2 jenkins jenkins 4096 Jan  9 15:12 bin

drwxr-xr-x  2 jenkins jenkins 4096 Jan  9 15:12 etc

drwxr-xr-x 22 jenkins jenkins 4096 Jan  9 15:12 include

drwxr-xr-x  4 jenkins jenkins 4096 Jan  9 15:12 lib

drwxr-xr-x  3 jenkins jenkins 4096 Jan  9 15:12 libexec

drwxr-xr-x  2 jenkins jenkins 4096 Jan  9 15:12 sbin

drwxr-xr-x  5 jenkins jenkins 4096 Jan  9 15:12 share

Step 3: reset build tool glibc api version setting 

bash-4.1$ cd /var/lib/jenkins/android-sdk/build-tools/25.0.0

bash-4.1$ mv aapt aapt_

bash-4.1$ touch aapt

// Set the environment variable

bash-4.1$ less aapt

#!/bin/sh

echo "$0"_$@

export LD_LIBRARY_PATH=/var/lib/jenkins/glibc/glibc-2.14/lib && "$0"_ $@

aapt (END)

// Change file to be executable

bash-4.1$ chmod +x aapt

╰(*°▽°*)╯Run successfully!!!

APK Download Location

http://xxx/view/app-release-build/job/xxxx-mobile-app-release-build/ws/app/build/outputs/apk/


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 175,490评论 5 419
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 74,060评论 2 335
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 124,407评论 0 291
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 47,741评论 0 248
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 56,543评论 3 329
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 43,040评论 1 246
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 34,107评论 3 358
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 32,646评论 0 229
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 36,694评论 1 271
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 32,398评论 2 279
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 33,987评论 1 288
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 30,097评论 3 285
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 35,298评论 3 282
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 27,278评论 0 14
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 28,413评论 1 232
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 38,397评论 2 309
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 38,099评论 2 314