1k-patching-native-modules

Patches native modules (expo-image, react-native, etc.) to fix native crashes or bugs.

16 stars

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

$curl -o ~/.claude/skills/1k-patching-native-modules/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/development/1k-patching-native-modules/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/1k-patching-native-modules/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How 1k-patching-native-modules Compares

Feature / Agent1k-patching-native-modulesStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/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

ai-native-product-building

16
from diegosouzapw/awesome-omni-skill

Rapidly build, prototype, and deploy full-stack software using AI "text-to-app" tools. Use this when you need to create a greenfield application, build a high-fidelity working prototype for user testing, or bypass traditional engineering bottlenecks for internal tools.

review-agent-native

16
from diegosouzapw/awesome-omni-skill

Use this skill when reviewing code to ensure features are agent-native - that any action a user can take, an agent can also take, and anything a user can see, an agent can see. This enforces the principle that agents should have parity with users in capability and context.

native-data-fetching

16
from diegosouzapw/awesome-omni-skill

Use when implementing or debugging ANY network request, API call, or data fetching. Covers fetch API, axios, React Query, SWR, error handling, caching strategies, offline support.

dispatching-parallel-agents

16
from diegosouzapw/awesome-omni-skill

Use when facing 3+ independent failures that can be investigated without shared state or dependencies. Dispatches multiple Claude agents to investigate and fix independent problems concurrently.

agent-native-reviewer

16
from diegosouzapw/awesome-omni-skill

Use this agent when reviewing code changes to ensure features are agent-native - any action a user can take, an agent can also take, and anything a user can see, an agent can see. Triggers on requests like "agent-native review", "AI accessibility check".

agent-native-architecture

16
from diegosouzapw/awesome-omni-skill

Build applications where agents are first-class citizens. Use this skill when designing autonomous agents, creating MCP tools, implementing self-modifying systems, or building apps where features are outcomes achieved by agents operating in a loop.

activation-patching

16
from diegosouzapw/awesome-omni-skill

Causal intervention via activation patching to identify important model components. Use when determining which layers, heads, or positions are causally responsible for model behavior.

competitor-alternatives

16
from diegosouzapw/awesome-omni-skill

When the user wants to create competitor comparison or alternative pages for SEO and sales enablement. Also use when the user mentions 'alternative page,' 'vs page,' 'competitor comparison,' 'compa...

ai-native-development

16
from diegosouzapw/awesome-omni-skill

Build AI-first applications with RAG pipelines, embeddings, vector databases, agentic workflows, and LLM integration. Master prompt engineering, function calling, streaming responses, and cost optimization for 2025+ AI development.

bgo

10
from diegosouzapw/awesome-omni-skill

Automates the complete Blender build-go workflow, from building and packaging your extension/add-on to removing old versions, installing, enabling, and launching Blender for quick testing and iteration.

Coding & Development

agentuity-cli-cloud-apikey-get

16
from diegosouzapw/awesome-omni-skill

Get a specific API key by id. Requires authentication. Use for Agentuity cloud platform operations

agentstack-server-debugging

16
from diegosouzapw/awesome-omni-skill

Instructions for debugging agentstack-server during development