jenkins 自动化打包flutter android apk

一、部署jenkins省略

二、部署flutter

1.环境:

Flutter (Channel stable, v1.12.13+hotfix.5, locale zh-Hans-CN)

下载地址:https://storage.googleapis.com/flutter_infra/releases/stable/windows/flutter_windows_v1.12.13+hotfix.5-stable.zip

gradle: 3.5.0

下载地址: https://gradle.org/next-steps/?version=3.4.1&format=bin

jdk: 1.8.0_151   (自行安装)

Android SDK version 28.0.3

下载地址:http://tools.android-studio.org/index.php/sdk/

开发给定渠道如下:

        qijian {}
        yingyongbao {}
        vivo {}
        oppo {}
        baidu {}
        lenovo {}
        huawei {}
        samsung {}
        xiaomi {}
        anzhi {}
        sougou {}
        gfan {}
        uc {}
        _360 {}
        meizu {}
        mumayi {}

 

2.部署

环境部署:

cd  /usr/local/src/

wget https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_v1.12.13+hotfix.5-stable.tar

tar -xf  flutter_linux_v1.12.13+hotfix.5-stable.tar  -C  /usr/local/

 

wget  http://dl.google.com/android/android-sdk_r24.4.1-linux.tgz

mkdir /usr/local/android-home -p

tar -xf android-sdk_r24.4.1-linux.tgz -C  /usr/local/android-home

 

wget   https://gradle.org/next-steps/?version=3.4.1&format=bin

unzip  gradle-3.5-bin.zip 

mkdir -p /opt/gradle/ 

mv gradle-3.5 /opt/gradle/ 

增加 profile

export JAVA_HOME=/usr/local/jdk1.8
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH:/usr/local/apache-maven-3.3.9/bin:/usr/local/flutter/bin
export PATH=$JAVA_HOME/bin:$PATH


export ANDROID_HOME=/usr/local/android-home
export PATH=$PATH:/usr/local/android-home/android-tools/bin
export PATH=$ANDROID_HOME/android-tools:$ANDROID_HOME/platform-tools:$PATH

export GRADLE_HOME=/opt/gradle/gradle-3.5
export PATH=$GRADLE_HOME/bin:$PATH

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=/usr/local/flutter/bin:$PATH

 

source  /etc/profile

安装 Android SDK

/usr/local/android-home/tools/bin/sdkmanager "platforms;android-28" "build-tools;28.0.3"

 

flutter doctor -v

flutter 版本信息会出现unknown 状态

需要升级git 版本

 yum remove git

yum install http://opensource.wandisco.com/centos/6/git/x86_64/wandisco-git-release-6-1.noarch.rpm   -y 

git version 2.22.0

 

flutter doctor -v

会出现网络问题

修改:

  /usr/local/flutter/packages/flutter_tools/gradle/flutter.gradle 

jenkins 自动化打包flutter android apk

 

 

再次运行 flutter doctor -v

发现已经解决报错问题。

 

jenkins上部署:

执行shell

jenkins 自动化打包flutter android apk

 

 

 代码粘贴如下:

 

#下载flutter 依赖包
flutter packages get

#flutter 打包
flutter build apk

#分渠道创建目录
rm -rf /data/tgbus_app_android/*
mkdir /data/tgbus_app_android/{_360,anzhi,baidu,gfan,huawei,lenovo,meizu,mumayi,qijian,samsung,sougou,uc,xiaomi,yingyongbao,oppo,vivo}

dir="/data/tgbus_app_android/"
project=`ls /data/tgbus_app_android/`


for i in $project;do
scp -qpr /data/tgbus.jks $dir$i
scp -qpr /data/jenkins/.jenkins/workspace/tgbus_app_android/build/app/outputs/apk/release/app-release.apk $dir$i
cd $dir$i/
#解码apk
apktool d -f app-release.apk
#修改渠道
sed "s/test1/${i}/g" -i app-release/AndroidManifest.xml
#重新打包apk
apktool b app-release -o app-release-$i-dev.apk
#为打包后的apk 进行签名,tgbus.jks 为开发提供的秘钥
echo "32100000" | jarsigner -verbose -keystore tgbus.jks -signedjar app-release-$i.apk app-release-$i-dev.apk tgbus
if [ $? -eq 0 ];then
echo "build is ok"
else
echo "build is false"
fi
done

 

以上命令  apktool  安装:

右键点击此链接,另存为apktool

下载最新版本的apktool-2,然后重命名为apktool.jar

将apktool和apktool.jar移动到/usr/local/bin文件夹中

 

mv apktool /usr/local/bin

mv apktool.jar /usr/local/bin

 

给apktool和apktool.jar添加可执行权限

chmod +x apktool

chmod +x apktool.jar

 

jarsigner 签名命令:  

cp /usr/local/jdk1.8/bin/jarsigner  /usr/local/bin

 

至此,jenkins 自动化打包flutter android apk包完成。

 

jenkins 自动化打包flutter android apk

上一篇:17行代码解决微信小程序图片延迟加载


下一篇:微信二次分享功能开发笔记