Use lower API level for static binaries

This commit is contained in:
topjohnwu 2018-05-13 05:22:46 +08:00
parent c6d2bf577f
commit c3c78428c4
6 changed files with 38 additions and 24 deletions

View File

@ -104,17 +104,35 @@ def build_binary(args):
os.utime(os.path.join('native', 'jni', 'include', 'logging.h'))
# Basic flags
flags = 'MAGISK_VERSION=\"{}\" MAGISK_VER_CODE={} MAGISK_DEBUG={}'.format(config['version'], config['versionCode'],
base_flags = 'MAGISK_VERSION=\"{}\" MAGISK_VER_CODE={} MAGISK_DEBUG={}'.format(config['version'], config['versionCode'],
'' if args.release else '-DMAGISK_DEBUG')
if 'magisk' in args.target:
# Magisk is special case as it is a dependency of magiskinit
proc = subprocess.run('{} -C native {} B_MAGISK=true -j{}'.format(ndk_build, flags, cpu_count), shell=True)
proc = subprocess.run('{} -C native {} B_MAGISK=1 -j{}'.format(ndk_build, base_flags, cpu_count), shell=True)
if proc.returncode != 0:
error('Build Magisk binary failed!')
collect_binary()
non_magisk = False
old_platform = False
flags = base_flags
if 'busybox' in args.target:
flags += ' B_BB=1'
old_platform = True
if 'b64xz' in args.target:
flags += ' B_BXZ=1'
old_platform = True
if old_platform:
proc = subprocess.run('{} -C native OLD_PLAT=1 {} -j{}'.format(ndk_build, flags, cpu_count), shell=True)
if proc.returncode != 0:
error('Build binaries failed!')
collect_binary()
other = False
flags = base_flags
if 'magiskinit' in args.target:
# We need to create dump.h beforehand
@ -127,22 +145,14 @@ def build_binary(args):
dump.write('const uint8_t magisk_dump[] = "')
dump.write(''.join("\\x{:02X}".format(c) for c in lzma.compress(bin.read(), preset=9)))
dump.write('";\n')
flags += ' B_INIT=true'
non_magisk = True
flags += ' B_INIT=1'
other = True
if 'magiskboot' in args.target:
flags += ' B_BOOT=true'
non_magisk = True
flags += ' B_BOOT=1'
other = True
if 'busybox' in args.target:
flags += ' B_BB=true'
non_magisk = True
if 'b64xz' in args.target:
flags += ' B_BXZ=true'
non_magisk = True
if non_magisk:
if other:
proc = subprocess.run('{} -C native {} -j{}'.format(ndk_build, flags, cpu_count), shell=True)
if proc.returncode != 0:
error('Build binaries failed!')
@ -369,7 +379,7 @@ def cleanup(args):
if 'binary' in args.target:
header('* Cleaning binaries')
subprocess.run(ndk_build + ' -C native B_MAGISK=true B_INIT=true B_BOOT=true B_BXZ=true B_BB=true clean', shell=True)
subprocess.run(ndk_build + ' -C native B_MAGISK=1 B_INIT=1 B_BOOT=1 B_BXZ=1 B_BB=1 clean', shell=True)
shutil.rmtree(os.path.join('native', 'out'), ignore_errors=True)
if 'java' in args.target:

View File

@ -14,7 +14,7 @@ android {
externalNativeBuild {
ndkBuild {
// Pass arguments to ndk-build.
arguments('B_MAGISK=true', 'B_INIT=true', 'B_BOOT=true', 'MAGISK_VERSION=debug',
arguments('B_MAGISK=1', 'B_INIT=1', 'B_BOOT=1', 'MAGISK_VERSION=debug',
'MAGISK_VER_CODE=99999', 'MAGISK_DEBUG=-DMAGISK_DEBUG')
}
}

View File

@ -57,8 +57,7 @@ LOCAL_SRC_FILES := \
su/su_socket.c \
$(UTIL_SRC)
LOCAL_CFLAGS := -DIS_DAEMON -DSELINUX ${MAGISK_DEBUG} \
-DMAGISK_VERSION="${MAGISK_VERSION}" -DMAGISK_VER_CODE=${MAGISK_VER_CODE}
LOCAL_CFLAGS := -DIS_DAEMON -DSELINUX
LOCAL_LDLIBS := -llog
include $(BUILD_EXECUTABLE)

View File

@ -1,5 +1,10 @@
APP_ABI := x86 armeabi-v7a
APP_PLATFORM := android-21
APP_CFLAGS := -std=gnu99
APP_CFLAGS := -std=gnu99 ${MAGISK_DEBUG} \
-DMAGISK_VERSION="${MAGISK_VERSION}" -DMAGISK_VER_CODE=${MAGISK_VER_CODE}
APP_CPPFLAGS := -std=c++11
APP_SHORT_COMMANDS := true
ifdef OLD_PLAT
APP_PLATFORM := android-9
else
APP_PLATFORM := android-21
endif

View File

@ -175,7 +175,7 @@ LOCAL_SRC_FILES := \
xz/src/liblzma/simple/simple_encoder.c \
xz/src/liblzma/simple/sparc.c \
xz/src/liblzma/simple/x86.c
LOCAL_CFLAGS += -DHAVE_CONFIG_H -std=c99
LOCAL_CFLAGS += -DHAVE_CONFIG_H -Wno-implicit-function-declaration
include $(BUILD_STATIC_LIBRARY)
# libsepol.a

@ -1 +1 @@
Subproject commit 4f5bf4ad8361c46441db19bd61605d0de324f19e
Subproject commit 869ebbfa97d9b47b2707adb10a01d1bfacd52191