Skip to content

Commit 7ce14f7

Browse files
Canatoclaude
andcommitted
Add CLAUDE.md - AI development guide for Android Image Cropper
- Comprehensive project overview and tech stack - Development workflow and conventions - Build commands and testing strategy - API change guidelines and deprecation process - Security considerations and troubleshooting - AI assistant guidelines Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 4833a5d commit 7ce14f7

1 file changed

Lines changed: 260 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
# Android Image Cropper - Claude AI Development Guide
2+
3+
This document provides project-specific instructions for AI-assisted development on the Android Image Cropper library.
4+
5+
## Project Overview
6+
7+
**Android Image Cropper** optimized image cropping capabilities for Android applications.
8+
9+
## Tech Stack
10+
11+
- **Language**: Kotlin 2.0.0
12+
- **Build System**: Gradle 8.5.2 with Kotlin DSL
13+
- **Android**: minSdk 21, compileSdk 34, targetSdk 34
14+
- **Key Dependencies**:
15+
- AndroidX (AppCompat, Core, Activity, ExifInterface)
16+
- Kotlin Coroutines 1.8.1
17+
- Material Components
18+
- **Testing**: JUnit, MockK, Robolectric, Paparazzi (snapshot testing)
19+
- **Code Quality**: ktlint 1.3.1, Dokka (documentation)
20+
21+
## Module Structure
22+
23+
```
24+
Android-Image-Cropper/
25+
├── cropper/ # Main library module (published artifact)
26+
│ └── src/
27+
│ ├── main/ # Library source code
28+
│ └── test/ # Unit tests
29+
├── sample/ # Sample app demonstrating usage
30+
│ └── src/main/ # Sample implementations
31+
├── .github/ # CI/CD workflows
32+
└── gradle/ # Build configuration
33+
```
34+
35+
## Code Style & Conventions
36+
37+
### Kotlin Style
38+
- **Code Style**: IntelliJ IDEA
39+
- **Indentation**: 2 spaces (no tabs)
40+
- **Continuation Indent**: 2 spaces
41+
- **Trailing Commas**: Allowed and encouraged
42+
- **Line Length**: No maximum (disabled)
43+
- **Linter**: ktlint with experimental features enabled
44+
- **Warnings**: All Kotlin warnings treated as errors
45+
46+
### File Organization
47+
- Package structure: `com.canhub.cropper.*`
48+
- Internal APIs: Classes/methods not meant for public use should be marked `internal`
49+
- Public API: Keep minimal and well-documented
50+
- Deprecated APIs: Mark with `@Deprecated` and provide migration path
51+
52+
### Code Quality Standards
53+
1. **No unused code**: Remove unused variables, functions, and imports
54+
2. **Type safety**: Leverage Kotlin's type system
55+
3. **Null safety**: Use Kotlin null-safety features appropriately
56+
4. **Coroutines**: Use for async operations (already in use for bitmap operations)
57+
5. **Resource management**: Always close resources properly (see BitmapUtils)
58+
59+
## Build & Test Commands
60+
61+
```bash
62+
# Build the project
63+
./gradlew build
64+
65+
# Run all checks (linting, tests, etc.)
66+
./gradlew licensee ktlint testDebug build --stacktrace
67+
68+
# Run unit tests
69+
./gradlew testDebug
70+
71+
# Run ktlint
72+
./gradlew ktlint
73+
74+
# Format code with ktlint
75+
./gradlew ktlintFormat
76+
77+
# Run Paparazzi snapshot tests
78+
./gradlew verifyPaparazziDebug
79+
80+
# Generate documentation
81+
./gradlew dokkaHtml
82+
```
83+
84+
## Development Workflow
85+
86+
### Making Changes
87+
88+
1. **Branch Naming**: Use developer github name `canato/` prefix (e.g., `canato/fix-rotation-bug`)
89+
2. **Code Changes**:
90+
- Make changes in `cropper/` module
91+
- Update tests as needed
92+
- Update sample app if adding new features
93+
3. **Before Committing**:
94+
- Run `./gradlew ktlintFormat` to auto-format
95+
- Run `./gradlew ktlint testDebug` to validate
96+
- Ensure all tests pass
97+
4. **Commit Messages**: Follow existing style in CHANGELOG.md
98+
- Start with category: "API:", "Fix:", "Security:", "Technical:", etc.
99+
- Reference issue/PR numbers: `[#123]`
100+
101+
### Testing Strategy
102+
103+
1. **Unit Tests**: All business logic should have unit tests
104+
- Location: `cropper/src/test/kotlin/`
105+
- Use MockK for mocking
106+
- Use Robolectric for Android framework dependencies
107+
2. **Snapshot Tests**: Use Paparazzi for UI component tests
108+
3. **Sample App**: Manual testing via `sample/` module
109+
4. **StrictMode**: Sample app has StrictMode enabled - no violations allowed
110+
111+
### API Changes
112+
113+
⚠️ **This is a published library** - API changes affect thousands of apps!
114+
115+
#### Breaking Changes
116+
- **Avoid** breaking changes whenever possible
117+
- If unavoidable:
118+
- Deprecate old API first
119+
- Provide migration guide
120+
- Increment major version
121+
- Update CHANGELOG.md with migration notes
122+
123+
#### Deprecation Process
124+
1. Mark as `@Deprecated` with message and replacement
125+
2. Keep deprecated code for at least one minor version
126+
3. Document in CHANGELOG.md
127+
4. Update README.md with migration guide
128+
5. Remove only in next major version
129+
130+
#### Adding New APIs
131+
1. Add to public API only if necessary
132+
2. Document with KDoc
133+
3. Add usage example to sample app
134+
4. Update README.md if user-facing
135+
5. Consider making `internal` if not needed publicly
136+
137+
## Release Process
138+
139+
**DO NOT manually trigger releases** - handled by maintainer via GitHub Actions.
140+
141+
1. **Snapshot Releases**: Auto-published from `main` branch to Maven Central
142+
2. **Release Versions**:
143+
- Update `VERSION_NAME` in `gradle.properties`
144+
- Update `CHANGELOG.md`
145+
- Tag release
146+
- GitHub Actions publishes to Maven Central
147+
148+
## Common Tasks
149+
150+
### Adding a New Feature
151+
1. Read existing code in `cropper/src/main/kotlin/com/canhub/cropper/`
152+
2. Understand how `CropImageView` and related classes work
153+
3. Add feature with appropriate tests
154+
4. Update `CropImageOptions` if adding new configuration
155+
5. Add example to sample app
156+
6. Update CHANGELOG.md under "In development" section
157+
7. Update README.md if user-facing
158+
159+
### Fixing a Bug
160+
1. Add a failing test that reproduces the bug
161+
2. Fix the bug
162+
3. Ensure test passes
163+
4. Run full test suite
164+
5. Update CHANGELOG.md with fix description and issue number
165+
166+
### Updating Dependencies
167+
1. Dependencies managed in `gradle/libs.versions.toml`
168+
2. Test thoroughly after updates (especially Android/Kotlin versions)
169+
3. Check for API changes in dependencies
170+
4. Run full test suite
171+
5. Check sample app still works
172+
173+
### Adding Translations
174+
1. Add strings to `cropper/src/main/res/values-{lang}/strings.xml`
175+
2. Copy structure from `values/strings.xml`
176+
3. Test in sample app with device language change
177+
4. Update CHANGELOG.md noting new language support
178+
179+
## Important Files
180+
181+
- **README.md**: User-facing documentation, API examples
182+
- **CHANGELOG.md**: All changes by version (REQUIRED for every change)
183+
- **gradle.properties**: Version, Maven coordinates, publishing config
184+
- **gradle/libs.versions.toml**: Dependency versions catalog
185+
- **build.gradle.kts**: Root build configuration
186+
- **cropper/build.gradle.kts**: Library module configuration
187+
- **lint.xml**: Android Lint configuration
188+
- **.editorconfig**: Code formatting rules
189+
- **.github/workflows/**: CI/CD pipelines
190+
191+
## Key Classes to Understand
192+
193+
1. **CropImageView**: Main public API - the custom view users add to layouts
194+
2. **CropImageOptions**: Configuration data class for cropping behavior
195+
3. **CropImageActivity**: (Deprecated) Activity-based cropping
196+
4. **CropImageContract**: Activity contract for cropping
197+
5. **CropOverlayView**: Internal - handles crop window UI
198+
6. **BitmapUtils**: Internal - image processing utilities
199+
7. **BitmapCroppingWorkerJob**: Internal - async cropping
200+
8. **BitmapLoadingWorkerJob**: Internal - async image loading
201+
202+
## Security Considerations
203+
204+
⚠️ **Security is critical** - this library handles user content and file URIs.
205+
206+
1. **URI Validation**: Always validate URIs (see PR #680)
207+
2. **File Provider**: Proper file provider configuration required
208+
3. **Permissions**: Handle camera/storage permissions appropriately
209+
4. **Input Validation**: Validate all user inputs and image dimensions
210+
5. **Resource Limits**: Prevent OOM with large images (sampling is used)
211+
212+
## Troubleshooting
213+
214+
### Build Issues
215+
- Clean build: `./gradlew clean build`
216+
- Check Java version: Requires JDK 11+ (toolchain configured)
217+
- Check Android SDK: Requires SDK 34
218+
219+
### Test Failures
220+
- Paparazzi failures: May need to record new snapshots
221+
- Robolectric failures: Check Android version compatibility
222+
223+
### Lint Issues
224+
- Run `./gradlew ktlintFormat` to auto-fix
225+
- Check `.editorconfig` for disabled rules
226+
- See `lint.xml` for Android Lint configuration
227+
228+
## AI Assistant Guidelines
229+
230+
When working on this project:
231+
232+
1. **Always read before editing**: Use Read tool on files before making changes
233+
2. **Respect code style**: Follow ktlint rules (2-space indent, trailing commas, etc.)
234+
3. **Update CHANGELOG.md**: Every change must be documented
235+
4. **Test your changes**: Add/update tests, run test suite
236+
5. **Check public API impact**: Breaking changes require deprecation cycle
237+
6. **Update documentation**: README.md for user-facing changes
238+
7. **Security first**: Validate inputs, handle errors, prevent security issues
239+
8. **Performance matters**: Large images are common - optimize for memory
240+
9. **Backward compatibility**: Support minSdk 21 (Android 5.0)
241+
10. **Sample app**: Update if adding features users should see
242+
243+
### When Uncertain
244+
245+
- **Architecture questions**: Check existing patterns in `CropImageView`
246+
- **API design**: Look at existing public APIs in the class
247+
- **Testing approach**: Check existing tests in `cropper/src/test/`
248+
- **Dependencies**: Check `gradle/libs.versions.toml` first
249+
- **Android compatibility**: Remember minSdk is 21
250+
251+
## Helpful Resources
252+
253+
- **Sample App**: Best reference for library usage
254+
- **CHANGELOG.md**: History of changes and API evolution
255+
- **GitHub Issues**: Known bugs and feature requests
256+
- **README.md**: User documentation and examples
257+
258+
---
259+
260+
*This document is maintained for AI-assisted development. Keep it updated as the project evolves.*

0 commit comments

Comments
 (0)