一、脚本
1、打包自动更换build版本号脚本
# 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位架构包脚本
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("-------------------分析完成-------------------------------")
网友评论