Loading...
Loading...
Patches native modules (expo-image, react-native, etc.) to fix native crashes or bugs.
npx skill4agent add onekeyhq/app-monorepo 1k-patching-native-modules1. Analyze Crash Log → 2. Locate Bug → 3. Fix Code → 4. Clean Build Artifacts → 5. Generate Patch → 6. Commit & PREXC_BAD_ACCESSSIGABRTEXC_BAD_ACCESS: KERN_INVALID_ADDRESS at 0x3c61c1a3b0d0
objc_msgSend in unknown file
-[SDWebImageManager cacheKeyForURL:context:] ← Crashing function
-[SDWebImageManager loadImageWithURL:options:context:progress:completed:]NullPointerExceptionOutOfMemoryError# iOS (Swift/Objective-C)
ls node_modules/<package>/ios/
# Android (Kotlin/Java)
ls node_modules/<package>/android/src/main/java/| Crash Type | Common Cause | Fix Pattern |
|---|---|---|
| Nil pointer dereference | Add |
| Accessing deallocated memory | Use weak references |
| Null object access | Add null check |
| Large image/data processing | Add size limits |
// Before (crashes when uri is nil)
imageManager.loadImage(with: source.uri, ...)
// After (safe)
guard let sourceUri = source.uri, !sourceUri.absoluteString.isEmpty else {
onError(["error": "Image source URI is nil or empty"])
return
}
imageManager.loadImage(with: sourceUri, ...)// Before
val uri = source.uri
loadImage(uri)
// After
val uri = source.uri ?: return
if (uri.toString().isEmpty()) return
loadImage(uri)# Remove Android build artifacts to avoid polluting the patch
rm -rf node_modules/<package>/android/build
# For expo-image specifically:
rm -rf node_modules/expo-image/android/build.class.jar# Generate patch file
npx patch-package <package-name>
# Example:
npx patch-package expo-imagepatches/<package-name>+<version>.patch# Check patch doesn't include unwanted files
grep -c "android/build" patches/<package-name>*.patch
# Should return 0
# View actual changes
head -100 patches/<package-name>*.patch# Stage patch file
git add patches/<package-name>*.patch
# Commit with descriptive message
git commit -m "fix(ios): prevent EXC_BAD_ACCESS crash in <package> when <condition>
Add guard checks in <package> native layer to prevent crash when <scenario>.
Fixes Sentry issue #XXXXX"
# Create PR
gh pr create --title "fix(ios): <description>" --base x| Package | iOS Source | Android Source |
|---|---|---|
| | |
| | |
| | |
| | |
ls patches/
cat patches/expo-image+3.0.10.patch# Clean all build artifacts
rm -rf node_modules/<package>/android/build
rm -rf node_modules/<package>/ios/build
rm -rf node_modules/<package>/.gradle
# Regenerate
npx patch-package <package># Check package version matches
cat node_modules/<package>/package.json | grep version
# Rename patch if version changed
mv patches/<package>+old.patch patches/<package>+new.patchguard let value = optionalValue else {
return // Must exit scope
}
// value is now non-optionalval value = nullableValue ?: return
// value is now non-nullpatches/node_modules/expo-image/ios/ImageView.swiftnode_modules/expo-image/android/src/main/java/expo/modules/image/