脚本记录

#!/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 "----------------------------------------------------------------------------"
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值