Switch to use ONDK

This commit is contained in:
topjohnwu 2022-04-15 10:04:04 -07:00 committed by John Wu
parent a609e0aad4
commit 3358eab991
4 changed files with 19 additions and 33 deletions

View File

@ -12,8 +12,7 @@ import subprocess
import sys import sys
import textwrap import textwrap
import urllib.request import urllib.request
import zipfile import tarfile
from distutils.dir_util import copy_tree
def error(str): def error(str):
@ -309,9 +308,11 @@ def dump_flag_header():
def build_binary(args): def build_binary(args):
# Verify NDK install # Verify NDK install
props = parse_props(op.join(ndk_path, 'source.properties')) try:
if props['Pkg.Revision'] != config['fullNdkVersion']: with open(op.join(ndk_path, 'ONDK_VERSION'), 'r') as ondk_ver:
error('Incorrect NDK. Please install/upgrade NDK with "build.py ndk"') assert ondk_ver.read().strip(' \t\r\n') == config['ondkVersion']
except:
error('Unmatched NDK. Please install/upgrade NDK with "build.py ndk"')
if 'target' not in vars(args): if 'target' not in vars(args):
vars(args)['target'] = [] vars(args)['target'] = []
@ -416,30 +417,17 @@ def cleanup(args):
def setup_ndk(args): def setup_ndk(args):
os_name = platform.system().lower() os_name = platform.system().lower()
ndk_ver = config['ndkVersion'] ndk_ver = config['ondkVersion']
url = f'https://dl.google.com/android/repository/android-ndk-r{ndk_ver}-{os_name}.zip' url = f'https://github.com/topjohnwu/ondk/releases/download/{ndk_ver}/ondk-{ndk_ver}-{os_name}.tar.gz'
ndk_zip = url.split('/')[-1] ndk_archive = url.split('/')[-1]
header(f'* Downloading {ndk_zip}') header(f'* Downloading and extracting {ndk_archive}')
with urllib.request.urlopen(url) as response, open(ndk_zip, 'wb') as out_file: with urllib.request.urlopen(url) as response:
shutil.copyfileobj(response, out_file) with tarfile.open(mode='r|gz', fileobj=response) as tar:
tar.extractall(ndk_root)
header('* Extracting NDK zip')
rm_rf(ndk_path) rm_rf(ndk_path)
with zipfile.ZipFile(ndk_zip, 'r') as zf: mv(op.join(ndk_root, f'ondk-{ndk_ver}'), ndk_path)
for info in zf.infolist():
vprint(f'Extracting {info.filename}')
if info.external_attr >> 28 == 0xA: # symlink
src = zf.read(info).decode("utf-8")
dest = op.join(ndk_root, info.filename)
os.symlink(src, dest)
continue
extracted_path = zf.extract(info, ndk_root)
if info.create_system == 3: # ZIP_UNIX_SYSTEM = 3
unix_attributes = info.external_attr >> 16
if unix_attributes:
os.chmod(extracted_path, unix_attributes)
mv(op.join(ndk_root, f'android-ndk-r{ndk_ver}'), ndk_path)
header('* Patching static libs') header('* Patching static libs')
for target in ['aarch64-linux-android', 'arm-linux-androideabi', for target in ['aarch64-linux-android', 'arm-linux-androideabi',
@ -452,8 +440,7 @@ def setup_ndk(args):
continue continue
src_dir = op.join('tools', 'ndk-bins', '21', arch) src_dir = op.join('tools', 'ndk-bins', '21', arch)
rm(op.join(src_dir, '.DS_Store')) rm(op.join(src_dir, '.DS_Store'))
for path in copy_tree(src_dir, lib_dir): shutil.copytree(src_dir, lib_dir, copy_function=cp, dirs_exist_ok=True)
vprint(f'Replaced {path}')
def setup_avd(args): def setup_avd(args):

View File

@ -29,5 +29,4 @@ android.nonTransitiveRClass=true
# Magisk # Magisk
magisk.stubVersion=27 magisk.stubVersion=27
magisk.versionCode=24306 magisk.versionCode=24306
magisk.ndkVersion=23b magisk.ondkVersion=r24.1
magisk.fullNdkVersion=23.1.7779620

View File

@ -248,7 +248,7 @@ LOCAL_SRC_FILES := \
selinux/libsepol/cil/src/cil_verify.c \ selinux/libsepol/cil/src/cil_verify.c \
selinux/libsepol/cil/src/cil_write_ast.c selinux/libsepol/cil/src/cil_write_ast.c
LOCAL_CFLAGS := -Dgetline=__getline -Wno-implicit-function-declaration LOCAL_CFLAGS := -Wno-unused-but-set-variable
include $(BUILD_STATIC_LIBRARY) include $(BUILD_STATIC_LIBRARY)
# libselinux.a # libselinux.a
@ -260,7 +260,7 @@ LOCAL_EXPORT_C_INCLUDES := $(LIBSELINUX)
LOCAL_STATIC_LIBRARIES := libpcre2 LOCAL_STATIC_LIBRARIES := libpcre2
LOCAL_CFLAGS := \ LOCAL_CFLAGS := \
-Wno-implicit-function-declaration -Wno-int-conversion -Wno-unused-function \ -Wno-implicit-function-declaration -Wno-int-conversion -Wno-unused-function \
-Wno-macro-redefined -D_GNU_SOURCE -DUSE_PCRE2 \ -Wno-macro-redefined -Wno-unused-but-set-variable -D_GNU_SOURCE -DUSE_PCRE2 \
-DNO_PERSISTENTLY_STORED_PATTERNS -DDISABLE_SETRANS -DDISABLE_BOOL \ -DNO_PERSISTENTLY_STORED_PATTERNS -DDISABLE_SETRANS -DDISABLE_BOOL \
-DNO_MEDIA_BACKEND -DNO_X_BACKEND -DNO_DB_BACKEND -DNO_ANDROID_BACKEND \ -DNO_MEDIA_BACKEND -DNO_X_BACKEND -DNO_DB_BACKEND -DNO_ANDROID_BACKEND \
-Dfgets_unlocked=fgets -D'__fsetlocking(...)=' -Dfgets_unlocked=fgets -D'__fsetlocking(...)='

@ -1 +1 @@
Subproject commit 0aa67c3ffea069bdb58fe3b5e7aad06934afb292 Subproject commit 9b40e8b93627e0aef4ee8ad1b9f3aea913ee32c0