Jenkins Build Android APK手順以及遇到問(wèn)題的解決方案


?

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:

這是因?yàn)閟dk build tools 25.0.0編譯依賴glibc2.14如庭,glibc是linux系統(tǒng)底層api末秃,幾乎其它任何運(yùn)行庫(kù)都會(huì)依賴于glibc哗总。所以如果不是很確定的話花吟,不要輕易更改系統(tǒng)glibc懒震≈菏可以選擇升級(jí)linux系統(tǒng)燥爷,但這顯然也不是一個(gè)省事兒的辦法惠窄,那么怎么辦呢喇闸。

我們可以自己重新編譯一個(gè)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/


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末询件,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子唆樊,更是在濱河造成了極大的恐慌宛琅,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,123評(píng)論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件逗旁,死亡現(xiàn)場(chǎng)離奇詭異嘿辟,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)片效,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,031評(píng)論 2 384
  • 文/潘曉璐 我一進(jìn)店門(mén)红伦,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人淀衣,你說(shuō)我怎么就攤上這事昙读。” “怎么了膨桥?”我有些...
    開(kāi)封第一講書(shū)人閱讀 156,723評(píng)論 0 345
  • 文/不壞的土叔 我叫張陵蛮浑,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我只嚣,道長(zhǎng)沮稚,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,357評(píng)論 1 283
  • 正文 為了忘掉前任册舞,我火速辦了婚禮蕴掏,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘调鲸。我一直安慰自己盛杰,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,412評(píng)論 5 384
  • 文/花漫 我一把揭開(kāi)白布线得。 她就那樣靜靜地躺著饶唤,像睡著了一般。 火紅的嫁衣襯著肌膚如雪贯钩。 梳的紋絲不亂的頭發(fā)上募狂,一...
    開(kāi)封第一講書(shū)人閱讀 49,760評(píng)論 1 289
  • 那天,我揣著相機(jī)與錄音角雷,去河邊找鬼祸穷。 笑死,一個(gè)胖子當(dāng)著我的面吹牛勺三,可吹牛的內(nèi)容都是我干的雷滚。 我是一名探鬼主播,決...
    沈念sama閱讀 38,904評(píng)論 3 405
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼吗坚,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼祈远!你這毒婦竟也來(lái)了呆万?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 37,672評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤车份,失蹤者是張志新(化名)和其女友劉穎谋减,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體扫沼,經(jīng)...
    沈念sama閱讀 44,118評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡出爹,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,456評(píng)論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了缎除。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片严就。...
    茶點(diǎn)故事閱讀 38,599評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖器罐,靈堂內(nèi)的尸體忽然破棺而出梢为,到底是詐尸還是另有隱情,我是刑警寧澤技矮,帶...
    沈念sama閱讀 34,264評(píng)論 4 328
  • 正文 年R本政府宣布抖誉,位于F島的核電站殊轴,受9級(jí)特大地震影響衰倦,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜旁理,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,857評(píng)論 3 312
  • 文/蒙蒙 一樊零、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧孽文,春花似錦驻襟、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,731評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至减牺,卻和暖如春豌习,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背拔疚。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,956評(píng)論 1 264
  • 我被黑心中介騙來(lái)泰國(guó)打工肥隆, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人稚失。 一個(gè)月前我還...
    沈念sama閱讀 46,286評(píng)論 2 360
  • 正文 我出身青樓栋艳,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親句各。 傳聞我的和親對(duì)象是個(gè)殘疾皇子吸占,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,465評(píng)論 2 348