美文网首页
打包脚本

打包脚本

作者: 出来遛狗了 | 来源:发表于2023-01-04 16:27 被阅读0次

一、脚本

1、打包自动更换build版本号脚本

image.png
# Type a script or drag a script file from your workspace to insert its path.
if [ $CONFIGURATION == Release ]; then
echo " Bumping build number... "

build_number=$(date +%Y%m%d%H%M)
/usr/libexec/PlistBuddy -c "Set CFBundleVersion ${build_number}" ${INFOPLIST_FILE}

fi

2、打包脚本
文件命名为:uat_development.sh

SFDate=`date +%Y-%m-%d`
SFDateTime=`date +%Y-%m-%d,%H.%M`
user="/Users/${USER}"
echo $user
cd $user/arichive-app/sf_express_international 
git checkout .
git pull
flutter pub get 
cd ios 
pod install

xcodebuild  clean \
archive \
-workspace "$user/arichive-app/sf_express_international/ios/Runner.xcworkspace" \
-scheme "Runner_UAT" \
-configuration "Release" \
-archivePath "$user/Archives/$SFDate/Runner_UAT $SFDateTime" \
-derivedDataPath "$user/DerivedData/" \
-quiet

3、打包移除32位架构包脚本

image.png
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"

# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*Lite.framework' -type d | while read -r FRAMEWORK
do
    FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
    FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
    echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"

    EXTRACTED_ARCHS=()

    for ARCH in $ARCHS
    do
        echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
        lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
        EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
    done

    echo "Merging extracted architectures: ${ARCHS}"
    lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
    rm "${EXTRACTED_ARCHS[@]}"

    echo "Replacing original executable with thinned version"
    rm "$FRAMEWORK_EXECUTABLE_PATH"
    mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"

done

4、查找Flutter中无用图片脚本(python)
命名为 imgAnalyze.py

# coding=utf8
#!/user/local/bin/python3
# 将本文件放在Flutter项目的根目录

from genericpath import isdir
import imghdr
from operator import delitem
import os
from re import search
import re
import string
from sys import path
import sys
from tokenize import String
from typing import List

print("---Analyze unused Assets----")
# 项目目录
projectAbsRootPath = sys.path[0]
# 图片所在的资源目录路径
assetPath = "/assets"
# 项目中dart代码所在目录
libPath = projectAbsRootPath + "/lib"
assetAbPath = projectAbsRootPath+assetPath

print("projectRootPath:" + projectAbsRootPath +
      "   assets:" + assetAbPath + "     lib:" + libPath)
print("----------开始查找图片--------------")
# 遍历目录,将图片存储到list中的方法


def searchImage(filePath: String):
    list = []
    isDir = os.path.isdir(filePath)
    if isDir:
        for f in os.listdir(filePath):
            if f.startswith("."):
                print(filePath+"/"+f)
            else:
                tList = searchImage(filePath+"/"+f)
                list.extend(tList)
    else:
        if imghdr.what(filePath) in {"jpg", "bmp", "jpeg", "rgb", "tif", "png"}:
            list.append(filePath)
    return list


# 项目中使用的图片资源路径集合
imageList = searchImage(assetAbPath)

print("-------------遍历dart文件,分析未使用的图片---------")


def matchAndDelImage(contentStr: String, list: List):
    # 遍历拷贝的list,操作原始的list,list[:]是对原始的一个拷贝
    for imgPath in list[:]:
        # 以文件名匹配图片的使用
        # pList = imgPath.split("/")
        # imgName = pList[-1]
        # 以使用的文件路径匹配图片
        index = imgPath.find(assetPath)
        imgName = imgPath[index+1:]
        imgName = imgName.replace("assets/img/", "")
        imgName = imgName.replace("/3.0x", "")
        imgName = imgName.split(".")[0]
        match = re.search(imgName, contentStr)
        if match:
            list.remove(imgPath)
            # print("used-->" + imgPath)

#


def searchImageInDart(filePath: String, list: List):
    if os.path.isdir(filePath):
        for f in os.listdir(filePath):
            searchImageInDart(filePath+"/"+f, list)
    else:
        with open(filePath, "r", encoding="utf-8") as f:
            print(f)
            contentStr = f.read()
            f.close()
            if len(contentStr) != 0:
                matchAndDelImage(contentStr, list)

#
searchImageInDart(libPath, imageList)

print("------在dart文件中未找到被使用的图片如下-----size:" + str(len(imageList)))
for img in imageList:
    print("may be unused-->" + img)
    # os.remove(img)
print("-------------------分析完成-------------------------------")

相关文章

  • gradlew和gradle的区别

    1. Android Studio打包和直接用gradlew脚本打包用的脚本不同,Android Studio打包...

  • 持续集成

    手动打包存在的问题 操作繁琐 时间慢 不够逼格 自动化打包 shell脚本打包shell脚本打包之前最好先buli...

  • iOS自动打包ipa(shell脚本)

    系列 iOS自动打包ipa(shell脚本)iOS自动打包ipa(Python脚本) 安装xctool shell...

  • 闲来无事的懒人-打包ipa

    gym 打包 cd项目根目录, 创建自动打包脚本: 提升脚本权限 chmod +x gym.sh 执行脚本 ./g...

  • Xcode自动打包

    [iOS]从零开始写个自动打包IPA脚本 【iOS打ipa包】:使用终端实现自动打包 iOS自动打包并发布脚本

  • iOS自动打包ipa(Python脚本)

    系列 iOS自动打包ipa(shell脚本)iOS自动打包ipa(Python脚本) 安装Python库 Pyth...

  • pyinstaller的使用

    pyinstaller简介 pyinstaller是一个常用的python脚本打包工具,可以将python脚本打包...

  • jenkins自动部署

    服务端自动打包脚本 自动部署脚本

  • 持续集成

    打包配置 httpclient测试代码打包: springboot集成代码打包: Jenkins--shell脚本...

  • GO打包部署脚本

    GO打包部署脚本 $ Linux 打包 build_linux.bat $ Windows exe 打包 bu...

网友评论

      本文标题:打包脚本

      本文链接:https://www.haomeiwen.com/subject/fnjlcdtx.html