Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CMake embeds a digest of these exact source bytes into the prebuilt reader.
# Keep checkouts identical on Windows and Linux so the artifact check is stable.
ohos/entry/src/main/cpp/** text eol=lf
110 changes: 110 additions & 0 deletions .github/workflows/android-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,116 @@ jobs:
exit 1
fi

# Prebuilt plugin JNI can remain 4 KB aligned even with a new NDK.
python3 - "$apk" --zipalign "$(dirname "$aapt")/zipalign" <<'PY_16KB'
#!/usr/bin/env python3
"""Check 64-bit ELF LOAD alignment and uncompressed APK library offsets.

Read-only; uses Python's standard library. Optionally also run SDK zipalign.
This verifies packaging/linker alignment, not runtime page-size assumptions.
"""

import argparse
import struct
import subprocess
import sys
import zipfile
from pathlib import Path

PAGE_SIZE = 16384
MACHINES = {"arm64-v8a": 183, "x86_64": 62}


def check_elf(stream, abi):
header = stream.read(64)
if (len(header) < 64 or header[:4] != b"\x7fELF" or
header[4:6] != b"\x02\x01"):
raise ValueError("expected little-endian ELF64")
if struct.unpack_from("<H", header, 18)[0] != MACHINES[abi]:
raise ValueError("ELF machine does not match APK ABI")
offset = struct.unpack_from("<Q", header, 32)[0]
size, count = struct.unpack_from("<HH", header, 54)
if size < 56 or not 0 < count <= 4096:
raise ValueError("invalid program header table")
stream.seek(offset)
loads = []
for _ in range(count):
entry = stream.read(size)
if len(entry) != size:
raise ValueError("truncated program header table")
if struct.unpack_from("<I", entry)[0] != 1: # PT_LOAD
continue
file_offset, address = struct.unpack_from("<QQ", entry, 8)
alignment = struct.unpack_from("<Q", entry, 48)[0]
if alignment < PAGE_SIZE or alignment & (alignment - 1):
raise ValueError(f"PT_LOAD alignment {alignment} is not 16 KB compatible")
if file_offset % PAGE_SIZE != address % PAGE_SIZE:
raise ValueError("PT_LOAD file offset and virtual address are not congruent")
loads.append(alignment)
if not loads:
raise ValueError("no PT_LOAD segments")
return min(loads)


def library_offset(apk, info):
with apk.open("rb") as stream:
stream.seek(info.header_offset)
header = stream.read(30)
if len(header) != 30 or header[:4] != b"PK\x03\x04":
raise ValueError("invalid ZIP local header")
name_length, extra_length = struct.unpack_from("<HH", header, 26)
return info.header_offset + 30 + name_length + extra_length


def inspect(apk):
failures = []
checked = 0
with zipfile.ZipFile(apk) as archive:
for info in archive.infolist():
parts = info.filename.split("/")
if (len(parts) != 3 or parts[0] != "lib" or
parts[1] not in MACHINES or not parts[2].endswith(".so")):
continue
checked += 1
try:
with archive.open(info) as stream:
alignment = check_elf(stream, parts[1])
packaging = "compressed (extracted at install)"
if info.compress_type == zipfile.ZIP_STORED:
offset = library_offset(apk, info)
if offset % PAGE_SIZE:
raise ValueError(f"uncompressed ZIP data offset {offset} is not 16 KB aligned")
packaging = "ZIP aligned"
print(f"PASS {info.filename}: ELF {alignment}, {packaging}")
except (ValueError, OSError, struct.error) as error:
failures.append(f"FAIL {info.filename}: {error}")
for failure in failures:
print(failure, file=sys.stderr)
print(f"Checked {checked} 64-bit libraries; failures={len(failures)}")
# ARM32-only splits legitimately have no 64-bit libraries.
return not failures


def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("apk", type=Path)
parser.add_argument("--zipalign", type=Path, help="SDK Build-Tools 35+ zipalign executable")
args = parser.parse_args()
try:
passed = inspect(args.apk)
if args.zipalign:
result = subprocess.run([str(args.zipalign), "-c", "-P", "16", "4", str(args.apk)], check=False)
passed = passed and result.returncode == 0
return 0 if passed else 1
except (OSError, ValueError, zipfile.BadZipFile) as error:
print(f"Cannot check APK: {error}", file=sys.stderr)
return 1


if __name__ == "__main__":
sys.exit(main())
PY_16KB

cp "$apk" "dist/TechPie-${RELEASE_NAME}-android-${token}.apk"
}

Expand Down
10 changes: 10 additions & 0 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
allprojects {
configurations.configureEach {
resolutionStrategy.eachDependency {
// The OHOS mobile_scanner fork still requests CameraX 1.3.4,
// whose image-processing JNI library has 4 KB ELF LOAD alignment.
if (requested.group == "androidx.camera" && requested.version == "1.3.4") {
useVersion("1.4.2")
because("CameraX 1.4.2 ships 16 KB aligned JNI libraries")
}
}
}
repositories {
maven(url = "https://maven.aliyun.com/repository/google")
maven(url = "https://maven.aliyun.com/repository/central")
Expand Down
4 changes: 2 additions & 2 deletions ohos/scripts/generate-build-profile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ function generateBuildProfile() {
// Drop the signing block and the product's reference to it: hvigor then has
// nothing to sign with and writes `entry-default-unsigned.hap`.
content = content
.replace(/"signingConfigs":\s*\[[\s\S]*?\n \],\n/, '')
.replace(/"signingConfig": "default",\n/, '');
.replace(/"signingConfigs":\s*\[[\s\S]*?\r?\n \],\r?\n/, '')
.replace(/"signingConfig": "default",\r?\n/, '');
if (content.includes('signingConfig')) {
throw new Error('Could not strip the signing block from the template');
}
Expand Down
5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ flutter_launcher_icons:
android: true
min_sdk_android: 21
adaptive_icon_background: "#FFFFFF"
adaptive_icon_foreground: "assets/icon/icon_foreground.png"
adaptive_icon_monochrome: "assets/icon/icon_monochrome.png"
# Use the source directly: Git symlinks may become text files on Windows.
adaptive_icon_foreground: "assets/icon/icon.png"
adaptive_icon_monochrome: "assets/icon/icon.png"
ios: true
remove_alpha_ios: true
web:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ void main() {
// The trace is the one place allowed to log; its own gate is covered by
// test/campus_card_http_trace_test.dart.
.where(
(file) => !file.path.endsWith('data/api/decrypted_http_trace.dart'),
(file) => !file.path
.replaceAll('\\', '/')
.endsWith('data/api/decrypted_http_trace.dart'),
)) {
expect(
file.readAsStringSync(),
Expand Down
6 changes: 5 additions & 1 deletion test/campus_card/architecture/platform_contract_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ void main() {
);
for (final entity in presentation.listSync(recursive: true)) {
if (entity is! File || !entity.path.endsWith('.dart')) continue;
if (entity.path.endsWith('/icons/platform_icons.dart')) continue;
if (entity.path
.replaceAll('\\', '/')
.endsWith('/icons/platform_icons.dart')) {
continue;
}
expect(
entity.readAsStringSync(),
isNot(contains('CupertinoIcons.')),
Expand Down
Loading