Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
53904b06
Commit
53904b06
authored
Jul 02, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use gradle magic to optimize resources
parent
cef14d45
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
38 deletions
+25
-38
build.gradle
build.gradle
+24
-0
build.py
build.py
+1
-38
No files found.
build.gradle
View file @
53904b06
import
java.nio.file.Paths
// Top-level build file where you can add configuration options common to all sub-projects/modules.
def
props
=
new
Properties
()
...
...
@@ -61,6 +63,28 @@ subprojects {
}
}
tasks
.
whenTaskAdded
{
task
->
if
(
task
.
name
==
'processReleaseResources'
)
{
task
.
finalizedBy
tasks
.
create
(
'optimizeReleaseResources'
)
{
doLast
{
def
aapt2
=
Paths
.
get
(
android
.
sdkDirectory
.
path
,
'build-tools'
,
android
.
buildToolsVersion
,
'aapt2'
)
def
zip
=
Paths
.
get
(
project
.
buildDir
.
path
,
'intermediates'
,
'processed_res'
,
'release'
,
'out'
,
'resources-release.ap_'
)
def
optimized
=
new
File
(
"${zip}.opt"
)
def
cmd
=
exec
{
commandLine
aapt2
,
'optimize'
,
'--collapse-resource-names'
,
'--shorten-resource-paths'
,
'-o'
,
optimized
,
zip
ignoreExitValue
true
}
if
(
cmd
.
exitValue
==
0
)
{
optimized
.
renameTo
(
"$zip"
)
}
}
}
}
}
if
(
getPlugins
().
hasPlugin
(
'java'
))
{
tasks
.
withType
(
JavaCompile
)
{
// If building with JDK 9+, we need additional flags to generate compatible bytecode
...
...
build.py
View file @
53904b06
...
...
@@ -57,12 +57,10 @@ default_targets = ['magisk', 'magiskinit', 'magiskboot', 'busybox']
ndk_ver
=
'21c'
ndk_ver_full
=
'21.2.6472646'
build_tools_ver
=
'30.0.0'
ndk_root
=
op
.
join
(
os
.
environ
[
'ANDROID_HOME'
],
'ndk'
)
ndk_path
=
op
.
join
(
ndk_root
,
'magisk'
)
ndk_build
=
op
.
join
(
ndk_path
,
'ndk-build'
)
build_tools
=
op
.
join
(
os
.
environ
[
'ANDROID_HOME'
],
'build-tools'
,
build_tools_ver
)
gradlew
=
op
.
join
(
'.'
,
'gradlew'
+
(
'.bat'
if
is_windows
else
''
))
# Global vars
...
...
@@ -345,42 +343,7 @@ def build_apk(args, module):
source
=
op
.
join
(
module
,
'build'
,
'outputs'
,
'apk'
,
build_type
,
apk
)
target
=
op
.
join
(
config
[
'outdir'
],
apk
)
if
args
.
release
:
zipalign
=
op
.
join
(
build_tools
,
'zipalign'
+
(
'.exe'
if
is_windows
else
''
))
aapt2
=
op
.
join
(
build_tools
,
'aapt2'
+
(
'.exe'
if
is_windows
else
''
))
apksigner
=
op
.
join
(
build_tools
,
'apksigner'
+
(
'.bat'
if
is_windows
else
''
))
try
:
with
tempfile
.
NamedTemporaryFile
(
delete
=
False
)
as
f
:
tmp
=
f
.
name
# AAPT2 optimization
execv
([
aapt2
,
'optimize'
,
'-o'
,
tmp
,
'--collapse-resource-names'
,
'--shorten-resource-paths'
,
source
])
# Recompress everything just to piss people off
with
zipfile
.
ZipFile
(
source
,
'w'
,
compression
=
zipfile
.
ZIP_DEFLATED
)
as
zout
:
with
zipfile
.
ZipFile
(
tmp
)
as
zin
:
for
e
in
zin
.
namelist
():
zout
.
writestr
(
e
,
zin
.
read
(
e
))
# Zipalign
execv
([
zipalign
,
'-f'
,
'4'
,
source
,
target
])
# Sign APK
execv
([
apksigner
,
'sign'
,
'--v4-signing-enabled'
,
'false'
,
'--v1-signer-name'
,
'CERT'
,
'--ks'
,
config
[
'keyStore'
],
'--ks-pass'
,
f
'pass:{config["keyStorePass"]}'
,
'--ks-key-alias'
,
config
[
'keyAlias'
],
'--key-pass'
,
f
'pass:{config["keyPass"]}'
,
target
])
finally
:
rm
(
tmp
)
rm
(
source
)
else
:
mv
(
source
,
target
)
mv
(
source
,
target
)
header
(
'Output: '
+
target
)
return
target
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment