├── .gitignore
├── .idea
├── gradle.xml
├── misc.xml
├── uiDesigner.xml
├── vcs.xml
└── workspace.xml
├── README.md
├── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── jar
└── autoSign-1.1.jar
├── settings.gradle
└── src
└── main
└── java
└── org
└── example
├── ApkUtil.java
├── Main.java
├── cmd
└── CmdUtil.java
├── config
├── SignConfigFile.java
└── SignConfigsBean.java
├── file
└── FileUtil.java
├── function
├── Action.java
├── Action2.java
├── Function.java
└── Function2.java
└── ui
├── FilePathFrame.java
└── Log.java
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 | !**/src/main/**/build/
5 | !**/src/test/**/build/
6 |
7 | ### IntelliJ IDEA ###
8 | .idea/modules.xml
9 | .idea/jarRepositories.xml
10 | .idea/compiler.xml
11 | .idea/libraries/
12 | *.iws
13 | *.iml
14 | *.ipr
15 | out/
16 | !**/src/main/**/out/
17 | !**/src/test/**/out/
18 |
19 | ### Eclipse ###
20 | .apt_generated
21 | .classpath
22 | .factorypath
23 | .project
24 | .settings
25 | .springBeans
26 | .sts4-cache
27 | bin/
28 | !**/src/main/**/bin/
29 | !**/src/test/**/bin/
30 |
31 | ### NetBeans ###
32 | /nbproject/private/
33 | /nbbuild/
34 | /dist/
35 | /nbdist/
36 | /.nb-gradle/
37 |
38 | ### VS Code ###
39 | .vscode/
40 |
41 | ### Mac OS ###
42 | .DS_Store
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 | -
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 |
29 | -
30 |
31 |
32 |
33 |
34 |
35 | -
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 | -
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 | true
121 | true
122 | false
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 | 1684290075434
143 |
144 |
145 | 1684290075434
146 |
147 |
148 | 1684290484445
149 |
150 |
151 |
152 | 1684290484445
153 |
154 |
155 | 1684308291006
156 |
157 |
158 |
159 | 1684308291006
160 |
161 |
162 | 1684309393512
163 |
164 |
165 |
166 | 1684309393512
167 |
168 |
169 | 1684309995492
170 |
171 |
172 |
173 | 1684309995492
174 |
175 |
176 | 1684315743637
177 |
178 |
179 |
180 | 1684315743637
181 |
182 |
183 | 1712804598981
184 |
185 |
186 |
187 | 1712804598981
188 |
189 |
190 | 1712804794385
191 |
192 |
193 |
194 | 1712804794385
195 |
196 |
197 |
198 |
199 |
200 |
201 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 | file://$PROJECT_DIR$/src/main/java/org/example/file/FileUtil.java
224 | 27
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 | org.example.*
233 |
234 |
235 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # autoSignApk
2 | 通过配置文件,可以自动签名apk,直接拖入apk文件即可
3 |
4 | # 序言
5 | 因为360加固,自动签名需要开通VIP,每次加固完了都得手动签名。所以写了个工具。实现通过配置文件配置,拖拽APK自动签名。
6 |
7 | 支持:V1 V2 V3 V4 签名。通过分析清单文件,自动选择版本。
8 |
9 | 
10 |
11 | # 2024.4.11 发布1.1
12 | 支持了对齐功能,如果apk没有对齐,在targetSdkVersion>30的情况下会出现无法按照的情。
13 | 需要在配置文件中配置对齐工具的地址。属性为alignToolsPath,值可以参考。"D:\\Android\\SDK(前面是sdk的地址)\\build-tools\\33.0.2(最新的sdk版本)\\zipalign.exe"
14 |
15 | # 效果
16 | 
17 | # 使用
18 |
19 | ## 1.下载jar包
20 | [autoSign-1.0.jar](https://github.com/zhuguohui/autoSignApk/blob/master/jar/autoSign-1.0.jar)
21 | ## 2.编写配置文件
22 |
23 | ```json
24 | {
25 | "signToolsPath": "D:\\Android\\SDK\\build-tools\\33.0.2\\apksigner.bat",
26 | "alignToolsPath":"D:\\Android\\SDK\\build-tools\\33.0.2\\zipalign.exe",
27 | "signConfigs": [{
28 | "appId": "com.aaa.bbb.ccc",
29 | "storePath": ".\\keysotres\\abc.jks",
30 | "storePassword": "abc",
31 | "keyAlias": "abc",
32 | "aliasPassword": "abc"
33 | }]
34 | }
35 | ```
36 | ### 参数说明
37 | | 字段名称 | 作用|
38 | |--|--|
39 | | signToolsPath | 签名工具地址,使用的是apksigner,在sdk下build-tools中。
例如: D:\\Android\\SDK\\build-tools\\33.0.2\\apksigner.bat |
40 | |signConfigs|用于配置单个的签名配置项|
41 | |appId|应用id |
42 | |storePath|签名文件地址|
43 | |storePassword|签名文件密码|
44 | |keyAlias|别名|
45 | |aliasPassword|别名密码|
46 | ## 3.使用bat启动
47 | 将以下命令放置在一个bat文件中。即可。其中 **-configFilePath** 后面接着的是上面的配置文件的地址。
48 | ```java
49 | start /min "cmd" java -jar autoSign-1.1.jar -configFilePath .\signConfig.json
50 | ```
51 | ## 直接拖入
52 | 拖入apk以后会自动解析出包名,然后通过配置文件签名。最后在apk原来的位置生成一个名字为 xxx-signed.apk
53 | 还会有一个idsig文件,这是V4签名生成的。可以不用
54 | 
55 | # 签名工具
56 | 使用的是 **apksigner**
57 | 文档地址
58 | [Android 开发者 apksigner](https://developer.android.google.cn/studio/command-line/apksigner?hl=zh-cn)
59 | 
60 | ## 签名版本
61 | 通过 --min-sdk-version 和 --max-sdk-version 的值来决定何时采用此签名方案
62 | 
63 | 而这两个值,通过解析apk文件获得
64 | 
65 | 所以兼容性没问题。
66 |
67 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'application'
4 | }
5 |
6 | group 'com.zgh.app'
7 | version '1.0'
8 |
9 | jar {
10 | //详细信息参考 https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html
11 | archivesBaseName = 'autoSign'//基本的文件名
12 | archiveVersion = '1.1' //版本
13 | manifest { //配置jar文件的manifest
14 | attributes(
15 | "Manifest-Version": 1.1,
16 | 'Main-Class': 'org.example.Main' //指定main方法所在的文件
17 | )
18 | }
19 | //打包依赖包
20 | from {
21 | (configurations.runtimeClasspath).collect {
22 | it.isDirectory() ? it : zipTree(it)
23 | }
24 | }
25 | }
26 |
27 |
28 | repositories {
29 | mavenCentral()
30 | }
31 |
32 | dependencies {
33 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
34 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
35 | implementation 'net.dongliu:apk-parser:2.6.10'
36 | implementation 'com.google.code.gson:gson:2.10.1'
37 | }
38 |
39 | test {
40 | useJUnitPlatform()
41 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhuguohui/autoSignApk/0d1d36f98c17b1f280a4c4c68ba9b657589e2103/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | #
21 | # Gradle start up script for POSIX generated by Gradle.
22 | #
23 | # Important for running:
24 | #
25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
26 | # noncompliant, but you have some other compliant shell such as ksh or
27 | # bash, then to run this script, type that shell name before the whole
28 | # command line, like:
29 | #
30 | # ksh Gradle
31 | #
32 | # Busybox and similar reduced shells will NOT work, because this script
33 | # requires all of these POSIX shell features:
34 | # * functions;
35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37 | # * compound commands having a testable exit status, especially «case»;
38 | # * various built-in commands including «command», «set», and «ulimit».
39 | #
40 | # Important for patching:
41 | #
42 | # (2) This script targets any POSIX shell, so it avoids extensions provided
43 | # by Bash, Ksh, etc; in particular arrays are avoided.
44 | #
45 | # The "traditional" practice of packing multiple parameters into a
46 | # space-separated string is a well documented source of bugs and security
47 | # problems, so this is (mostly) avoided, by progressively accumulating
48 | # options in "$@", and eventually passing that to Java.
49 | #
50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
52 | # see the in-line comments for details.
53 | #
54 | # There are tweaks for specific operating systems such as AIX, CygWin,
55 | # Darwin, MinGW, and NonStop.
56 | #
57 | # (3) This script is generated from the Groovy template
58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59 | # within the Gradle project.
60 | #
61 | # You can find Gradle at https://github.com/gradle/gradle/.
62 | #
63 | ##############################################################################
64 |
65 | # Attempt to set APP_HOME
66 |
67 | # Resolve links: $0 may be a link
68 | app_path=$0
69 |
70 | # Need this for daisy-chained symlinks.
71 | while
72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
73 | [ -h "$app_path" ]
74 | do
75 | ls=$( ls -ld "$app_path" )
76 | link=${ls#*' -> '}
77 | case $link in #(
78 | /*) app_path=$link ;; #(
79 | *) app_path=$APP_HOME$link ;;
80 | esac
81 | done
82 |
83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
84 |
85 | APP_NAME="Gradle"
86 | APP_BASE_NAME=${0##*/}
87 |
88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
90 |
91 | # Use the maximum available, or set MAX_FD != -1 to use that value.
92 | MAX_FD=maximum
93 |
94 | warn () {
95 | echo "$*"
96 | } >&2
97 |
98 | die () {
99 | echo
100 | echo "$*"
101 | echo
102 | exit 1
103 | } >&2
104 |
105 | # OS specific support (must be 'true' or 'false').
106 | cygwin=false
107 | msys=false
108 | darwin=false
109 | nonstop=false
110 | case "$( uname )" in #(
111 | CYGWIN* ) cygwin=true ;; #(
112 | Darwin* ) darwin=true ;; #(
113 | MSYS* | MINGW* ) msys=true ;; #(
114 | NONSTOP* ) nonstop=true ;;
115 | esac
116 |
117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
118 |
119 |
120 | # Determine the Java command to use to start the JVM.
121 | if [ -n "$JAVA_HOME" ] ; then
122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
123 | # IBM's JDK on AIX uses strange locations for the executables
124 | JAVACMD=$JAVA_HOME/jre/sh/java
125 | else
126 | JAVACMD=$JAVA_HOME/bin/java
127 | fi
128 | if [ ! -x "$JAVACMD" ] ; then
129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
130 |
131 | Please set the JAVA_HOME variable in your environment to match the
132 | location of your Java installation."
133 | fi
134 | else
135 | JAVACMD=java
136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137 |
138 | Please set the JAVA_HOME variable in your environment to match the
139 | location of your Java installation."
140 | fi
141 |
142 | # Increase the maximum file descriptors if we can.
143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144 | case $MAX_FD in #(
145 | max*)
146 | MAX_FD=$( ulimit -H -n ) ||
147 | warn "Could not query maximum file descriptor limit"
148 | esac
149 | case $MAX_FD in #(
150 | '' | soft) :;; #(
151 | *)
152 | ulimit -n "$MAX_FD" ||
153 | warn "Could not set maximum file descriptor limit to $MAX_FD"
154 | esac
155 | fi
156 |
157 | # Collect all arguments for the java command, stacking in reverse order:
158 | # * args from the command line
159 | # * the main class name
160 | # * -classpath
161 | # * -D...appname settings
162 | # * --module-path (only if needed)
163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
164 |
165 | # For Cygwin or MSYS, switch paths to Windows format before running java
166 | if "$cygwin" || "$msys" ; then
167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
169 |
170 | JAVACMD=$( cygpath --unix "$JAVACMD" )
171 |
172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
173 | for arg do
174 | if
175 | case $arg in #(
176 | -*) false ;; # don't mess with options #(
177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
178 | [ -e "$t" ] ;; #(
179 | *) false ;;
180 | esac
181 | then
182 | arg=$( cygpath --path --ignore --mixed "$arg" )
183 | fi
184 | # Roll the args list around exactly as many times as the number of
185 | # args, so each arg winds up back in the position where it started, but
186 | # possibly modified.
187 | #
188 | # NB: a `for` loop captures its iteration list before it begins, so
189 | # changing the positional parameters here affects neither the number of
190 | # iterations, nor the values presented in `arg`.
191 | shift # remove old arg
192 | set -- "$@" "$arg" # push replacement arg
193 | done
194 | fi
195 |
196 | # Collect all arguments for the java command;
197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
198 | # shell script including quotes and variable substitutions, so put them in
199 | # double quotes to make sure that they get re-expanded; and
200 | # * put everything else in single quotes, so that it's not re-expanded.
201 |
202 | set -- \
203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
204 | -classpath "$CLASSPATH" \
205 | org.gradle.wrapper.GradleWrapperMain \
206 | "$@"
207 |
208 | # Use "xargs" to parse quoted args.
209 | #
210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
211 | #
212 | # In Bash we could simply go:
213 | #
214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
215 | # set -- "${ARGS[@]}" "$@"
216 | #
217 | # but POSIX shell has neither arrays nor command substitution, so instead we
218 | # post-process each arg (as a line of input to sed) to backslash-escape any
219 | # character that might be a shell metacharacter, then use eval to reverse
220 | # that process (while maintaining the separation between arguments), and wrap
221 | # the whole thing up as a single "set" statement.
222 | #
223 | # This will of course break if any of these variables contains a newline or
224 | # an unmatched quote.
225 | #
226 |
227 | eval "set -- $(
228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
229 | xargs -n1 |
230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
231 | tr '\n' ' '
232 | )" '"$@"'
233 |
234 | exec "$JAVACMD" "$@"
235 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/jar/autoSign-1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhuguohui/autoSignApk/0d1d36f98c17b1f280a4c4c68ba9b657589e2103/jar/autoSign-1.1.jar
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'AutoSign'
2 |
3 |
--------------------------------------------------------------------------------
/src/main/java/org/example/ApkUtil.java:
--------------------------------------------------------------------------------
1 | package org.example;
2 |
3 | import net.dongliu.apk.parser.ApkFile;
4 | import net.dongliu.apk.parser.bean.ApkMeta;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 |
9 | public class ApkUtil {
10 | public static ApkMeta getPackInfo(String path) throws IOException {
11 |
12 | File file = new File(path);
13 | if (file.exists() && file.isFile()) {
14 | ApkFile apkFile = new ApkFile(file);
15 | ApkMeta apkMeta = apkFile.getApkMeta();
16 | /* System.out.println("应用名称 :" + apkMeta.getLabel());
17 | System.out.println("包名 :" + apkMeta.getPackageName());
18 | System.out.println("版本号 :" + apkMeta.getVersionName());
19 | System.out.println("图标 :" + apkMeta.getIcon());
20 | System.out.println("大小 :" + (double) (file.length() * 100 / 1024 / 1024) / 100 + " MB");*/
21 | return apkMeta;
22 | //注释:apk所有信息都在apkMeta类里面。可以输出整个apkMeta来查看跟多详情信息
23 | }
24 |
25 | return null;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/org/example/Main.java:
--------------------------------------------------------------------------------
1 | package org.example;
2 |
3 | import net.dongliu.apk.parser.bean.ApkMeta;
4 | import org.example.cmd.CmdUtil;
5 | import org.example.config.SignConfigFile;
6 | import org.example.config.SignConfigsBean;
7 | import org.example.file.FileUtil;
8 | import org.example.function.Action;
9 | import org.example.function.Action2;
10 | import org.example.ui.FilePathFrame;
11 | import org.example.ui.Log;
12 |
13 | import java.io.File;
14 | import java.io.IOException;
15 |
16 | import static org.example.file.FileUtil.getOutPath;
17 | import static org.example.file.FileUtil.getOutPathInTemp;
18 |
19 | public class Main {
20 | public static void main(String[] args) {
21 |
22 | FilePathFrame jFrame=new FilePathFrame();
23 | //从args中读取config;
24 | jFrame.setVisible(true);
25 | Log log=jFrame;
26 | String configPath=getConfigPathFromArgs(args);
27 | if(isEmpty(configPath)){
28 | log.e("没有配置 签名配置文件,无法使用");
29 | return;
30 | }
31 | SignConfigFile signConfigFile=null;
32 | try {
33 | signConfigFile=SignConfigFile.create(configPath);
34 | } catch (Exception e) {
35 | String action= "读取配置文件失败:位置:"+configPath;
36 | showError(log,action,e);
37 | }
38 | if(signConfigFile==null){
39 | return;
40 | }
41 | log.i("拖入apk文件 自动签名");
42 |
43 | SignConfigFile finalSignConfigFile = signConfigFile;
44 | jFrame.setFilePathGetFunction(str->{
45 | doAlign(log,str,finalSignConfigFile,(outPath,signedApkPath)->{
46 | doSign(log,outPath,signedApkPath, finalSignConfigFile);
47 | });
48 | return null;
49 | });
50 | }
51 |
52 | /**
53 | * 对文件进行对齐
54 | * 官方解释:
55 | * 如果以 Android 11(API 级别 30)或更高版本为目标平台的应用包含压缩的 resources.arsc
56 | * 文件或者如果此文件未按 4 字节边界对齐,应用将无法安装。如果存在其中任意一种情况,系统将无法对此文件进行内存映射。
57 | * 无法进行内存映射的资源表必须读入 RAM 中的缓冲区,从而给系统造成不必要的内存压力,并大大增加设备的 RAM 使用量
58 | * 原文链接:https://blog.csdn.net/qq_23045311/article/details/125814795
59 | * @param log
60 | * @param apkPath
61 | * @param configFile
62 | * @param successCall
63 | */
64 | private static void doAlign(Log log, String apkPath, SignConfigFile configFile, Action2 successCall){
65 | String outPath = getOutPathInTemp(apkPath, "zipAlign");
66 | boolean executeSuccess=false;
67 | try{
68 | String alignCmdStr = configFile.getAlignCmdStr(apkPath, outPath);
69 | executeSuccess= CmdUtil.executive(alignCmdStr,log);
70 | if(!executeSuccess){
71 | throw new RuntimeException("执行对齐命令失败:命令为"+alignCmdStr);
72 | }
73 | //成功
74 | if(successCall!=null){
75 | String signedApkPath= FileUtil.getOutPath(apkPath,"signed");
76 | successCall.call(outPath,signedApkPath);
77 | }
78 |
79 | }catch (Exception e){
80 | log.e("对齐失败:"+e.getMessage());
81 | }finally {
82 | //删除文件
83 | FileUtil.doDeleteFile(outPath);
84 | }
85 |
86 | }
87 |
88 |
89 |
90 |
91 |
92 | private static void doSign(Log log, String apkPath,String signedApkPath, SignConfigFile configFile) {
93 | ApkMeta apkInfo=null;
94 | try {
95 | apkInfo= ApkUtil.getPackInfo(apkPath);
96 | } catch (IOException e) {
97 | showError(log,"解析apk出错,位置:"+apkPath,e);
98 | }
99 | if(apkInfo==null){
100 | return;
101 | }
102 | log.i("应用名称:"+apkInfo.getName());
103 | log.i("应用包名:"+apkInfo.getPackageName());
104 | SignConfigsBean configsBean= configFile.getConfigBeanByPackageName(apkInfo.getPackageName());
105 | if(configsBean==null){
106 | log.e("没有对应包名的配置信息");
107 | return;
108 | }
109 |
110 | SignConfigsBean.CmdInfo cmdInfo = null;
111 | try{
112 | cmdInfo=configsBean.buildSignCommand(apkPath, signedApkPath);
113 | }catch (Exception e){
114 | showError(log,"生成签名命令失败",e);
115 | return;
116 | }
117 |
118 | boolean executeSuccess=false;
119 | try {
120 | executeSuccess= CmdUtil.executive(cmdInfo.getCmd(),log);
121 | } catch (Exception e) {
122 | showError(log,"执行命令失败,命令为:"+cmdInfo.getCmd(),e);
123 | }
124 | if(executeSuccess){
125 | log.i("签名成功");
126 | log.i("文件保存在:"+cmdInfo.getOutPath());
127 | }
128 |
129 |
130 | }
131 |
132 | private static void showError(Log log,String action,Exception e){
133 | log.e(action);
134 | log.e("错误详情:");
135 | log.e(e.getMessage());
136 | e.printStackTrace();
137 | }
138 |
139 | private static boolean isEmpty(String info){
140 | return info==null||info.length()==0;
141 | }
142 |
143 | private static final String CONFIG_KEY="-configFilePath";
144 | private static String getConfigPathFromArgs(String[] args) {
145 | if(args==null||args.length==0){
146 | return null;
147 | }
148 | String configFilePath=null;
149 | for(int i=0;i=0){
17 | baos.write(buffer,0,len);
18 | }
19 | String str = baos.toString();
20 | baos.close();
21 | fis.close();
22 | SignConfigFile signConfigFile = gson.fromJson(str, SignConfigFile.class);
23 | signConfigFile.setFilePath(path);
24 | return signConfigFile;
25 | }
26 |
27 | String filePath;
28 |
29 | private void setFilePath(String filePath) {
30 | this.filePath = filePath;
31 | }
32 |
33 | public String getFilePath() {
34 | return filePath;
35 | }
36 |
37 | /**
38 | * signToolsPath : D:\Android\SDKuild-tools\33.0.2\apksigner.bat
39 | * signConfigs : [{"appId":"com.wznews.news.app","path":"E:\\Desktop\\apk\\keysotres\\wzrb.jks","storePassword":"monsoon","keyAlias":"myandroidkey","aliasPassword":"monsoon"}]
40 | */
41 |
42 | private String signToolsPath;
43 |
44 | //对齐工具的路径地址;一般在SDK\build-tools\33.0.2(最新的sdkVersion)\zipalign.exe
45 | private String alignToolsPath;
46 | private List signConfigs;
47 |
48 | private String getSignToolsPath() {
49 | return signToolsPath;
50 | }
51 | private static final String ALIGN_CMD_TEMPLATE = "%s -p -f -v 4 %s %s";
52 |
53 | /**
54 | * 获取用来压缩的命令
55 | * @param inputApkPath
56 | * @return
57 | */
58 | public String getAlignCmdStr(String inputApkPath,String outApkPath){
59 | if(alignToolsPath==null||alignToolsPath.length()==0){
60 | throw new RuntimeException("alignToolsPath 没有配置 无法对齐apk");
61 | }
62 | return String.format(ALIGN_CMD_TEMPLATE, alignToolsPath, inputApkPath, outApkPath);
63 | }
64 |
65 |
66 |
67 |
68 | public SignConfigsBean getConfigBeanByPackageName(String packageName) {
69 | if(packageName==null||packageName.isEmpty()){
70 | throw new RuntimeException("传入的包名为空");
71 | }
72 | if(signConfigs==null||signConfigs.size()==0){
73 | return null;
74 | }
75 | for(SignConfigsBean bean:signConfigs){
76 | if(packageName.equals(bean.getAppId())){
77 | bean.setSignToolsPath(getSignToolsPath());
78 | bean.setConfigFilePath(filePath);
79 | return bean;
80 | }
81 | }
82 | return null;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/org/example/config/SignConfigsBean.java:
--------------------------------------------------------------------------------
1 | package org.example.config;
2 |
3 |
4 | import java.io.File;
5 | import java.io.Serializable;
6 |
7 | public class SignConfigsBean implements Serializable {
8 | /**
9 | * appId : com.wznews.news.app
10 | * path : E:\Desktop\apk\keysotres\wzrb.jks
11 | * storePassword : monsoon
12 | * keyAlias : myandroidkey
13 | * aliasPassword : monsoon
14 | */
15 |
16 | private String appId;
17 | private String storePath;
18 | private String storePassword;
19 | private String keyAlias;
20 | private String aliasPassword;
21 | private String signToolsPath;
22 |
23 | private String configFilePath;
24 |
25 |
26 | public String getAppId() {
27 | return appId;
28 | }
29 |
30 | void setSignToolsPath(String signToolsPath) {
31 | this.signToolsPath = signToolsPath;
32 | }
33 |
34 | void setConfigFilePath(String configFilePath) {
35 | this.configFilePath = configFilePath;
36 | }
37 |
38 | /**
39 | * D:\Android\SDK\build-tools\33.0.2\apksigner.bat sign --ks E:\Desktop\apk\keysotres\wzrb.jks --ks-pass pass:xxx --ks-key-alias aaa --key-pass pass:xxx --out E:\Desktop\apk\wd_signed.apk E:\Desktop\apk\wd.apk
40 | */
41 |
42 | private static final String CMD_TEMPLATE = "%s sign --v3-signing-enabled false --v4-signing-enabled false --ks %s --ks-pass pass:%s --ks-key-alias %s --key-pass pass:%s --out %s %s";
43 |
44 | /**
45 | * 生成签名的命令
46 | *
47 | * @param apkPath 应用的地址
48 | * @param signSuffix 签名以后的后缀,比如后缀是xxx。原来的apk名称为。a.apk,签名以后
49 | * 在原来的位置生成的apk的名字为a_xxx.apk
50 | * @return 生成的签名命令
51 | */
52 | public CmdInfo buildSignCommand(String apkPath, String signedApkPath) {
53 |
54 |
55 | String cmd = String.format(CMD_TEMPLATE,
56 | signToolsPath,
57 | storePath,
58 | storePassword,
59 | keyAlias,
60 | aliasPassword,
61 | signedApkPath,
62 | apkPath);
63 | //如果包含相对路径的话比如./就替换为配置文件的父路径
64 | File file=new File(configFilePath);
65 | String parentPath= file.getParent()+"\\";
66 |
67 | cmd= cmd.replace(".\\",parentPath);
68 | return new CmdInfo(cmd, signedApkPath);
69 | }
70 |
71 | public static class CmdInfo {
72 | String cmd;
73 | String outPath;
74 |
75 | public CmdInfo(String cmd, String outPath) {
76 | this.cmd = cmd;
77 | this.outPath = outPath;
78 | }
79 |
80 | public String getCmd() {
81 | return cmd;
82 | }
83 |
84 | public String getOutPath() {
85 | return outPath;
86 | }
87 | }
88 |
89 | private static String getOutPath(String apkPath, String signSuffix) {
90 | int index = apkPath.lastIndexOf(".");
91 | return apkPath.substring(0, index) + "_" + signSuffix + ".apk";
92 | }
93 |
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/java/org/example/file/FileUtil.java:
--------------------------------------------------------------------------------
1 | package org.example.file;
2 |
3 | import java.io.File;
4 | import java.nio.file.Files;
5 | import java.nio.file.Path;
6 | import java.nio.file.Paths;
7 | import java.util.concurrent.ExecutorService;
8 | import java.util.concurrent.Executors;
9 |
10 | public class FileUtil {
11 |
12 | static ExecutorService executor = Executors.newSingleThreadExecutor();
13 |
14 | public static String getOutPath(String apkPath, String signSuffix) {
15 | int index = apkPath.lastIndexOf(".");
16 | return apkPath.substring(0, index) + "_" + signSuffix + ".apk";
17 | }
18 |
19 |
20 | public static String getOutPathInTemp(String apkPath, String signSuffix) {
21 | int index = apkPath.lastIndexOf(".");
22 | // 获取系统默认的临时文件路径
23 |
24 | Path tempDirPath = Paths.get(System.getProperty("java.io.tmpdir"));
25 | String str= apkPath.substring(0, index) + "_" + signSuffix + ".apk";
26 | str= str.substring(str.lastIndexOf("\\"));
27 | String outPath= tempDirPath + str;
28 | File file=new File(outPath);
29 | if(file.exists()){
30 | file.delete();
31 | }
32 | return outPath;
33 | }
34 |
35 |
36 |
37 | public static void doDeleteFile(String path) {
38 | File file = new File(path);
39 | if (file.exists()) {
40 | //删除临时的对齐文件
41 | boolean delete = file.delete();
42 | if (!delete) {
43 | //可能文件被占用,隔断时间再去删除
44 | executor.submit(() -> {
45 | try {
46 | Thread.sleep(1000);
47 | } catch (InterruptedException e) {
48 | throw new RuntimeException(e);
49 | }
50 | doDeleteFile(path);
51 | });
52 | }
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/example/function/Action.java:
--------------------------------------------------------------------------------
1 | package org.example.function;
2 |
3 | public interface Action {
4 | void call(T t);
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/org/example/function/Action2.java:
--------------------------------------------------------------------------------
1 | package org.example.function;
2 |
3 | public interface Action2 {
4 | void call(T1 t1,T2 t2);
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/org/example/function/Function.java:
--------------------------------------------------------------------------------
1 | package org.example.function;
2 |
3 | public interface Function {
4 | R call(T t);
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/org/example/function/Function2.java:
--------------------------------------------------------------------------------
1 | package org.example.function;
2 |
3 | public interface Function2 {
4 | R call(T1 t1,T2 t2);
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/org/example/ui/FilePathFrame.java:
--------------------------------------------------------------------------------
1 | package org.example.ui;
2 |
3 | import org.example.function.Function;
4 |
5 | import javax.swing.*;
6 | import javax.swing.text.BadLocationException;
7 | import javax.swing.text.Document;
8 | import javax.swing.text.SimpleAttributeSet;
9 | import javax.swing.text.StyleConstants;
10 | import java.awt.*;
11 | import java.awt.datatransfer.DataFlavor;
12 | import java.awt.datatransfer.Transferable;
13 |
14 | public class FilePathFrame extends JFrame implements Log {
15 | Function filePathGetFunction;
16 | private JTextPane jText;
17 | private StringBuilder builder;
18 |
19 | public FilePathFrame( ) throws HeadlessException {
20 | builder=new StringBuilder();
21 | setUI();
22 | }
23 |
24 | public void setFilePathGetFunction(Function filePathGetFunction) {
25 | this.filePathGetFunction = filePathGetFunction;
26 | }
27 |
28 | private void setUI(){
29 | setSize(600,500);
30 | setResizable(false);
31 | setTitle("自动签名工具");
32 | setLocationRelativeTo(null);
33 | setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
34 | //JscrollPanne 实现自动滚动
35 |
36 |
37 | jText = new JTextPane();
38 | jText.setEditable(false);
39 | Font font = new Font("Default", Font.BOLD, 15 );
40 | jText.setFont(font);
41 |
42 | JScrollPane pane = new JScrollPane(jText);
43 | pane.setPreferredSize(new Dimension(600,500));
44 | add(pane,BorderLayout.CENTER);
45 |
46 |
47 |
48 | jText.setTransferHandler(new TransferHandler(){
49 | public boolean importData(JComponent comp, Transferable t) {
50 | try {
51 | Object o = t.getTransferData(DataFlavor.javaFileListFlavor);
52 |
53 | String filepath = o.toString();
54 | if (filepath.startsWith("[")) {
55 | filepath = filepath.substring(1);
56 | }
57 | if (filepath.endsWith("]")) {
58 | filepath = filepath.substring(0, filepath.length() - 1);
59 | }
60 | i(filepath);
61 | if(filePathGetFunction!=null){
62 | filePathGetFunction.call(filepath);
63 | }
64 |
65 | return true;
66 | }
67 | catch (Exception e) {
68 | e.printStackTrace();
69 | }
70 | return false;
71 | }
72 |
73 | @Override
74 | public boolean canImport(JComponent comp, DataFlavor[] flavors) {
75 | return true;
76 | }
77 |
78 |
79 | });
80 |
81 | }
82 |
83 |
84 | @Override
85 | public void i(String info) {
86 | insertString(info,Color.BLACK);
87 | }
88 |
89 | private void insertString(String info,Color color){
90 | info="\n"+info;
91 | SimpleAttributeSet attrSet = new SimpleAttributeSet();
92 | StyleConstants.setForeground(attrSet, color);
93 | Document document = jText.getDocument();
94 | try {
95 | document.insertString(document.getLength(),info,attrSet);
96 | //自动滚动到结尾
97 | jText.setCaretPosition(document.getLength());
98 | } catch (BadLocationException e) {
99 | throw new RuntimeException(e);
100 | }
101 | }
102 |
103 | @Override
104 | public void e(String info) {
105 | insertString(info,Color.RED);
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/src/main/java/org/example/ui/Log.java:
--------------------------------------------------------------------------------
1 | package org.example.ui;
2 |
3 | public interface Log {
4 | void i(String info);
5 | void e(String info);
6 | }
7 |
--------------------------------------------------------------------------------