#!/bin/bash -e
#
#arg1:
# --release :build unsign apk to packages/carapps
# --test :build sign apk to packages/carapps
#arg2:
# apkList :"xx xx" if not set,build all apk
#
function printHelp() {
echo "-------------------------------------------------------------------------------------------------------"
echo "Help:"
echo "-----------buildApps.sh --release :build all unsign apk(used by CI)------------------------"
echo "-----------buildApps.sh --test :build all sign and proguard apk-------------------------"
echo "-----------buildApps.sh --testN :build all sign and not proguard apk---------------------"
echo "-----------buildApps.sh --test \"av\" :build av sign and proguard apk--------------------------"
echo "-----------buildApps.sh --testN \"av\" :build av sign and not proguard apk----------------------"
echo "-------------------------------------------------------------------------------------------------------"
}
printHelp
starttime=$(date +%s)
echo "gradle build begin:$(date)"
currentPath=$(
cd $(dirname $0)/..
pwd
)
echo "current shell path:$currentPath"
export GRADLE_HOME=$HOME/.gradle/wrapper/dists/gradle-5.4.1-all/3221gyojl5jsh0helicew7rwx/gradle-5.4.1
export PATH=$GRADLE_HOME/bin:$PATH
vendorDirPrefix="$currentPath/Apks"
option=$1
buildApkList=$2
gradle --version
echo "Android Sdk Path: $ANDROID_HOME"
echo "gradle home Path: $GRADLE_HOME"
echo "Path: $PATH"
rm -rf $HOME/.gradle/caches
rm -rf $HOME/.gradle/daemon
##########################
#
#agr1: apkName
#arg2: --release: not sign and proguard
# --test: sign and proguard
# --testN: sign and not proguard
#
##########################
function buildApp() {
echo "============================================================================"
echo "---------------------- build apk:$1 begin, arg:$2 ------------------------"
local apkName=$1
local apkprefix="app/build/outputs/apk"
local proguardMaping="app/build/outputs/mapping"
local buildType=""
local apkPath=""
local OutDir=""
echo "$currentPath/Apps/$apkName/build.gradle"
if [ ! -f "$currentPath/Apps/$apkName/build.gradle" ]; then
echo -e "\033[41;30m===warning: gradle file not exist in $currentPath/Apps/$apkName \033[0m"
echo -e "\033[41;30m===warning: Please check the app name is correct \033[0m"
echo -e "\033[41;30m===warning: Please check the app's folder is exist \033[0m"
echo -e "\033[41;30m===warning: Please check the app is a gradle project and not null \033[0m"
return
fi
cd $currentPath/Apps/$apkName
mkdir -p "$vendorDirPrefix/$apkName/"
rm -rf app/build
gradle clean
if [[ "$2" == "--release" ]]; then
buildType="release"
gradle assembleRelease --refresh-dependencies --offline
apkPath="$apkprefix/$buildType/app-$buildType-unsigned.apk"
OutDir="$vendorDirPrefix/$apkName/$apkName.apk"
if [ -d "${proguardMaping}" ]; then
cp -frv ${proguardMaping} $vendorDirPrefix/$apkName/
else
echo -e "\033[41;30m=====================warning: proguard maping file not exist============================\033[0m"
fi
elif [[ "$2" == "--test" ]]; then
buildType="uiTestProguard"
gradle assembleUiTestProguard --refresh-dependencies --offline
apkPath="$apkprefix/$buildType/app-$buildType.apk"
OutDir="$vendorDirPrefix/$apkName/$apkName.apk"
cp -frv ${proguardMaping} $vendorDirPrefix/$apkName/
elif [[ "$2" == "--testN" ]]; then
buildType="uiTestNoProguard"
gradle assembleUiTestNoProguard --refresh-dependencies --offline
apkPath="$apkprefix/$buildType/app-$buildType.apk"
OutDir="$vendorDirPrefix/$apkName/$apkName.apk"
else
echo -e "\033[41;30m=================================================\033[0m"
printHelp
echo -e "\033[41;30m=================================================\033[0m"
exit 1
fi
cp -frv ${apkPath} ${OutDir}
echo "------------------------ build apk:$1 end --------------------------------"
echo "============================================================================"
}
function generateCode() {
cd $currentPath/eCSWorkspace/iWorkSpace
cp $currentPath/eCSWorkspace/iWorkSpace/AutoTest.json $currentPath/eCSWorkspace/iWorkSpace/iAutoConfig/AutoTest.json
python autoTest.py $currentPath/eCSWorkspace/iWorkSpace/sketchfiles $currentPath/eCSWorkspace/iWorkSpace $currentPath/Apps
rm -rf $currentPath/eCSWorkspace/iWorkSpace/iAutoConfig/AutoTest.json
}
function buildUiBase() {
echo "---------------------- build uibase begin ---------------------------------"
cd $currentPath/UIBase
gradle clean
gradle publish --offline
echo "---------------------- build uibase end -----------------------------------"
}
function buildUiControl() {
echo "---------------------- build uicontrol begin ---------------------------------"
cd $currentPath/UIControl
gradle clean
gradle publish --refresh-dependencies --offline
echo "---------------------- build uicontrol end -----------------------------------"
}
function buildFuncmodel() {
echo "---------------------- build funcmodel begin ---------------------------------"
cd $currentPath/funcmodel
gradle clean
gradle publish --refresh-dependencies --offline
echo "---------------------- build funcmodel end -----------------------------------"
}
function buildFuncmodelAndroidTest() {
echo "---------------------- build buildFuncmodelAndroidTest begin -----------------"
cd $currentPath/funcmodel
gradle clean
gradle assembleDebugAndroidTest --refresh-dependencies --offline
echo "---------------------- build buildFuncmodelAndroidTest end -------------------"
}
##########################
# build UI apk
# agr1: buildOption
# agr2: apkName list
#
##########################
function buildUiApk() {
echo "---------------------- build apk begin ---------------------------------"
buildOption=$1
apkList=$2
hulue="carsystemui vk debug"
AppsFolderName=""
echo "first param:$buildOption"
echo "second param:$apkList"
AppsFolderNameTmp=$(ls $currentPath/Apps)
for folderName in $AppsFolderNameTmp; do
if [ -d "$currentPath/Apps/$folderName" ]; then
if [[ $hulue =~ $folderName ]]; then
echo $folderName
else
AppsFolderName="$AppsFolderName $folderName"
fi
fi
done
echo "AppsFolderName:$AppsFolderName"
if [ ! -n "$apkList" ]; then
apkList=$AppsFolderName
fi
echo "apk list:$apkList"
for apk in $apkList; do
buildApp $apk $buildOption
done
echo "---------------------- build apk end -----------------------------------"
}
echo "buildApkList:"$buildApkList
case $buildApkList in
"uibase")
echo "build uibase"
buildUiBase
;;
"uicontrol")
echo "build uicontrol"
buildUiBase
buildUiControl
;;
"funcmodel")
echo "build funcmodel"
buildUiBase
buildUiControl
buildFuncmodel
;;
*)
echo "build apk"
#generate code from workspace
# generateCode
buildUiBase
buildUiControl
buildFuncmodelAndroidTest
buildFuncmodel
buildUiApk $option "$buildApkList"
;;
esac
echo "gradle build end:$(date)"
endtime=$(date +%s)
cost=$((endtime - starttime))
echo $cost"s"
echo "----------------------------------------------------------------------------"