Skip to content

Commit c443187

Browse files
committed
统一项目中获取资源文件路径的方式
1 parent f04bc9f commit c443187

File tree

17 files changed

+214
-200
lines changed

17 files changed

+214
-200
lines changed

shell/business/ResourceManager.sh

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/bin/bash
2+
# ----------------------------------------------------------------------
3+
# author : Android 轮子哥
4+
# github : https://github.com/getActivity/AndroidCmdTools
5+
# time : 2026/02/28
6+
# desc : 资源管理器脚本
7+
# ----------------------------------------------------------------------
8+
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../common/SystemPlatform.sh" || source "../common/SystemPlatform.sh"
9+
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../common/FileTools.sh" || source "../common/FileTools.sh"
10+
11+
getDexToJarShellDirPath() {
12+
local resourcesDirPath=$(getResourcesDirPath)
13+
echo "${resourcesDirPath}$(getFileSeparator)dex2jar-2.4$(getFileSeparator)d2j-dex2jar.sh"
14+
}
15+
16+
getDexToJarShellFilePath() {
17+
local resourcesDirPath=$(getResourcesDirPath)
18+
echo "${resourcesDirPath}$(getFileSeparator)dex2jar-2.4$(getFileSeparator)d2j-dex2jar.sh"
19+
}
20+
21+
getJarToDexShellDirPath() {
22+
local resourcesDirPath=$(getResourcesDirPath)
23+
echo "${resourcesDirPath}$(getFileSeparator)dex2jar-2.4$(getFileSeparator)d2j-jar2dex.sh"
24+
}
25+
26+
getJarToDexShellFilePath() {
27+
local resourcesDirPath=$(getResourcesDirPath)
28+
echo "${resourcesDirPath}$(getFileSeparator)dex2jar-2.4$(getFileSeparator)d2j-jar2dex.sh"
29+
}
30+
getJadxShellFilePath() {
31+
local resourcesDirPath=$(getResourcesDirPath)
32+
local fileSeparator=$(getFileSeparator)
33+
local jadxVersion="1.5.3"
34+
local jadxDirPath="${resourcesDirPath}${fileSeparator}jadx-${jadxVersion}"
35+
36+
local outputPrint
37+
local exitCode
38+
if [[ ! -d "${jadxDirPath}" ]]; then
39+
zipFileName="jadx-${jadxVersion}.zip"
40+
decompressedDirPath="${resourcesDirPath}${fileSeparator}jadx-${jadxVersion}"
41+
zipUrl="https://github.com/skylot/jadx/releases/download/v${jadxVersion}/${zipFileName}"
42+
zipFilePath="${resourcesDirPath}${fileSeparator}${zipFileName}"
43+
expectedSha256="8280f3799c0273fe797a2bcd90258c943e451fd195f13d05400de5e6451d15ec"
44+
if [[ -f "${zipFilePath}" ]]; then
45+
actualSha256=$(getFileSha256 "${zipFilePath}")
46+
if [[ "${actualSha256}" != "${expectedSha256}" ]]; then
47+
rm -f "${zipFilePath}"
48+
fi
49+
fi
50+
if [[ -f "${zipFilePath}" ]]; then
51+
outputPrint="$(unzip -q -o "${zipFilePath}" -d "${decompressedDirPath}" 2>&1)"
52+
exitCode=$?
53+
if (( exitCode != 0 )); then
54+
echo "${zipFileName} 解压失败,原因如下:"
55+
echo "${outputPrint}"
56+
kill -SIGTERM $$
57+
exit 1
58+
fi
59+
else
60+
echo "⏳ 检测到本地还未下载 jadx,开始下载 ${zipFileName} 文件,体积较大请耐心等待..."
61+
curl -L --progress-bar -o "${zipFilePath}" "${zipUrl}"
62+
exitCode=$?
63+
if (( exitCode != 0 )); then
64+
echo "${zipFileName} 下载失败,请检查网络或稍后重试"
65+
kill -SIGTERM $$
66+
exit 1
67+
fi
68+
actualSha256=$(getFileSha256 "${zipFilePath}")
69+
if [[ "${actualSha256}" != "${expectedSha256}" ]]; then
70+
rm -f "${zipFilePath}"
71+
echo "${zipFileName} 文件校验失败,期望值:${expectedSha256},实际值:${actualSha256}"
72+
kill -SIGTERM $$
73+
exit 1
74+
fi
75+
outputPrint="$(unzip -q -o "${zipFilePath}" -d "${decompressedDirPath}" 2>&1)"
76+
exitCode=$?
77+
if (( exitCode != 0 )); then
78+
echo "${zipFileName} 解压失败,原因如下:"
79+
echo "${outputPrint}"
80+
kill -SIGTERM $$
81+
exit 1
82+
fi
83+
fi
84+
rm -f "${zipFilePath}"
85+
fi
86+
87+
local jadxGuiShellFilePath="${jadxDirPath}${fileSeparator}bin${fileSeparator}jadx-gui"
88+
if ! isWindows; then
89+
if [[ ! -x "${jadxGuiShellFilePath}" ]]; then
90+
chmod +x "${jadxGuiShellFilePath}"
91+
fi
92+
jadxShellFilePath="${jadxDirPath}${fileSeparator}bin${fileSeparator}jadx"
93+
if [[ ! -x "${jadxShellFilePath}" ]]; then
94+
chmod +x "${jadxShellFilePath}"
95+
fi
96+
fi
97+
echo "${jadxGuiShellFilePath}"
98+
}
99+
100+
getJetifierStandaloneShellFilePath() {
101+
local resourcesDirPath=$(getResourcesDirPath)
102+
local fileSeparator=$(getFileSeparator)
103+
local jetifierDirPath="${resourcesDirPath}${fileSeparator}jetifier-standalone-20200827"
104+
local shellPath="${jetifierDirPath}${fileSeparator}bin${fileSeparator}jetifier-standalone"
105+
if isWindows; then
106+
echo "${shellPath}.bat"
107+
return
108+
fi
109+
if [[ ! -x "${shellPath}" ]]; then
110+
chmod +x "${shellPath}"
111+
fi
112+
echo "${shellPath}"
113+
}
114+
115+
getADBKeyBoardApkFilePath() {
116+
local resourcesDirPath=$(getResourcesDirPath)
117+
echo "${resourcesDirPath}$(getFileSeparator)ADBKeyBoard-5.0.apk"
118+
}
119+
120+
getApksignerJarFilePath() {
121+
local resourcesDirPath=$(getResourcesDirPath)
122+
echo "${resourcesDirPath}$(getFileSeparator)apksigner-36.0.0.jar"
123+
}
124+
125+
getDefaultStoreFilePath() {
126+
local resourcesDirPath=$(getResourcesDirPath)
127+
echo "${resourcesDirPath}$(getFileSeparator)signatureFile$(getFileSeparator)AppSignature.jks"
128+
}
129+
130+
getApktoolJarFilePath() {
131+
local resourcesDirPath=$(getResourcesDirPath)
132+
echo "${resourcesDirPath}$(getFileSeparator)apktool-2.12.1.jar"
133+
}
134+
135+
getBaksmaliJarFilePath() {
136+
local resourcesDirPath=$(getResourcesDirPath)
137+
echo "${resourcesDirPath}$(getFileSeparator)baksmali-2.5.2.jar"
138+
}
139+
140+
getSmaliJarFilePath() {
141+
local resourcesDirPath=$(getResourcesDirPath)
142+
echo "${resourcesDirPath}$(getFileSeparator)smali-2.5.2.jar"
143+
}
144+
145+
getDiffuserJarFilePath() {
146+
local resourcesDirPath=$(getResourcesDirPath)
147+
echo "${resourcesDirPath}$(getFileSeparator)diffuse-0.1.0.jar"
148+
}
149+
150+
getJdGuiJarFilePath() {
151+
local resourcesDirPath=$(getResourcesDirPath)
152+
echo "${resourcesDirPath}$(getFileSeparator)jd-gui-1.6.6.jar"
153+
}

