1k-patching-native-modules
Patches native modules (expo-image, react-native, etc.) to fix native crashes or bugs.
Best use case
1k-patching-native-modules is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Patches native modules (expo-image, react-native, etc.) to fix native crashes or bugs.
Teams using 1k-patching-native-modules should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/1k-patching-native-modules/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How 1k-patching-native-modules Compares
| Feature / Agent | 1k-patching-native-modules | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Patches native modules (expo-image, react-native, etc.) to fix native crashes or bugs.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Patching Native Modules
Follow this workflow to analyze crash logs, fix native module bugs, and generate patches.
## Workflow Overview
```
1. Analyze Crash Log → 2. Locate Bug → 3. Fix Code → 4. Clean Build Artifacts → 5. Generate Patch → 6. Commit & PR
```
## Step 1: Analyze Crash Log
### iOS Crash (EXC_BAD_ACCESS / KERN_INVALID_ADDRESS)
Key information to extract:
- **Exception type**: `EXC_BAD_ACCESS`, `SIGABRT`, etc.
- **Stack trace**: Identify the crashing function
- **Memory address**: Helps identify nil pointer issues
- **Library**: Which native module is crashing
Example crash pattern:
```
EXC_BAD_ACCESS: KERN_INVALID_ADDRESS at 0x3c61c1a3b0d0
objc_msgSend in unknown file
-[SDWebImageManager cacheKeyForURL:context:] ← Crashing function
-[SDWebImageManager loadImageWithURL:options:context:progress:completed:]
```
### Android Crash (NullPointerException / OOM)
Look for:
- **Exception class**: `NullPointerException`, `OutOfMemoryError`
- **Stack trace**: Java/Kotlin method chain
- **Thread info**: Main thread vs background
## Step 2: Locate the Bug
### Find native module source
```bash
# iOS (Swift/Objective-C)
ls node_modules/<package>/ios/
# Android (Kotlin/Java)
ls node_modules/<package>/android/src/main/java/
```
### Common crash causes
| Crash Type | Common Cause | Fix Pattern |
|------------|--------------|-------------|
| `EXC_BAD_ACCESS` | Nil pointer dereference | Add `guard let` check |
| `KERN_INVALID_ADDRESS` | Accessing deallocated memory | Use weak references |
| `NullPointerException` | Null object access | Add null check |
| `OutOfMemoryError` | Large image/data processing | Add size limits |
## Step 3: Fix the Code
### iOS (Swift) - Nil Check Pattern
```swift
// 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, ...)
```
### Android (Kotlin) - Null Check Pattern
```kotlin
// Before
val uri = source.uri
loadImage(uri)
// After
val uri = source.uri ?: return
if (uri.toString().isEmpty()) return
loadImage(uri)
```
## Step 4: Clean Build Artifacts (CRITICAL)
**Before generating patch, MUST clean Android build cache:**
```bash
# 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
```
Why this matters:
- Android build generates `.class`, `.jar`, binary files
- These pollute the patch file (can grow to 5000+ lines)
- patch-package will include these unwanted files
## Step 5: Generate Patch
```bash
# Generate patch file
npx patch-package <package-name>
# Example:
npx patch-package expo-image
```
Patch file location: `patches/<package-name>+<version>.patch`
### Verify patch content
```bash
# 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
```
## Step 6: Commit & Create PR
```bash
# 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
```
## Common Packages & Their Native Locations
| Package | iOS Source | Android Source |
|---------|------------|----------------|
| `expo-image` | `node_modules/expo-image/ios/` | `node_modules/expo-image/android/src/` |
| `react-native` | `node_modules/react-native/React/` | `node_modules/react-native/ReactAndroid/` |
| `@react-native-async-storage/async-storage` | `node_modules/@react-native-async-storage/async-storage/ios/` | `...android/src/` |
| `react-native-reanimated` | `node_modules/react-native-reanimated/ios/` | `...android/src/` |
## Existing Patches Reference
Check existing patches for patterns:
```bash
ls patches/
cat patches/expo-image+3.0.10.patch
```
## Troubleshooting
### Patch file too large
```bash
# 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>
```
### Patch not applying
```bash
# 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.patch
```
### Swift/Kotlin syntax help
**Swift guard let:**
```swift
guard let value = optionalValue else {
return // Must exit scope
}
// value is now non-optional
```
**Kotlin null check:**
```kotlin
val value = nullableValue ?: return
// value is now non-null
```
## Related Files
- Patches directory: `patches/`
- expo-image iOS: `node_modules/expo-image/ios/ImageView.swift`
- expo-image Android: `node_modules/expo-image/android/src/main/java/expo/modules/image/`Related Skills
activation-patching
Causal intervention via activation patching to identify important model components. Use when determining which layers, heads, or positions are causally responsible for model behavior.
ux
This AI agent skill provides comprehensive guidance for creating professional and insightful User Experience (UX) designs, covering user research, information architecture, interaction design, visual guidance, and usability evaluation. It aims to produce actionable, user-centered solutions that avoid generic AI aesthetics.
ontopo
An AI agent skill to search for Israeli restaurants, check table availability, view menus, and retrieve booking links via the Ontopo platform, acting as an unofficial interface to its data.
lets-go-rss
A lightweight, full-platform RSS subscription manager that aggregates content from YouTube, Vimeo, Behance, Twitter/X, and Chinese platforms like Bilibili, Weibo, and Douyin, featuring deduplication and AI smart classification.
tech-blog
Generates comprehensive technical blog posts, offering detailed explanations of system internals, architecture, and implementation, either through source code analysis or document-driven research.
whisper-transcribe
Transcribes audio and video files to text using OpenAI's Whisper CLI, enhanced with contextual grounding from local markdown files for improved accuracy.
vly-money
Generate crypto payment links for supported tokens and networks, manage access to X402 payment-protected content, and provide direct access to the vly.money wallet interface.
thor-skills
An entry point and router for AI agents to manage various THOR-related cybersecurity tasks, including running scans, analyzing logs, troubleshooting, and maintenance.
grail-miner
This skill assists in setting up, managing, and optimizing Grail miners on Bittensor Subnet 81, handling tasks like environment configuration, R2 storage, model checkpoint management, and performance tuning.
chrome-debug
This skill empowers AI agents to debug web applications and inspect browser behavior using the Chrome DevTools Protocol (CDP), offering both collaborative (headful) and automated (headless) modes.
modal-deployment
Run Python code in the cloud with serverless containers, GPUs, and autoscaling using Modal. This skill enables agents to generate code for deploying ML models, running batch jobs, serving APIs, and scaling compute-intensive workloads.
astro
This skill provides essential Astro framework patterns, focusing on server-side rendering (SSR), static site generation (SSG), middleware, and TypeScript best practices. It helps AI agents implement secure authentication, manage API routes, and debug rendering behaviors within Astro projects.