-
-
Notifications
You must be signed in to change notification settings - Fork 218
config: Android: 16 KB page size #3565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ajaysehwal
wants to merge
2
commits into
ZeusLN:master
Choose a base branch
from
ajaysehwal:android-16kb
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| #!/bin/bash | ||
| progname="${0##*/}" | ||
| progname="${progname%.sh}" | ||
|
|
||
| # usage: check_elf_alignment.sh [path to *.so files|path to *.apk] | ||
|
|
||
| cleanup_trap() { | ||
| if [ -n "${tmp}" -a -d "${tmp}" ]; then | ||
| rm -rf ${tmp} | ||
| fi | ||
| exit $1 | ||
| } | ||
|
|
||
| usage() { | ||
| echo "Host side script to check the ELF alignment of shared libraries." | ||
| echo "Shared libraries are reported ALIGNED when their ELF regions are" | ||
| echo "16 KB or 64 KB aligned. Otherwise they are reported as UNALIGNED." | ||
| echo | ||
| echo "Usage: ${progname} [input-path|input-APK|input-APEX]" | ||
| } | ||
|
|
||
| if [ ${#} -ne 1 ]; then | ||
| usage | ||
| exit | ||
| fi | ||
|
|
||
| case ${1} in | ||
| --help | -h | -\?) | ||
| usage | ||
| exit | ||
| ;; | ||
|
|
||
| *) | ||
| dir="${1}" | ||
| ;; | ||
| esac | ||
|
|
||
| if ! [ -f "${dir}" -o -d "${dir}" ]; then | ||
| echo "Invalid file: ${dir}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ "${dir}" == *.apk ]]; then | ||
| trap 'cleanup_trap' EXIT | ||
|
|
||
| echo | ||
| echo "Recursively analyzing $dir" | ||
| echo | ||
|
|
||
| if { zipalign --help 2>&1 | grep -q "\-P <pagesize_kb>"; }; then | ||
| echo "=== APK zip-alignment ===" | ||
| zipalign -v -c -P 16 4 "${dir}" | egrep 'lib/arm64-v8a|lib/x86_64|Verification' | ||
| echo "=========================" | ||
| else | ||
| echo "NOTICE: Zip alignment check requires build-tools version 35.0.0-rc3 or higher." | ||
| echo " You can install the latest build-tools by running the below command" | ||
| echo " and updating your \$PATH:" | ||
| echo | ||
| echo " sdkmanager \"build-tools;35.0.0-rc3\"" | ||
| fi | ||
|
|
||
| dir_filename=$(basename "${dir}") | ||
| tmp=$(mktemp -d -t "${dir_filename%.apk}_out_XXXXX") | ||
| unzip "${dir}" lib/* -d "${tmp}" >/dev/null 2>&1 | ||
| dir="${tmp}" | ||
| fi | ||
|
|
||
| if [[ "${dir}" == *.apex ]]; then | ||
| trap 'cleanup_trap' EXIT | ||
|
|
||
| echo | ||
| echo "Recursively analyzing $dir" | ||
| echo | ||
|
|
||
| dir_filename=$(basename "${dir}") | ||
| tmp=$(mktemp -d -t "${dir_filename%.apex}_out_XXXXX") | ||
| deapexer extract "${dir}" "${tmp}" || { echo "Failed to deapex." && exit 1; } | ||
| dir="${tmp}" | ||
| fi | ||
|
|
||
| RED="\e[31m" | ||
| GREEN="\e[32m" | ||
| ENDCOLOR="\e[0m" | ||
|
|
||
| unaligned_libs=() | ||
|
|
||
| echo | ||
| echo "=== ELF alignment ===" | ||
|
|
||
| matches="$(find "${dir}" -type f)" | ||
| IFS=$'\n' | ||
| for match in $matches; do | ||
| # We could recursively call this script or rewrite it to though. | ||
| [[ "${match}" == *".apk" ]] && echo "WARNING: doesn't recursively inspect .apk file: ${match}" | ||
| [[ "${match}" == *".apex" ]] && echo "WARNING: doesn't recursively inspect .apex file: ${match}" | ||
|
|
||
| [[ $(file "${match}") == *"ELF"* ]] || continue | ||
|
|
||
| res="$(objdump -p "${match}" | grep LOAD | awk '{ print $NF }' | head -1)" | ||
| if [[ $res =~ 2\*\*(1[4-9]|[2-9][0-9]|[1-9][0-9]{2,}) ]]; then | ||
| echo -e "${match}: ${GREEN}ALIGNED${ENDCOLOR} ($res)" | ||
| else | ||
| echo -e "${match}: ${RED}UNALIGNED${ENDCOLOR} ($res)" | ||
| unaligned_libs+=("${match}") | ||
| fi | ||
| done | ||
|
|
||
| if [ ${#unaligned_libs[@]} -gt 0 ]; then | ||
| echo -e "${RED}Found ${#unaligned_libs[@]} unaligned libs (only arm64-v8a/x86_64 libs need to be aligned).${ENDCOLOR}" | ||
| elif [ -n "${dir_filename}" ]; then | ||
| echo -e "ELF Verification Successful" | ||
| fi | ||
| echo "=====================" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Prevent crash when VisionCamera native library cannot be loaded on the device/ABI. | ||
| // This repo targets 16KB page-size compliance; some prebuilt native libs may not load on | ||
| // certain emulator/device setups. | ||
|
|
||
| import fs from 'fs'; | ||
|
|
||
| export function patchVisionCamera() { | ||
| const cameraPackagePath = | ||
| './node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/react/CameraPackage.kt'; | ||
|
|
||
| if (!fs.existsSync(cameraPackagePath)) { | ||
| console.log('Patching react-native-vision-camera'); | ||
| console.log(' - Skipping: CameraPackage.kt not found'); | ||
| return; | ||
| } | ||
|
|
||
| console.log('Patching react-native-vision-camera'); | ||
|
|
||
| let content = fs.readFileSync(cameraPackagePath, 'utf8'); | ||
|
|
||
| // Guard native module creation so an UnsatisfiedLinkError in VisionCamera's static init | ||
| // doesn't crash the whole app at startup. | ||
| if (!content.includes('catch (e: UnsatisfiedLinkError)')) { | ||
| content = content.replace( | ||
| /override fun createNativeModules\(reactContext: ReactApplicationContext\): List<NativeModule> =\n\s*listOf\(\n\s*CameraViewModule\(reactContext\),\n\s*CameraDevicesManager\(reactContext\)\n\s*\)/m, | ||
| `override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> = | ||
| try { | ||
| listOf( | ||
| CameraViewModule(reactContext), | ||
| CameraDevicesManager(reactContext) | ||
| ) | ||
| } catch (e: UnsatisfiedLinkError) { | ||
| // VisionCamera native lib failed to load. Disable camera modules instead of crashing. | ||
| emptyList() | ||
| }` | ||
| ); | ||
| } | ||
|
|
||
| fs.writeFileSync(cameraPackagePath, content); | ||
| console.log(' - Guarded CameraPackage.kt createNativeModules()'); | ||
| } | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make this script more robust, I recommend adding
set -euo pipefailat the beginning.set -e: Exits the script immediately if any command fails. This would prevent the script from providing a misleading 'success' message if, for example, theunzipcommand at line 64 fails.set -u: Treats unset variables as an error, which helps catch typos in variable names.set -o pipefail: Ensures that a pipeline's exit code is the exit code of the rightmost command to exit with a non-zero status, or zero if all commands of the pipeline exit successfully.This is a standard best practice for writing safer shell scripts.