Read props directly in Gradle

This commit is contained in:
topjohnwu 2018-08-20 12:02:38 +08:00
parent c0b750a09a
commit c19b78180c
3 changed files with 44 additions and 73 deletions

View File

@ -1,5 +1,8 @@
apply plugin: 'com.android.application'
def configProps = new Properties()
configProps.load(new FileInputStream(rootProject.file('config.prop')))
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
@ -10,11 +13,21 @@ android {
targetSdkVersion rootProject.ext.compileSdkVersion
}
signingConfigs {
config {
storeFile rootProject.file('release-key.jks')
storePassword configProps['keyStorePass']
keyAlias configProps['keyAlias']
keyPassword configProps['keyPass']
}
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
}
@ -22,8 +35,8 @@ android {
productFlavors {
full {
versionCode 134
versionName "5.8.3"
versionName configProps['appVersion']
versionCode configProps['appVersionCode'] as Integer
javaCompileOptions {
annotationProcessorOptions {
argument('butterknife.debuggable', 'false')

View File

@ -123,29 +123,6 @@ def sign_zip(unsigned, output, release):
if proc.returncode != 0:
error('Signing zip failed!')
def sign_apk(source, target):
# Find the latest build tools
build_tool = os.path.join(os.environ['ANDROID_HOME'], 'build-tools',
sorted(os.listdir(os.path.join(os.environ['ANDROID_HOME'], 'build-tools')))[-1])
proc = execv([os.path.join(build_tool, 'zipalign'), '-vpf', '4', source, target], subprocess.DEVNULL)
if proc.returncode != 0:
error('Zipalign Magisk Manager failed!')
# Find apksigner.jar
apksigner = ''
for root, dirs, files in os.walk(build_tool):
if 'apksigner.jar' in files:
apksigner = os.path.join(root, 'apksigner.jar')
break
if not apksigner:
error('Cannot find apksigner.jar in Android SDK build tools')
proc = execv(['java', '-jar', apksigner, 'sign', '--ks', keystore, '--ks-pass', 'pass:' + config['keyStorePass'],
'--ks-key-alias', config['keyAlias'], '--key-pass', 'pass:' + config['keyPass'], target])
if proc.returncode != 0:
error('Release sign Magisk Manager failed!')
def binary_dump(src, out, var_name):
out.write('const static unsigned char {}[] = {{'.format(var_name))
for i, c in enumerate(xz(src.read())):
@ -244,60 +221,37 @@ def build_binary(args):
error('Build binaries failed!')
collect_binary()
def build_apk(args):
header('* Building Magisk Manager')
def build_apk(args, flavor):
header('* Building {} Magisk Manager'.format(flavor))
buildType = 'Release' if args.release else 'Debug'
proc = execv([gradlew, 'app:assemble' + flavor + buildType])
if proc.returncode != 0:
error('Build Magisk Manager failed!')
flavor = flavor.lower()
buildType = buildType.lower()
apk = 'app-{}-{}.apk'.format(flavor, buildType)
source = os.path.join('app', 'build', 'outputs', 'apk', flavor, buildType, apk)
target = os.path.join(config['outdir'], apk)
mv(source, target)
header('Output: ' + target)
return target
def build_app(args):
source = os.path.join('scripts', 'util_functions.sh')
target = os.path.join('app', 'src', 'full', 'res', 'raw', 'util_functions.sh')
cp(source, target)
if args.release:
proc = execv([gradlew, 'app:assembleFullRelease'])
if proc.returncode != 0:
error('Build Magisk Manager failed!')
source = os.path.join('app', 'build', 'outputs', 'apk', 'full', 'release', 'app-full-release-unsigned.apk')
target = os.path.join(config['outdir'], 'app-release.apk')
sign_apk(source, target)
rm(source)
else:
proc = execv([gradlew, 'app:assembleFullDebug'])
if proc.returncode != 0:
error('Build Magisk Manager failed!')
source = os.path.join('app', 'build', 'outputs', 'apk', 'full', 'debug', 'app-full-debug.apk')
target = os.path.join(config['outdir'], 'app-debug.apk')
mv(source, target)
header('Output: ' + target)
build_apk(args, 'Full')
def build_stub(args):
header('* Building stub Magisk Manager')
if args.release:
proc = execv([gradlew, 'app:assembleStubRelease'])
if proc.returncode != 0:
error('Build stub Magisk Manager failed!')
source = os.path.join('app', 'build', 'outputs', 'apk', 'stub', 'release', 'app-stub-release-unsigned.apk')
target = os.path.join(config['outdir'], 'stub-release.apk')
sign_apk(source, target)
rm(source)
else:
proc = execv([gradlew, 'app:assembleStubDebug'])
if proc.returncode != 0:
error('Build stub Magisk Manager failed!')
source = os.path.join('app', 'build', 'outputs', 'apk', 'stub', 'debug', 'app-stub-debug.apk')
target = os.path.join(config['outdir'], 'stub-debug.apk')
mv(source, target)
header('Output: ' + target)
stub = build_apk(args, 'Stub')
# Dump the stub APK to header
mkdir(os.path.join('native', 'out'))
with open(os.path.join('native', 'out', 'binaries.h'), 'w') as out:
with open(target, 'rb') as src:
with open(stub, 'rb') as src:
binary_dump(src, out, 'manager_xz');
def build_snet(args):
@ -437,7 +391,7 @@ def cleanup(args):
def build_all(args):
vars(args)['target'] = []
build_stub(args)
build_apk(args)
build_apk(args, 'Full')
build_binary(args)
zip_main(args)
zip_uninstaller(args)
@ -481,7 +435,7 @@ binary_parser.add_argument('target', nargs='*', help='Support: magisk, magiskini
binary_parser.set_defaults(func=build_binary)
apk_parser = subparsers.add_parser('apk', help='build Magisk Manager APK')
apk_parser.set_defaults(func=build_apk)
apk_parser.set_defaults(func=build_app)
stub_parser = subparsers.add_parser('stub', help='build stub Magisk Manager APK')
stub_parser.set_defaults(func=build_stub)

View File

@ -1,7 +1,11 @@
# The version string and version code of Magisk
# The version name and version code of Magisk
version=
versionCode=
# The version name and version code of Magisk Manager
appVersion=
appVersionCode=
outdir=out
# Whether use pretty names for zips, e.g. Magisk-v${version}.zip, Magisk-uninstaller-${date}.zip