DevOps&CI CD

Jenkins Build Android APK手顺以及遇到问

2018-01-30  本文已影响0人  小蘑菇的后花园简书


 

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/

上一篇下一篇

猜你喜欢

热点阅读