avatar

目录
Script MuiltPackage

MuiltPackage-多项目编译打包

说明

linux服务器多项目Android工程打包,本项目基于自定义as-build.grade打包脚本 → Android Gradle

本文实例测试代码已上传githubAndroidGradle

使用

shell
1
2
chmod +x svn2Git.sh
./base-release.sh "test-project" "test-project-code" "git@xxxx.git" "assembleRelease"

参数1:项目别名

参数2:git代码链接

参数3:git代码分支

参数4:gradle打包task

示例

  1. 创建打包工程目录及脚本目录
shell
1
2
3
4
mkdir Project
cd Project
mkdir script
cd script
  1. 将base-package.sh放入到script文件夹,并在script 自定义脚本testgradleproject.sh
shell
1
2
3
4
5
6
7
8
9
#!/bin/bash
echo "-------------------------------------------------------------"
echo "----------------------start load test-project---------------------"
echo "-------------------------------------------------------------"
./base-package.sh test-project git@github.com:lairdli/AndroidGradle.git master assembleRelease
./base-package.sh test-project-mul git@github.com:lairdli/AndroidGradle.git develop assembleRelease
echo "-------------------------------------------------------------"
echo "----------------------finish load test-project---------------------"
echo "-------------------------------------------------------------"
  1. 运行脚本

运行自定义脚本

shell
1
2
3
chmod +x base-package.sh
chmod +x testgradleproject.sh
./testgradleproject.sh

或手动运行base脚本

shell
1
./base-package.sh test-project git@github.com:lairdli/AndroidGradle.git master assembleRelease
  1. 编译完成后目录
shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 laird@192  ~/Work/00doc/study/Script/multPackage  tree -L 4
.
└── testProjiecrt
├── out
│   ├── test-project
│   │   ├── app_test
│   │   ├── app_test1
│   │   └── release
│   └── test-project-mul
│   ├── app_test1_mul
│   ├── app_test_mul
│   └── release
├── script
│   ├── base-package.sh
│   └── testgradleproject.sh
└── workspace
├── test-project
│   └── AndroidGradle
└── test-project-mul
└── AndroidGradle
  1. 编译完成后输出out目录
shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
out
├── test-project
│   ├── app_test
│   │   ├── output.json
│   │   ├── top.lairdli.study.testapplication.release.202006081831.apk
│   │   └── top.lairdli.study.testapplication.txt
│   ├── app_test1
│   │   ├── output.json
│   │   ├── top.lairdli.study.testapplication1.release.202006081831.apk
│   │   └── top.lairdli.study.testapplication1.txt
│   └── release
│   ├── aar
│   │   └── 20200608
│   │   ├── top.lairdli.study.comon.aar
│   │   ├── top.lairdli.study.testlibrary.aar
│   │   └── top.lairdli.study.testlibrary1.aar
│   └── app
│   └── 20200608
│   ├── top.lairdli.study.testapplication.apk
│   ├── top.lairdli.study.testapplication.txt
│   ├── top.lairdli.study.testapplication1.apk
│   └── top.lairdli.study.testapplication1.txt
└── test-project-mul
├── app_test1_mul
│   └── mulTest
│   ├── output.json
│   ├── top.lairdli.study.testapplication1_mul.release.202006081831.apk
│   └── top.lairdli.study.testapplication1_mul.txt
├── app_test_mul
│   └── mulTest
│   ├── output.json
│   ├── top.lairdli.study.testapplication_mul.release.202006081831.apk
│   └── top.lairdli.study.testapplication_mul.txt
└── release
├── aar
│   └── 20200608
│   ├── top.lairdli.study.comon.aar
│   ├── top.lairdli.study.testlibrary.aar
│   └── top.lairdli.study.testlibrary1.aar
└── app
└── 20200608
├── top.lairdli.study.testapplication1_mul.apk
├── top.lairdli.study.testapplication1_mul.txt
├── top.lairdli.study.testapplication_mul.apk
└── top.lairdli.study.testapplication_mul.txt

18 directories, 26 files
  1. 其中txt为相关版本的版本信息
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
****************************************************
*************** https://lairdli.top ***************
****************************************************
**:Name:top.lairdli.study.testapplication.release.202006081831.apk
**:ApplicationId:top.lairdli.study.testapplication
**:VersionCode:2020060831
**:VeresionName:202006081831
**:LastModify:2020-06-08 06:31:25
**:Size:1645505
**:Md5:4300857fea7d824475c03527b5f3a2e8
**:Sha1:d5a41ae9bb2432a5e9ae22e6976b1657e96f4726
**:Des:
****************************************************

源码

shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
#参数1:项目名称 例如 test-project
#参数2:项目对应的代码目录名称 例如 test-project-code
#参数3:代码vcs路径,默认是git,svn暂未实现 例如 xxx.git
#参数4:打包脚本命令: 例如 assemble
#

function printParams(){
echo "--------load params------------"
echo "project-name: $1"
echo "project-code-git-url: $2"
echo "project-code-git-branch: $3"
echo "project-code-gradle-task: $4"
echo "-------------------------------"
}

function mkdirDir(){
echo mkdir $1
if [ ! -d $1 ]; then
mkdir $1
fi
}

#参数1:项目对应的代码目录名称 例如 amg-iptv-os
#参数2:代码vcs路径,默认是git,svn暂未实现 例如 xxx.git
#参数3:打包脚本命令: 例如 assemble
#
function compileCode(){
gitUrl=$1
urlLastName=${gitUrl##*/}
gitProjectName=${urlLastName%.git}
gitBranch=$2
gradleTask=$3
echo "------>>>>start clone $gitProjectName<<<-----"< span>
rm -rf $gitProjectName
git clone -b $gitBranch $gitUrl
echo "------>>>>finish clone $gitProjectName<<<-----"< span>
echo "------>>>>start compile $gitProjectName<<<-----"< span>
cd $gitProjectName
chmod 777 gradlew
echo "------>>>> ./gradlew $gradleTask<<<-----"< span>
./gradlew $gradleTask
echo "------>>>>finish compile $gitProjectName<<<-----"< span>
}



function packageOut(){
pwd
mkdirDir ../../../out
mkdirDir ../../../out/$projectName/
echo "start cp ,just wating ..."
sleep 2s
cp -rf out/* ../../../out/$projectName/
echo "finish cp"
}


printParams $1 $2 $3 "$4"

projectName=$1
gitUrl=$2
gitBranch=$3
gradleTask=$4


echo "------>>>>init Project $projectName<<<-----"< span>
cd ../workspace
mkdirDir $projectName
cd $projectName

echo "------>>>>start load $projectName<<<-----"< span>

echo "------>>>>start compile $projectName<<<-----"< span>
compileCode $2 $3 $4
echo "------>>>>end compile $projectName<<<-----"< span>

echo "------>>>>start package $projectName<<<-----"< span>
packageOut
echo "------>>>>end package $projectName<<<-----"< span>

echo "------>>>>end Project $projectName<<<-----"< span>

其他

linux服务器上打包可能出现androd编译版本找不到的情况

可进入sdk根目录下,执行如下命令

  • 查看帮助
shell
1
2
3
tools/android -h
tools/android -h list sdk
tools/android -h update sdk
  • 查询Android 所有版本
shell
1
tools/android list sdk -a
  • 升级Android SDK Platform的API num对应指定的id
shell
1
tools/android update sdk -u -t id -a
文章作者: laird.li
文章链接: https://lairdli.top/2020/06/06/Script-MultiPackage/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 黎明鸟飞去

评论