背景
本文记录不是安卓Gradle打包,因为我们google play提审,为了规避跟下架包的相似度避免马甲包封号,使用混淆逻辑。
打包环境部署
申请对应虚拟机会有两个账号root和admin,主要避免root账号权限过高造成脚本误操作。这里面问题就是那些步骤需要admin操作,那些是root,因为jenkins配置使用admin账号。
1.安装相关过程中需要用的工具- root 账号
方便直接上传和下载对应的文件
# 安装 lrzsz 和 wget命令
yum -y install lrzsz
yum -y install wget# 安装git
yum install git# 查看git 版本号
[root@bogon admin]# git --version
git version 1.8.3.1# Android 工程打包需要这两个架包
yum install perl-Image-ExifTool
yum install libwebp-tools# 常见md5sum 软连接,jenkinsFile脚本中有使用
[root@bogon admin]# which md5sum
/bin/md5sum
[root@bogon admin]# ln -s /bin/md5sum /usr/local/bin/md5sum# 测试软连接成功
[root@bogon admin]# /usr/local/bin/md5sum --version
md5sum (GNU coreutils) 8.22
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.Written by Ulrich Drepper, Scott Miller, and David Madore.
2.安装python 3.7和对应的python 第三方架包-root账号
研发工程打包脚本有python2和python3两个逻辑,所以机器配置要支持python2.7(系统默认)和python3.7(手工安装)。
-
python3.7以上版本,安装依赖包:libffi-devel
yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
-
下载 python3.7.10源码,然后解压
cd /home/admin
wget https://www.python.org/ftp/python/3.7.10/Python-3.7.10.tgz
tar -xvzf Python-3.7.10.tgz
-
进入到 python3.7.9 目录下编译和配置
cd Python-3.7.10# 创建一个空文件夹,存放python3程序
mkdir /usr/local/python3# 编译安装
./configure --prefix=/usr/local/python3
make && make install# 建立Python3的软连接
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3# 检查Python3和pip3
[root@bogon Python-3.7.10]# python3 --version
Python 3.7.10
[root@bogon Python-3.7.10]# pip3 --version
pip 20.1.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
-
python3.7 安装如下2个python 第三方架包
# 安装第三方架包pip3 install PyYAMLpip3 install protobuf# 查看安装的第三方架包和版本号
[root@bogon android-sdk]# pip3 list
Package Version
---------- -------
pip 20.1.1
protobuf 4.24.1
PyYAML 6.0.1
setuptools 47.1.0
3.上传bundletool.jar和apktools.jar
将这两个架包放置在/home/admin
目录下即可,odin打包脚本会使用这两个jar。
# 修改名称 [admin@bogon ~]$ mv bundletool-all-1.11.2.jar bundletool.jar
注:将本地文件上传的到虚拟服务器的2种方法
-
方法一: 使用scp命令
从本地mac scp 对应的jar 到 虚拟服务器
#上传文件 scp /Users/zhangxuekun/Downloads/bundletool-all-1.11.2.jar admin@10.61.153.58:/home/admin
-
方法二:使用rz命令
使用之前需要在虚拟环境上安装 rz 命令
[root@bogon admin]# yum install lrzsz
然后使用支持rz 和sz 命令的 ssh 程序进行上传。
4.安装 android ndk 架包
[admin@bogon Android_install]$ wget https://dl.google.com/android/repository/android-ndk-r25c-linux.zip?hl=zh-cn
[admin@bogon Android_install]$ unzip android-ndk-r25c-linux.zip -d /home/admin/
5.安装JDK11 和 配置Java环境变量-root账号
-
下载jdk11地址
-
上传jdk 压缩包到虚拟服务器,并解压
[root@bogon admin]# cd /home/admin
[root@bogon admin]# wget https://objects.githubusercontent.com/github-production-release-asset-2e65be/372924883/901544ca-9d19-45c7-b351-cd8c9b0038a2?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230828%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230828T101651Z&X-Amz-Expires=300&X-Amz-Signature=32a249bd1fa1305f16baef12041f5b2fcd961adb886814800a0481563209cf42&X-Amz-SignedHeaders=host&actor_id=75983814&key_id=0&repo_id=372924883&response-content-disposition=attachment%3B%20filename%3DOpenJDK11U-jdk_x64_linux_hotspot_11.0.20_8.tar.gz&response-content-type=application%2Foctet-stream
[root@bogon admin]# tar -zxvf OpenJDK11U-jdk_x64_linux_hotspot_11.0.20_8.tar.gz -C /home/admin
-
配置java环境变量,也可参见centos7下安装java及环境变量配置技巧https://cloud.tencent.com/developer/article/1720948
[root@bogon jdk-11.0.20+8]# cd /home/admin/jdk-11.0.20+8
[root@bogon jdk-11.0.20+8]# vi /etc/profile
[root@bogon jdk-11.0.20+8]# source /etc/profile
[root@bogon jdk-11.0.20+8]# java -version
openjdk version "11.0.20" 2023-07-18
OpenJDK Runtime Environment Temurin-11.0.20+8 (build 11.0.20+8)
OpenJDK 64-Bit Server VM Temurin-11.0.20+8 (build 11.0.20+8, mixed mode)
# 在/etc/profile 文件最后面加上如下内容
export JAVA_HOME=/home/admin/jdk-11.0.20+8
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
注:
查看linux系统是32位还是64位的方法:执行shell命令“arch”,显示为x86_64表示当前系统为64位,显示为i386,i486等表示系统是32位的。
6.安装 android sdk 环境(这个步骤非常重要否则后面本地编译各种报错)-root账号
-
下载cmdline-tools 包https://developer.android.com/studio/
注:不要使用官网的最新版本,跟jdk11不兼容。请下载历史版本
cd /home/admin# 下载cmdline-tools包 历史版本 5.0,最新的版本跟jdk11不兼容
wget https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip[root@bogon admin]# md5sum commandlinetools-linux-7583922_latest.zip
4c2625877503a4b140a6b7ad98b7d5c1 commandlinetools-linux-7583922_latest.zip
-
安装配置
# 解压cmdline-tools包
[root@bogon admin]# cd /home/admin
[root@bogon admin]# mkdir android-sdk
[root@bogon admin]# unzip commandlinetools-linux-7583922_latest.zip -d /home/admin/android-sdk# 查看对应的解压内容
[root@bogon admin]# cd /home/admin/android-sdk
[root@bogon android-sdk]# cd cmdline-tools/
[root@bogon cmdline-tools]# ll
total 128
-rwxr-xr-x 1 root root 120492 Jan 1 2010 NOTICE.txt
drwxr-xr-x 2 root root 146 Aug 22 17:08 bin
drwxr-xr-x 17 root root 4096 Aug 22 17:08 lib
-rwxr-xr-x 1 root root 86 Jan 1 2010 source.properties# 新建一个文件夹/home/admin/android-sdk/cmdline-tools/lastet
[root@bogon cmdline-tools]# cd /home/admin/android-sdk/cmdline-tools
[root@bogon cmdline-tools]# mkdir lastet# 拷贝文件 到 lastet 目录下
[root@bogon cmdline-tools]# mv bin/ lib/ NOTICE.txt source.properties /home/admin/android-sdk/cmdline-tools/lastet/
[root@bogon cmdline-tools]# ll /home/admin/android-sdk/cmdline-tools/lastet
total 100
-rwxr-xr-x 1 root root 92364 Jan 1 2010 NOTICE.txt
drwxr-xr-x 2 root root 122 Aug 22 17:56 bin
drwxr-xr-x 17 root root 4096 Aug 22 17:56 lib
-rwxr-xr-x 1 root root 84 Jan 1 2010 source.properties# 查看所有的platforms-tools
[root@bogon bin]# cd /home/admin/android-sdk/cmdline-tools/lastet/bin
[root@bogon bin]# ./sdkmanager --list --channel=0# 安装 33相关的版本,打包需要使用到
[root@bogon bin]# ./sdkmanager "build-tools;33.0.2" "platforms;android-33" "sources;android-33"# 配置sdkmanager全局变量PATH
[root@bogon jdk-11.0.20+8]# vi /etc/profile
[root@bogon jdk-11.0.20+8]# source /etc/profile# 检查sdkmanager是否安装成功以及对应的版本信息
[root@bogon android-sdk]# sdkmanager --sdk_root=/usr/local/androidSdk/ --version
5.0
[root@bogon bin]# sdkmanager --list --channel=0
# 将如下内容添加到/etc/profile 文件的最后面export SDK_HOME=/home/admin/android-sdk
export PATH=${SDK_HOME}/cmdline-tools/lastet/bin:$PATHexport ANDROID_HOME=/home/admin/android-sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools
admin账号 授权/home/admin/android-sdk/
原因:打包会报错没有改文件操作权限
使用 root账号 输入操作
chown -R admin:admin /home/admin/android-sdk/
7.安装 exiftool库
下载解压完即可, 对应的环境变量会在测试工程对应的jenkinsFile里面中使用
cd /home/admin
git clone https://github.com/exiftool/exiftool.git
cd exiftool
8.内存磁盘的挂载-root账号
因为客户端要做特征,所以所有.class 和类名 都需要改名称,需要大量读写操作。我们目前条件都是统一采用虚拟内存当做磁盘使用
研发打包逻辑里面,有部分路径写死的,所以linux机器挂载路径必须是/home/admin/ramdisk
cd /home/admin
mkdir ramdisk
sudo mount -t tmpfs -o size=16384m tmpfs ramdisk
执行完上面的命令以后,会生成一个绿色的 ramdisk 的文件夹
注:
-
如果机器重新启动了,需要重新挂载执行
mount -t tmpfs -o size=16384m tmpfs ramdisk
-
内存磁盘卸载命令如下:(正常情况下不需要使用)
umount ramdisk
9.配置Git & 拉取工程代码 - admin账号
必须要使用admin账号进行配置和拉取代码,否则后面会因为git权限的问题jenkins构建报错。
10.Git拉取安卓客户端工程
手工创建代码固定放的路径,后续jenkins挂在该节点机器也是这个目录
注:Android代码拉取比较慢,可以继续执行后面的环境部署事项
拉取研发代码
mkdir /home/admin/.jenkins
mkdir /home/admin/.jenkins/workspace
cd /home/admin/.jenkins/workspace# 拉取研发代码
git clone 客户端git地址# check out 指定调试分支,找研发要,后面需要先在机器上手工执行打包
git checkout 分支名# 查看当前分支
git branch
手工创建/home/admin/.jenkins/workspace/android/bloodeye/local.properties
文件
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Tue Aug 22 15:22:27 CST 2023
sdk.dir=/home/admin/android-sdk
ndk.dir=/home/admin/android-ndk-r25sdk.dir=/home/admin/sdk
ndk.dir=/home/admin/sdk/ndk-bundle
11.【重要】打包机器手工执行打包编译
本地手工打包编译成功,说明Android打包环境配置成功
先手工本地执行,确保整个打包编译环境是通畅的,可以编译apk成功。
-
将 /home/admin/.jenkins/workspace/live-me-android/bloodeye 目录拷贝到 /home/admin/ramdisk/目录下
① 打包的时候,需要在 /home/admin/ramdisk/ 内打包,否则打包非常慢。人工手工调试打包需要自己拷贝,正常打包的话, 这个步骤打包脚本来完成
② 拷贝过去的 bloodeye目录,需要确保git 切到了指定的打包分支中。
[root@bogon bloodeye]# cd /home/admin/.jenkins/workspace/android# 确认是否切到了指定的打包分支
[root@bogon live-me-android]# git branchmaster
* nujoom_1.5.90_gp_rb# 拷贝 Android工程下的bloodeye整个目录 到 /home/admin/ramdisk/中
[root@bogon bloodeye]# cd /home/admin/.jenkins/workspace/android/bloodeye
[root@bogon bloodeye]# cp -rf /home/admin/.jenkins/workspace/android/bloodeye /home/admin/ramdisk/[root@bogon bloodeye]# ll /home/admin/ramdisk/
total 0
drwxr-xr-x 45 root root 1560 Aug 22 18:18 bloodeye
-
本地手工打包编译
# 进入到内存挂载磁盘的目录
[root@bogon bloodeye]# cd /home/admin/ramdisk# 执行清理缓存文件
[root@bogon bloodeye]# ./bloodeye/gradlew --no-build-cache -p bloodeye clean# 手工执行打包命令。对应红色标记的字符串,需要问对应研发[root@bogon bloodeye]# ./bloodeye/gradlew --no-build-cache -p bloodeye assemblehertzOuterDebug --stacktrace# 打完包以后,apk存放路径
[root@bogon debug]# pwd
/home/admin/ramdisk/bloodeye/app/build/outputs/apk/hertzOuter/debug
[root@bogon debug]# ll
total 62280
-rw-r--r-- 1 root root 63770147 Aug 22 19:51 bloodeye_1.5.90_15902238_20230822_hertz_outer_debug.apk
-rw-r--r-- 1 root root 432 Aug 22 19:51 output-metadata.json
注:执行 ./bloodeye/gradlew --no-build-cache -p bloodeye clean
命令的结果
执行 ./bloodeye/gradlew --no-build-cache -p bloodeye
assemblehertzOuterDebug
--stacktrace
命令的结果
最后记得把 /home/admin/ramdisk/的所有者赋值给 admin账号
chown -R admin:admin /home/admin/ramdisk/
FQA
1.打包环境部署相关问题
1.1 yum 安装架包报错Failed to set locale, defaulting to C
[root@bogon ~]# yum install -y perl-Image-ExifTool
Failed to set locale, defaulting to C
No package perl-Image-ExifTool available.
Error: Nothing to do
解决方案:
[root@bogon ~]# vi /etc/profile.d/my-custom.lang.sh
[root@bogon ~]# source /etc/profile.d/my-custom.lang.sh
添加内容为:
## US English ##
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_COLLATE=C
export LC_CTYPE=en_US.UTF-8
具体解决方案查看:
https://www.cyberciti.biz/faq/failed-to-set-locale-defaulting-to-c-warning-message-on-centoslinux/
1.2 yum 安装perl-Image-ExifTool 报错
[root@bogon ~]# yum install perl-Image-ExifTool
No package perl-Image-ExifTool available.
Error: Nothing to do
原因:这个错误可能是因为 perl-Image-ExifTool
软件包不在您的软件源中。您可以尝试添加 perl-Image-ExifTool
软件包的软件源并重新安装该软件包。
解决方案:
# 添加软件源
sudo yum install epel-release# 更新软件包列表
sudo yum update# 安装 perl-Image-ExifTool 软件包
sudo yum install perl-Image-ExifTool
1.3 安装python3.7.10 报错
Traceback (most recent call last):File "/home/admin/Android_install/Python-3.7.10/Lib/runpy.py", line 193, in _run_module_as_main"__main__", mod_spec)File "/home/admin/Android_install/Python-3.7.10/Lib/runpy.py", line 85, in _run_codeexec(code, run_globals)File "/home/admin/Android_install/Python-3.7.10/Lib/ensurepip/__main__.py", line 5, in <module>sys.exit(ensurepip._main())File "/home/admin/Android_install/Python-3.7.10/Lib/ensurepip/__init__.py", line 214, in _maindefault_pip=args.default_pip,File "/home/admin/Android_install/Python-3.7.10/Lib/ensurepip/__init__.py", line 127, in _bootstrapreturn _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)File "/home/admin/Android_install/Python-3.7.10/Lib/ensurepip/__init__.py", line 32, in _run_piprunpy.run_module("pip", run_name="__main__", alter_sys=True)File "/home/admin/Android_install/Python-3.7.10/Lib/runpy.py", line 201, in run_modulemod_name, mod_spec, code = _get_module_details(mod_name)File "/home/admin/Android_install/Python-3.7.10/Lib/runpy.py", line 142, in _get_module_detailsreturn _get_module_details(pkg_main_name, error)File "/home/admin/Android_install/Python-3.7.10/Lib/runpy.py", line 109, in _get_module_details__import__(pkg_name)
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1
原因:
zlib1g-dev
是 Debian/Ubuntu 系统上的软件包名称,而在 CentOS/RHEL 系统上,可以使用 yum
包管理器来安装 zlib
库。您可以使用以下命令来安装 zlib
库:
解决方案
[root@bogon Python-3.7.10]# yum install zlib-devel
1.4 安装python3.7 架包报错HTTPSConnectionPool
[root@bogon admin]# pip3 install PyYAML
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pyyaml/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pyyaml/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pyyaml/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pyyaml/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pyyaml/
Could not fetch URL https://pypi.org/simple/pyyaml/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pyyaml/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement PyYAML (from versions: none)
ERROR: No matching distribution found for PyYAML
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
原因:
这个错误通常是由于缺少 SSL 模块导致的。SSL 模块是 Python 中用于处理加密和安全连接的模块,许多 Python 库和工具都依赖于它。
要解决此错误,您需要安装 SSL 模块。您可以使用适当的包管理器来安装 SSL 模块。
解决方案:如果依然报错建议卸载python3 重新安装
yum install openssl-devel
1.5 安装Android sdk环境,检查sdkmanager
是否安装成功时报错
[root@bogon cmdline-tools]# sdkmanager --sdk_root=/usr/local/androidSdk/ --version
Error: LinkageError occurred while loading main class com.android.sdklib.tool.sdkmanager.SdkManagerClijava.lang.UnsupportedClassVersionError: com/android/sdklib/tool/sdkmanager/SdkManagerCli has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
说明JDK的环境太低了,需要升级。说明官网最新的 commandlinetools 跟jdk11不兼容
但是我们打包需要jdk11,jdk18不支持,所以我们只能降低commandlinetools的版本,使用历史版本
比如 https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip
详情查看:ubuntu配置Android编译环境_guo_zhen_qian的博客-CSDN博客
1.6 安装配置Android sdk环境 运行sdkmanager报错
Error: Could not determine SDK root.
Error: Either specify it explicitly with --sdk_root= or move this package into its expected location: <sdk>/cmdline-tools/latest/
解决方案:
# 新建一个文件夹/home/admin/android-sdk/cmdline-tools/lastet
[root@bogon cmdline-tools]# cd /home/admin/android-sdk/cmdline-tools
[root@bogon cmdline-tools]# mkdir lastet# 拷贝文件 到 lastet 目录下
[root@bogon cmdline-tools]# mv bin/ lib/ NOTICE.txt source.properties -t latest/# 查看所有的platforms-tools
[root@bogon bin]# cd /home/admin/android-sdk/cmdline-tools/lastet/bin
[root@bogon bin]# ./sdkmanager --list --channel=0# 安装
[root@bogon bin]# cd /home/admin/android-sdk/cmdline-tools/lastet/bin
[root@bogon bin]# ./sdkmanager "build-tools;33.0.2" "platforms;android-33" "sources;android-33"
1.7 手工清除缓存报错缺少相关Android sdk tools错误
Failed to install the following Android SDK packages as some licences have not been accepted.build-tools;33.0.2 Android SDK Build-Tools 33.0.2platforms;android-33 Android SDK Platform 33
原因:工程里面是33,打包编译环境需要安装33相关的 platforms-tools。如果不太清楚可以报错的时候问研发。
[root@bogon bin]# cd /home/admin/android-sdk/cmdline-tools/lastet/bin
[root@bogon bin]# ./sdkmanager --list --channel=0
[root@bogon bin]# ./sdkmanager "build-tools;33.0.2" "platforms;android-33" "sources;android-33"
安装Android 33相关的 platforms-tools成功,如下截图:
报错详情:
[root@bogon ramdisk]# ./bloodeye/gradlew --no-build-cache -p bloodeye clean --info
...... 省略部分内容
The build will continue, but you are strongly encouraged to update your project to
use a newer Android Gradle Plugin that has been tested with compileSdk = 33
Parsing legacy package: /home/admin/android-sdk/cmdline-tools
Parsing legacy package: /home/admin/android-sdk/cmdline-tools
Checking the license for package Android SDK Build-Tools 33.0.2 in /home/admin/android-sdk/licenses
Warning: License for package Android SDK Build-Tools 33.0.2 not accepted.
Checking the license for package Android SDK Platform 33 in /home/admin/android-sdk/licenses
Warning: License for package Android SDK Platform 33 not accepted.FAILURE: Build failed with an exception.* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:huaweiOuterDebugRuntimeClasspath'.> Could not create task ':app:minifyHertzInnerReleaseWithR8'.> Failed to install the following Android SDK packages as some licences have not been accepted.build-tools;33.0.2 Android SDK Build-Tools 33.0.2platforms;android-33 Android SDK Platform 33To 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.htmlUsing Android SDK: /home/admin/android-sdk* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.* Get more help at https://help.gradle.orgDeprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.See https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warningsBUILD FAILED in 1s
1.8 手工清除缓存报错缺少ANDROID_SDK_ROOT环境变量
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 '/home/admin/ramdisk/bloodeye/local
原因:没有配置 ANDROID_SDK_ROOT环境变量
# 执行命令
[root@localhost admin]# cd /home/admin/jdk-11.0.20+8
[root@bogon jdk-11.0.20+8]# vi /etc/profile
[root@bogon jdk-11.0.20+8]# source /etc/profile
# 添加如下内容到/etc/profile文件中
export ANDROID_HOME=/home/admin/android-sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools
检查是否手工创建 /home/admin/.jenkins/workspace/live-me-android/bloodeye/local.properties
[admin@localhost bloodeye]$ touch local.properties
[admin@localhost bloodeye]$ vi local.properties
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Tue Aug 22 15:22:27 CST 2023
sdk.dir=/home/admin/android-sdk
ndk.dir=/home/admin/android-ndk-r25c
报错详情:
[root@bogon ramdisk]# ./bloodeye/gradlew --no-build-cache -p bloodeye clean
.... 省略部分内容
FAILURE: Build failed with an exception.* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:huaweiOuterDebugRuntimeClasspath'.> Could not create task ':app:minifyHertzInnerReleaseWithR8'.> 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 '/home/admin/ramdisk/bloodeye/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.orgDeprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.See https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warningsBUILD FAILED in 1s
1.9 报错报错 "The SDK directory is not writable (/home/admin/android-sdk)"
解决办法:
root账号登录 授权admin账号
1.10 手工清除缓存报错:/home/admin/ramdisk/bloodeye/local.properties (No such file or directory)
因为是手工执行,所以需要自己手工创建对应的文件。
[root@bogon bloodeye]# cd /home/admin/ramdisk/bloodeye
[root@bogon bloodeye]# touch /home/admin/ramdisk/bloodeye/local.properties
文件内容如下:
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Tue Aug 22 15:22:27 CST 2023
sdk.dir=/home/admin/android-sdk
ndk.dir=/home/admin/android-ndk-r25c
报错详情:
[root@bogon ramdisk]# ./bloodeye/gradlew --no-build-cache -p bloodeye clean
.... 省略部分内容
> Configure project :livemesdk
livemesdk
WARNING:Using flatDir should be avoided because it doesn't support any meta-data formats.
WARNING:Using flatDir2 should be avoided because it doesn't support any meta-data formats.
WARNING:Software Components will not be created automatically for Maven publishing from Android Gradle Plugin 8.0. To opt-in to the future behavior, set the Gradle property android.disableAutomaticComponentCreation=true in the `gradle.properties` file or use the new publishing DSL.FAILURE: Build failed with an exception.* Where:
Script '/home/admin/ramdisk/bloodeye/upload_aar_publish.gradle' line: 161* What went wrong:
A problem occurred evaluating script.
> /home/admin/ramdisk/bloodeye/local.properties (No such file or directory)* 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.orgDeprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.See https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warningsBUILD FAILED in 7s
1.11 清理缓存时打包时有正在进行中的任务It is currently in use by another Gradle instance
-
报错详情:
[admin@localhost ramdisk]$ ./bloodeye/gradlew --no-build-cache -p bloodeye cleanFAILURE: Build failed with an exception.What went wrong:
Gradle could not start your build.
Cannot create service of type BuildTreeActionExecutor using method LauncherServices$ToolingBuildTreeScopeServices.createActionExecutor() as there is a problem with parameter #1 of type List<BuildActionRunner>.
Could not create service of type FileAccessTimeJournal using GradleUserHomeScopeServices.createFileAccessTimeJournal().> Timeout waiting to lock journal cache (/home/admin/.gradle/caches/journal-1). It is currently in use by another Gradle instance.Owner PID: 10592Our PID: 31761Owner Operation: Our operation: Lock file: /home/admin/.gradle/caches/journal-1/journal-1.lockTry:
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
-
排查原因:
先查看其他正在进行中的的任务,获取任务ID
[admin@localhost ramdisk]$ ps -ef | grep gradle
-
解决办法:
确认有其他正在执行的任务,杀掉进程;如果有多个正在进行的任务,需要全部杀掉之后重新执行清缓存命令
[admin@localhost ramdisk]$ kill -9 16459
[admin@localhost ramdisk]$ ./bloodeye/gradlew --no-build-cache -p bloodeye clean
1.12 打包虚拟机本地打包时报错:Task :livemesdk:compileChasexOuterReleaseJavaWithJavac FAILED
-
报错详情:
warning: unknown enum constant Mode.LOCAL
/home/admin/ramdisk/bloodeye/livemesdk/src/main/java/com/app/live/activity/UpLiveActivity.java:4189: error: cannot find symbolif (!LMScreenRecordService.bind(this, conn, R.drawable.notification_logo, name, content, true)) {^symbol: variable LMScreenRecordServicelocation: class UpLiveActivity
/home/admin/ramdisk/bloodeye/livemesdk/src/main/java/com/app/live/activity/UpLiveActivity.java:4202: error: cannot find symbolLMScreenRecordService.unbind(this, mRecordConnection);^symbol: variable LMScreenRecordServicelocation: class UpLiveActivity
warning: unknown enum constant Mode.LOCAL
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors
24 warnings
> Task :livemesdk:compileChasexOuterReleaseJavaWithJavac FAILED
FAILURE: Build failed with an exception.
-
排查办法:
① 打包虚拟机上检查代码中引用正常
② 打包虚拟机上手工下载包是正常的
③ 打包虚拟机上Gradle 缓存中程序下载正常
④ 检查git发版分支与最新的分支对比,检查对应报错引用的第三方架包版本是否一致(因为客户端代码在中间有更新,所以对应第三方架包做了版本号的升级)
-
解决办法:更正版本号与其他分支保持一致
1.13 打包虚拟机本地打包时报错:No space left on devices
-
报错详情:
-
原因:
/home/admin/ramdisk的磁盘空间,磁盘空间不足,导致打包失败
-
排查办法:
① 检查/home/admin/ramdisk的磁盘空间,发现磁盘空间异常
[admin@localhost ramdisk]$cd /home/admin/ramdisk
[admin@localhost ramdisk]$df -h #查看磁盘大小
② 检查/home/admin/.jenkins/workspace/live-me-android目录下bloodeye文件夹的大小,文件大小16G仍异常
[root@localhost live-me-android]# cd /home/admin/.jenkins/workspace/live-me-android
[root@localhost live-me-android]# du -sh bloodeye
③ 检查本地工程代码中bloodeye文件夹的大小,6.05G没有异常
④ 可以确定是虚拟机上的工程上的bloodeye文件夹大小异常(推断原因:可能是研发为了排查打包问题,在对应的本地文件夹中进行了打包编译,所以导致bloodeye文件夹变大,然后我们copy 到了 /home/admin/ramdisk 文件夹中)。解决方案:删除工程代码和挂载文件夹,重新拉取代码及创建挂载文件;再次检查工程文件大小
[root@localhost live-me-android]# cd /home/admin/.jenkins/workspace/live-me-android
[root@localhost live-me-android]# du -sh bloodeye
1.6G bloodeye
1.14 odin打包失败,提示错误:[BT:1.11.2] Error: File '/home/admin/ramdisk/bloodeye/autoBuild/tools/chasex.keystore' was not found.
报错详情
-
排查办法:
检查/Users/odin/script/Jenkinsfiles/android-chasex/Jenkinsfile 文件中keystroe 需要与研发给的keystroe一致(有时可以叫xx.key ,有时叫xx.keystroe)