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

View File

@ -14,7 +14,7 @@ android {
externalNativeBuild { externalNativeBuild {
ndkBuild { ndkBuild {
// Pass arguments to ndk-build. // 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') 'MAGISK_VER_CODE=99999', 'MAGISK_DEBUG=-DMAGISK_DEBUG')
} }
} }

View File

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

View File

@ -1,5 +1,10 @@
APP_ABI := x86 armeabi-v7a APP_ABI := x86 armeabi-v7a
APP_PLATFORM := android-21 APP_CFLAGS := -std=gnu99 ${MAGISK_DEBUG} \
APP_CFLAGS := -std=gnu99 -DMAGISK_VERSION="${MAGISK_VERSION}" -DMAGISK_VER_CODE=${MAGISK_VER_CODE}
APP_CPPFLAGS := -std=c++11 APP_CPPFLAGS := -std=c++11
APP_SHORT_COMMANDS := true 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/simple_encoder.c \
xz/src/liblzma/simple/sparc.c \ xz/src/liblzma/simple/sparc.c \
xz/src/liblzma/simple/x86.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) include $(BUILD_STATIC_LIBRARY)
# libsepol.a # libsepol.a

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