Centos部署Android自动打包

注意事项

  • 服务器内存1G+, 编译Android占内存比较多,512M容易打满
  • Android SDK的下载路径都在google域名下,不确定是否能正常访问,亲测腾讯云可以。

安装Java环境

# 查看可用的jdk版本
yum search java|grep jdk

# 注意区分OpenJDK Development Environment(JDK) 和 OpenJDK Runtime Environment(JRE), 编译Android选择 JDK

# 安装jdk, 会自动配置环境变量
yum install java-1.8.0-openjdk-devel.i686

# 检测是否安装成功
java、javac、java -version  

安装Jenkins

sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo  
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key  
yum install jenkins

# 启动 jenkins
sudo systemctl start jenkins.service  
sudo systemctl enable jenkins.service

# 可以访问了
http://<your-server-IP>:8080  

配置码云自动部署

使用Generic Webhook Trigger插件实现Jenkins+WebHooks(码云)持续集成

设置nginx代理 (非必须)

server {  
    listen 80;
    server_name jenkins.xxxxxxx.com;

    location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_pass         http://127.0.0.1:8080;
    }
}

下载Android SDK、NDK

# 创建一个android-sdk目录,下载tools文件夹
curl -OL https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip

# 下载NDK
curl -OL https://dl.google.com/android/repository/android-ndk-r16-linux-x86_64.zip

如果项目包含了JNI需要下载cmake Install CMake

wget https://github.com/Commit451/android-cmake-installer/releases/download/1.1.0/install-cmake.sh  
chmod +x install-cmake.sh  
./install-cmake.sh

需要配置ANDROID_HOME环境变量,推荐下载3.6.4111459版本, 默认是3.6.3155560

./install-cmake.sh -v 3.6.4111459

错误解决方案

  • 如下错误: 进行sdk目录,执行./tools/bin/sdkmanager --licenses 全部选Y
    Failed to install the following Android SDK packages as some licences have not been accepted.

参考文档