shell/device-tools/simulation/InputText.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ source "../../common/SystemPlatform.sh" && \
1212
source "../../common/EnvironmentTools.sh" && \
1313
source "../../common/FileTools.sh" && \
1414
source "../../common/PasteTools.sh" && \
15-
source "../../business/DevicesSelector.sh" || exit 1
15+
source "../../business/DevicesSelector.sh" && \
16+
source "../../business/ResourceManager.sh" || exit 1
1617
cd "${originalDirPath}" || exit 1
1718
unset scriptDirPath
1819
unset originalDirPath
@@ -100,14 +101,8 @@ isInstallAdbKeyBoard() {
100101

101102
installAdbKeyBoard() {
102103
local deviceId=$1
103-
local resourcesDirPath
104-
resourcesDirPath=$(getResourcesDirPath)
105-
if [[ -z "${resourcesDirPath}" ]]; then
106-
echo "❌ 未找到 resources 目录,请确保它位于脚本的当前目录或者父目录"
107-
return 1
108-
fi
109-
echo "资源目录为:${resourcesDirPath}"
110-
local apkFilePath="${resourcesDirPath}/ADBKeyBoard-5.0.apk"
104+
local apkFilePath
105+
apkFilePath="$(getADBKeyBoardApkFilePath)"
111106
if [[ ! -f "${apkFilePath}" ]]; then
112107
echo "❌ 找不到 ADBKeyBoard 安装包:${apkFilePath}"
113108
return 1

shell/package-tools/AndroidXToSupport.sh

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ originalDirPath=$PWD
1010
cd "${scriptDirPath}" || exit 1
1111
source "../common/SystemPlatform.sh" && \
1212
source "../common/EnvironmentTools.sh" && \
13-
source "../common/FileTools.sh" || exit 1
13+
source "../common/FileTools.sh" && \
14+
source "../business/ResourceManager.sh" || exit 1
1415
cd "${originalDirPath}" || exit 1
1516
unset scriptDirPath
1617
unset originalDirPath
@@ -19,13 +20,6 @@ main() {
1920
printCurrentSystemType
2021
checkJavaEnvironment
2122

22-
resourcesDirPath=$(getResourcesDirPath)
23-
if [[ -z "${resourcesDirPath}" ]]; then
24-
echo "❌ 未找到 resources 目录,请确保它位于脚本的当前目录或者父目录"
25-
exit 1
26-
fi
27-
echo "资源目录为:${resourcesDirPath}"
28-
2923
echo "请输入要转换 aar / jar / zip 包的路径:"
3024
read -r androidXFilePath
3125
androidXFilePath=$(parseComputerFilePath "${androidXFilePath}")
@@ -53,7 +47,7 @@ main() {
5347
fi
5448
echo "support 包的保存路径:${supportFilePath}"
5549

56-
outputPrint="$("${resourcesDirPath}$(getFileSeparator)jetifier-standalone-20200827$(getFileSeparator)bin$(getFileSeparator)jetifier-standalone" -r -i "${androidXFilePath}" -o "${supportFilePath}" 2>&1)"
50+
outputPrint="$("$(getJetifierStandaloneShellFilePath)" -r -i "${androidXFilePath}" -o "${supportFilePath}" 2>&1)"
5751
exitCode=$?
5852
if (( exitCode != 0 )); then
5953
echo "❌ 转换失败,原因如下:"

shell/package-tools/CompareArchives.sh

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ originalDirPath=$PWD
1010
cd "${scriptDirPath}" || exit 1
1111
source "../common/SystemPlatform.sh" && \
1212
source "../common/EnvironmentTools.sh" && \
13-
source "../common/FileTools.sh" || exit 1
13+
source "../common/FileTools.sh" && \
14+
source "../business/ResourceManager.sh" || exit 1
1415
cd "${originalDirPath}" || exit 1
1516
unset scriptDirPath
1617
unset originalDirPath
@@ -19,13 +20,6 @@ main() {
1920
printCurrentSystemType
2021
checkJavaEnvironment
2122

22-
resourcesDirPath=$(getResourcesDirPath)
23-
if [[ -z "${resourcesDirPath}" ]]; then
24-
echo "❌ 未找到 resources 目录,请确保它位于脚本的当前目录或者父目录"
25-
exit 1
26-
fi
27-
echo "资源目录为:${resourcesDirPath}"
28-
2923
echo "请输入旧 apk/aar/jar/aab 包的路径:"
3024
read -r oldLibraryFilePath
3125
oldLibraryFilePath=$(parseComputerFilePath "${oldLibraryFilePath}")
@@ -50,8 +44,7 @@ main() {
5044
exit 1
5145
fi
5246

53-
diffuseJar="${resourcesDirPath}$(getFileSeparator)diffuse-0.1.0.jar"
54-
java -jar "${diffuseJar}" diff "${oldLibraryFilePath}" "${newLibraryFilePath}"
47+
java -jar "$(getDiffuserJarFilePath)" diff "${oldLibraryFilePath}" "${newLibraryFilePath}"
5548
}
5649

5750
clear

shell/package-tools/GetApkSignature.sh

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ originalDirPath=$PWD
1010
cd "${scriptDirPath}" || exit 1
1111
source "../common/SystemPlatform.sh" && \
1212
source "../common/EnvironmentTools.sh" && \
13-
source "../common/FileTools.sh" || exit 1
13+
source "../common/FileTools.sh" && \
14+
source "../business/ResourceManager.sh" || exit 1
1415
cd "${originalDirPath}" || exit 1
1516
unset scriptDirPath
1617
unset originalDirPath
@@ -19,13 +20,6 @@ main() {
1920
printCurrentSystemType
2021
checkJavaEnvironment
2122

22-
resourcesDirPath=$(getResourcesDirPath)
23-
if [[ -z "${resourcesDirPath}" ]]; then
24-
echo "❌ 未找到 resources 目录,请确保它位于脚本的当前目录或者父目录"
25-
exit 1
26-
fi
27-
echo "资源目录为:${resourcesDirPath}"
28-
2923
echo "请输入要要进行要验证的 apk 包的路径(不能为空)"
3024
read -r sourceApkFilePath
3125
sourceApkFilePath=$(parseComputerFilePath "${sourceApkFilePath}")
@@ -45,7 +39,7 @@ main() {
4539
apkSignerJarFilePath=$(parseComputerFilePath "${apkSignerJarFilePath}")
4640

4741
if [[ -z "${apkSignerJarFilePath}" ]]; then
48-
apkSignerJarFilePath="${resourcesDirPath}$(getFileSeparator)apksigner-36.0.0.jar"
42+
apkSignerJarFilePath="$(getApksignerJarFilePath)"
4943
fi
5044

5145
if [[ ! -f "${apkSignerJarFilePath}" ]]; then

shell/package-tools/SignatureApk.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ originalDirPath=$PWD
1010
cd "${scriptDirPath}" || exit 1
1111
source "../common/SystemPlatform.sh" && \
1212
source "../common/EnvironmentTools.sh" && \
13-
source "../common/FileTools.sh" || exit 1
13+
source "../common/FileTools.sh" && \
14+
source "../business/ResourceManager.sh" || exit 1
1415
cd "${originalDirPath}" || exit 1
1516
unset scriptDirPath
1617
unset originalDirPath
@@ -48,19 +49,13 @@ waitUserInputParameter() {
4849
exit 1
4950
fi
5051

51-
resourcesDirPath=$(getResourcesDirPath)
52-
if [[ -z "${resourcesDirPath}" ]]; then
53-
echo "❌ 未找到 resources 目录,请确保它位于脚本的当前目录或者父目录"
54-
exit 1
55-
fi
56-
echo "资源目录为:${resourcesDirPath}"
5752
echo "是否使用默认的签名配置进行签名?(y/n),留空则默认使用"
5853
read -r oneKeySignature
5954
if [[ -z "${oneKeySignature}" ]]; then
6055
oneKeySignature="y"
6156
fi
6257
if [[ "${oneKeySignature}" =~ ^[yY]$ ]]; then
63-
storeFilePath="${resourcesDirPath}$(getFileSeparator)signatureFile$(getFileSeparator)AppSignature.jks"
58+
storeFilePath=$(getDefaultStoreFilePath)
6459
apkSignerJarFilePath=""
6560
else
6661
echo "请输入 apksigner jar 包的路径(可为空)"
@@ -92,7 +87,7 @@ waitUserInputParameter() {
9287
read -r keyPassword
9388
fi
9489
if [[ -z "${apkSignerJarFilePath}" ]]; then
95-
apkSignerJarFilePath="${resourcesDirPath}$(getFileSeparator)apksigner-36.0.0.jar"
90+
apkSignerJarFilePath="$(getApksignerJarFilePath)"
9691
fi
9792
if [[ ! -f "${storeFilePath}" ]]; then
9893
echo "❌ 密钥库文件不存在,请检查 ${storeFilePath} 文件路径是否正确"

shell/package-tools/SupportToAndroidX.sh

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ originalDirPath=$PWD
1010
cd "${scriptDirPath}" || exit 1
1111
source "../common/SystemPlatform.sh" && \
1212
source "../common/EnvironmentTools.sh" && \
13-
source "../common/FileTools.sh" || exit 1
13+
source "../common/FileTools.sh" && \
14+
source "../business/ResourceManager.sh" || exit 1
1415
cd "${originalDirPath}" || exit 1
1516
unset scriptDirPath
1617
unset originalDirPath
@@ -19,13 +20,6 @@ main() {
1920
printCurrentSystemType
2021
checkJavaEnvironment
2122

22-
resourcesDirPath=$(getResourcesDirPath)
23-
if [[ -z "${resourcesDirPath}" ]]; then
24-
echo "❌ 未找到 resources 目录,请确保它位于脚本的当前目录或者父目录"
25-
exit 1
26-
fi
27-
echo "资源目录为:${resourcesDirPath}"
28-
2923
echo "请输入要转换 aar / jar / zip 包的路径:"
3024
read -r supportFilePath
3125
supportFilePath=$(parseComputerFilePath "${supportFilePath}")
@@ -53,7 +47,7 @@ main() {
5347
fi
5448
echo "androidx 包的保存路径:${androidXFilePath}"
5549

56-
outputPrint="$("${resourcesDirPath}$(getFileSeparator)jetifier-standalone-20200827$(getFileSeparator)bin$(getFileSeparator)jetifier-standalone" -i "${supportFilePath}" -o "${androidXFilePath}" 2>&1)"
50+
outputPrint="$("$(getJetifierStandaloneShellFilePath)" -i "${supportFilePath}" -o "${androidXFilePath}" 2>&1)"
5751
exitCode=$?
5852
if (( exitCode != 0 )); then
5953
echo "❌ 转换失败,原因如下:"

shell/reverse-tools/apktool/DecompileApk.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ originalDirPath=$PWD
1010
cd "${scriptDirPath}" || exit 1
1111
source "../../common/SystemPlatform.sh" && \
1212
source "../../common/EnvironmentTools.sh" && \
13-
source "../../common/FileTools.sh" || exit 1
13+
source "../../common/FileTools.sh" && \
14+
source "../../business/ResourceManager.sh" || exit 1
1415
cd "${originalDirPath}" || exit 1
1516
unset scriptDirPath
1617
unset originalDirPath
1718

1819
waitUserInputParameter() {
19-
resourcesDirPath=$(getResourcesDirPath)
20-
echo "资源目录为:${resourcesDirPath}"
21-
2220
echo "请输入要反编译 apk 包的路径"
2321
read -r sourceApkFilePath
2422
sourceApkFilePath=$(parseComputerFilePath "${sourceApkFilePath}")
@@ -64,13 +62,16 @@ waitUserInputParameter() {
6462
done
6563
fi
6664

67-
local apktoolJarFileName="apktool-2.12.1.jar"
68-
echo "请输入 apktool jar 包的路径(可为空,默认使用 ${apktoolJarFileName}"
65+
local apktoolDefaultJarFilePath
66+
apktoolDefaultJarFilePath=$(getApktoolJarFilePath)
67+
local apktoolDefaultJarFileName
68+
apktoolDefaultJarFileName=$(basename "${apktoolDefaultJarFilePath}")
69+
echo "请输入 apktool jar 包的路径(可为空,默认使用 ${apktoolDefaultJarFileName}"
6970
read -r apktoolJarFilePath
7071
apktoolJarFilePath=$(parseComputerFilePath "${apktoolJarFilePath}")
7172

7273
if [[ -z "${apktoolJarFilePath}" ]]; then
73-
apktoolJarFilePath="${resourcesDirPath}$(getFileSeparator)${apktoolJarFileName}"
74+
apktoolJarFilePath="${apktoolDefaultJarFilePath}"
7475
fi
7576

7677
if [[ ! -f "${apktoolJarFilePath}" ]]; then

0 commit comments

Comments
 (0)