This document provides project-specific instructions for AI-assisted development on the Android Image Cropper library.
Android Image Cropper optimized image cropping capabilities for Android applications.
- Language: Kotlin 2.0.0
- Build System: Gradle 8.5.2 with Kotlin DSL
- Android: minSdk 21, compileSdk 34, targetSdk 34
- Key Dependencies:
- AndroidX (AppCompat, Core, Activity, ExifInterface)
- Kotlin Coroutines 1.8.1
- Material Components
- Testing: JUnit, MockK, Robolectric, Paparazzi (snapshot testing)
- Code Quality: ktlint 1.3.1, Dokka (documentation)
Android-Image-Cropper/
├── cropper/ # Main library module (published artifact)
│ └── src/
│ ├── main/ # Library source code
│ └── test/ # Unit tests
├── sample/ # Sample app demonstrating usage
│ └── src/main/ # Sample implementations
├── .github/ # CI/CD workflows
└── gradle/ # Build configuration
- Code Style: IntelliJ IDEA
- Indentation: 2 spaces (no tabs)
- Continuation Indent: 2 spaces
- Trailing Commas: Allowed and encouraged
- Line Length: No maximum (disabled)
- Linter: ktlint with experimental features enabled
- Warnings: All Kotlin warnings treated as errors
- Package structure:
com.canhub.cropper.* - Internal APIs: Classes/methods not meant for public use should be marked
internal - Public API: Keep minimal and well-documented
- Deprecated APIs: Mark with
@Deprecatedand provide migration path
- No unused code: Remove unused variables, functions, and imports
- Type safety: Leverage Kotlin's type system
- Null safety: Use Kotlin null-safety features appropriately
- Coroutines: Use for async operations (already in use for bitmap operations)
- Resource management: Always close resources properly (see BitmapUtils)
# Build the project
./gradlew build
# Run all checks (linting, tests, etc.)
./gradlew licensee ktlint testDebug build --stacktrace
# Run unit tests
./gradlew testDebug
# Run ktlint
./gradlew ktlint
# Format code with ktlint
./gradlew ktlintFormat
# Run Paparazzi snapshot tests
./gradlew verifyPaparazziDebug
# Generate documentation
./gradlew dokkaHtml- Branch Naming: Use developer github name
canato/prefix (e.g.,canato/fix-rotation-bug) - Code Changes:
- Make changes in
cropper/module - Update tests as needed
- Update sample app if adding new features
- Make changes in
- Before Committing:
- Run
./gradlew ktlintFormatto auto-format - Run
./gradlew ktlint testDebugto validate - Ensure all tests pass
- Run
- Commit Messages: Follow existing style in CHANGELOG.md
- Start with category: "API:", "Fix:", "Security:", "Technical:", etc.
- Reference issue/PR numbers:
[#123]
- Unit Tests: All business logic should have unit tests
- Location:
cropper/src/test/kotlin/ - Use MockK for mocking
- Use Robolectric for Android framework dependencies
- Location:
- Snapshot Tests: Use Paparazzi for UI component tests
- Sample App: Manual testing via
sample/module - StrictMode: Sample app has StrictMode enabled - no violations allowed
- Avoid breaking changes whenever possible
- If unavoidable:
- Deprecate old API first
- Provide migration guide
- Increment major version
- Update CHANGELOG.md with migration notes
- Mark as
@Deprecatedwith message and replacement - Keep deprecated code for at least one minor version
- Document in CHANGELOG.md
- Update README.md with migration guide
- Remove only in next major version
- Add to public API only if necessary
- Document with KDoc
- Add usage example to sample app
- Update README.md if user-facing
- Consider making
internalif not needed publicly
DO NOT manually trigger releases - handled by maintainer via GitHub Actions.
- Snapshot Releases: Auto-published from
mainbranch to Maven Central - Release Versions:
- Update
VERSION_NAMEingradle.properties - Update
CHANGELOG.md - Tag release
- GitHub Actions publishes to Maven Central
- Update
- Read existing code in
cropper/src/main/kotlin/com/canhub/cropper/ - Understand how
CropImageViewand related classes work - Add feature with appropriate tests
- Update
CropImageOptionsif adding new configuration - Add example to sample app
- Update CHANGELOG.md under "In development" section
- Update README.md if user-facing
- Add a failing test that reproduces the bug
- Fix the bug
- Ensure test passes
- Run full test suite
- Update CHANGELOG.md with fix description and issue number
- Dependencies managed in
gradle/libs.versions.toml - Test thoroughly after updates (especially Android/Kotlin versions)
- Check for API changes in dependencies
- Run full test suite
- Check sample app still works
- Add strings to
cropper/src/main/res/values-{lang}/strings.xml - Copy structure from
values/strings.xml - Test in sample app with device language change
- Update CHANGELOG.md noting new language support
- README.md: User-facing documentation, API examples
- CHANGELOG.md: All changes by version (REQUIRED for every change)
- gradle.properties: Version, Maven coordinates, publishing config
- gradle/libs.versions.toml: Dependency versions catalog
- build.gradle.kts: Root build configuration
- cropper/build.gradle.kts: Library module configuration
- lint.xml: Android Lint configuration
- .editorconfig: Code formatting rules
- .github/workflows/: CI/CD pipelines
- CropImageView: Main public API - the custom view users add to layouts
- CropImageOptions: Configuration data class for cropping behavior
- CropImageActivity: (Deprecated) Activity-based cropping
- CropImageContract: Activity contract for cropping
- CropOverlayView: Internal - handles crop window UI
- BitmapUtils: Internal - image processing utilities
- BitmapCroppingWorkerJob: Internal - async cropping
- BitmapLoadingWorkerJob: Internal - async image loading
- URI Validation: Always validate URIs (see PR #680)
- File Provider: Proper file provider configuration required
- Permissions: Handle camera/storage permissions appropriately
- Input Validation: Validate all user inputs and image dimensions
- Resource Limits: Prevent OOM with large images (sampling is used)
- Clean build:
./gradlew clean build - Check Java version: Requires JDK 11+ (toolchain configured)
- Check Android SDK: Requires SDK 34
- Paparazzi failures: May need to record new snapshots
- Robolectric failures: Check Android version compatibility
- Run
./gradlew ktlintFormatto auto-fix - Check
.editorconfigfor disabled rules - See
lint.xmlfor Android Lint configuration
When working on this project:
- Always read before editing: Use Read tool on files before making changes
- Respect code style: Follow ktlint rules (2-space indent, trailing commas, etc.)
- Update CHANGELOG.md: Every change must be documented
- Test your changes: Add/update tests, run test suite
- Check public API impact: Breaking changes require deprecation cycle
- Update documentation: README.md for user-facing changes
- Security first: Validate inputs, handle errors, prevent security issues
- Performance matters: Large images are common - optimize for memory
- Backward compatibility: Support minSdk 21 (Android 5.0)
- Sample app: Update if adding features users should see
- Architecture questions: Check existing patterns in
CropImageView - API design: Look at existing public APIs in the class
- Testing approach: Check existing tests in
cropper/src/test/ - Dependencies: Check
gradle/libs.versions.tomlfirst - Android compatibility: Remember minSdk is 21
- Sample App: Best reference for library usage
- CHANGELOG.md: History of changes and API evolution
- GitHub Issues: Known bugs and feature requests
- README.md: User documentation and examples
This document is maintained for AI-assisted development. Keep it updated as the project evolves.