|
1 | 1 | # Instructions for AIs
|
2 | 2 |
|
3 |
| -This repository is .NET for Android. |
4 |
| - |
5 |
| -This is the main branch targeting .NET 10. |
| 3 | +This repository is **.NET for Android** (formerly Xamarin.Android), the open-source bindings and tooling for Android development using .NET languages like C#. |
| 4 | + |
| 5 | +This is the main branch targeting **.NET 10**. |
| 6 | + |
| 7 | +## Repository Overview |
| 8 | + |
| 9 | +.NET for Android provides: |
| 10 | +- Android SDK bindings in C# (`src/Mono.Android/`) |
| 11 | +- MSBuild tasks for building Android apps (`src/Xamarin.Android.Build.Tasks/`) |
| 12 | +- Native runtime components (`src/native/`) |
| 13 | +- Build tooling and infrastructure (`build-tools/`) |
| 14 | +- Comprehensive test suite (`tests/`) |
| 15 | + |
| 16 | +### Key Directories |
| 17 | +- `bin/`: Build output (Debug/Release configurations) |
| 18 | +- `src/`: Main redistributable source code |
| 19 | +- `tests/`: Unit tests and integration tests |
| 20 | +- `build-tools/`: Build-time-only tooling |
| 21 | +- `external/`: Git submodules (Java.Interop, mono, etc.) |
| 22 | +- `Documentation/`: Project documentation |
| 23 | +- `eng/`: .NET Arcade SDK build infrastructure |
| 24 | + |
| 25 | +### Project Types in this Repository |
| 26 | +- **Android API Bindings**: C# wrappers for Android Java APIs |
| 27 | +- **MSBuild Tasks**: Build logic for .NET Android projects |
| 28 | +- **Native Libraries**: C++ runtime components using CMake |
| 29 | +- **Java Support Code**: Java runtime classes |
| 30 | +- **Build Tools**: Custom tools for build process |
| 31 | +- **Tests**: NUnit tests, integration tests, and device tests |
| 32 | + |
| 33 | +## Build System |
| 34 | + |
| 35 | +This repository uses: |
| 36 | +- **MSBuild** as the primary build system with extensive `.targets` and `.props` files |
| 37 | +- **[.NET Arcade SDK](https://github.com/dotnet/arcade)** for consistent .NET build infrastructure |
| 38 | +- **CMake** for native C++ components |
| 39 | +- **Gradle** for some Android-specific build tasks |
| 40 | + |
| 41 | +Common build commands: |
| 42 | +- `./build.sh` or `build.cmd` - Main build |
| 43 | +- `./dotnet-local.sh` or `dotnet-local.cmd` - Use locally built .NET tools |
| 44 | +- `make` - Various make targets for specific components |
| 45 | + |
| 46 | +## Android Development Patterns |
| 47 | + |
| 48 | +### API Bindings |
| 49 | +- Android Java APIs are bound to C# in `src/Mono.Android/` |
| 50 | +- Follow existing patterns for Android namespaces (e.g., `Android.App`, `Android.Content`) |
| 51 | +- Use `[Register]` attributes for Java type registration |
| 52 | + |
| 53 | +### MSBuild Integration |
| 54 | +- Build tasks extend `Microsoft.Build.Utilities.Task` or related base classes |
| 55 | +- Place custom MSBuild logic in `src/Xamarin.Android.Build.Tasks/Tasks/` |
| 56 | +- Follow existing error code patterns (e.g., `XA####` for errors, `XA####` for warnings) |
| 57 | +- Support incremental builds where possible |
| 58 | +- Follow patterns in [`Documentation/guides/MSBuildBestPractices.md`](Documentation/guides/MSBuildBestPractices.md) |
| 59 | + |
| 60 | +### Native Code |
| 61 | +- C++ code uses CMake build system |
| 62 | +- Native libraries are in `src/native/` |
| 63 | +- Follow Android NDK patterns and conventions |
| 64 | +- Use proper JNI patterns for Java interop |
| 65 | + |
| 66 | +### Testing Patterns |
| 67 | +- Unit tests go in `tests/` directory |
| 68 | +- Device integration tests in `tests/MSBuildDeviceIntegration/` |
| 69 | +- Use NUnit for C# tests |
| 70 | +- Mock Android APIs appropriately for unit testing |
| 71 | +- Follow patterns in [`Documentation/workflow/UnitTests.md`](Documentation/workflow/UnitTests.md) for comprehensive testing guidance |
| 72 | + |
| 73 | +### Development and Debugging |
| 74 | +- Use `MSBUILDDEBUGONSTART=2` environment variable to debug MSBuild tasks |
| 75 | +- Follow patterns in [`Documentation/workflow/DevelopmentTips.md`](Documentation/workflow/DevelopmentTips.md) |
| 76 | +- Use update directories for rapid testing of Debug builds on devices |
| 77 | +- Utilize `dotnet test --filter` for running specific unit tests |
| 78 | +- Reference [`Documentation/workflow/MSBuildBestPractices.md`](Documentation/workflow/MSBuildBestPractices.md) for MSBuild debugging techniques |
6 | 79 |
|
7 | 80 | ## Nullable Reference Types
|
8 | 81 |
|
@@ -107,3 +180,100 @@ try {
|
107 | 180 | // Code here
|
108 | 181 | }
|
109 | 182 | ```
|
| 183 | + |
| 184 | +## Error and Warning Patterns |
| 185 | + |
| 186 | +### Error Codes |
| 187 | +- Use `XA####` for MSBuild errors (e.g., `XA1234`) |
| 188 | +- Use `XA####` for MSBuild warnings |
| 189 | +- Use `APT####` for Android Asset Packaging Tool errors |
| 190 | +- Include clear, actionable error messages |
| 191 | +- Reference documentation when available |
| 192 | + |
| 193 | +### Logging |
| 194 | +- Use MSBuild logging (`Log.LogError`, `Log.LogWarning`, `Log.LogMessage`) |
| 195 | +- Every `LogCodedWarning` and `LogCodedError` needs an error/warning code |
| 196 | +- Include relevant context (file paths, line numbers when available) |
| 197 | +- Make error messages helpful for developers |
| 198 | + |
| 199 | +## Documentation Patterns |
| 200 | + |
| 201 | +### Code Documentation |
| 202 | +- Use XML documentation comments for public APIs |
| 203 | +- Document Android API level requirements where relevant |
| 204 | +- Include `<example>` tags for complex APIs |
| 205 | +- Reference official Android documentation where helpful: |
| 206 | + - [Android Developer Guide](https://developer.android.com/develop) |
| 207 | + - [Android API Reference](https://developer.android.com/reference) |
| 208 | + |
| 209 | +### Project Documentation |
| 210 | +- Update relevant `.md` files in `Documentation/` when making significant changes |
| 211 | +- Follow existing documentation structure and formatting |
| 212 | +- Include code examples that actually work |
| 213 | + |
| 214 | +## Commit Message Guidelines |
| 215 | + |
| 216 | +Follow the patterns in `Documentation/workflow/commit-messages.md`: |
| 217 | + |
| 218 | +### Summary Format |
| 219 | +``` |
| 220 | +[Component] Summary |
| 221 | +``` |
| 222 | + |
| 223 | +Where Component is either: |
| 224 | +- Directory name (e.g., `[Mono.Android]`, `[Build.Tasks]`) |
| 225 | +- Broad category: `build`, `ci`, `docs`, `tests` |
| 226 | + |
| 227 | +### Dependency Bumps |
| 228 | +``` |
| 229 | +Bump to org/repo/branch@commit |
| 230 | +Bump to [Dependency Name] [Dependency Version] |
| 231 | +``` |
| 232 | + |
| 233 | +### Required Sections |
| 234 | +- **Changes**: What was modified |
| 235 | +- **Fixes**: Issues resolved (include GitHub issue numbers) |
| 236 | +- **Context**: Why the change was needed |
| 237 | + |
| 238 | +## Common Troubleshooting |
| 239 | + |
| 240 | +### Build Issues |
| 241 | +- Clean `bin/` and `obj/` directories |
| 242 | +- Ensure Android SDK/NDK are properly configured |
| 243 | +- Use `make clean` for complete rebuild |
| 244 | + |
| 245 | +### MSBuild Task Development |
| 246 | +- Test tasks in isolation first |
| 247 | +- Handle incremental build scenarios |
| 248 | +- Consider cross-platform compatibility (Windows/macOS/Linux) |
| 249 | +- Validate inputs and provide clear error messages |
| 250 | +- Use `MSBUILDDEBUGONSTART=2` for debugging MSBuild tasks |
| 251 | + |
| 252 | +### Device Testing |
| 253 | +- Use `tests/MSBuildDeviceIntegration/` for comprehensive device tests |
| 254 | +- Leverage update directories for rapid iteration on Debug builds |
| 255 | +- Use `dotnet test --filter` to run specific tests |
| 256 | +- Ensure proper Android emulator/device setup for testing |
| 257 | + |
| 258 | +### Performance and Diagnostics |
| 259 | +- Use profiling capabilities documented in [`Documentation/guides/profiling.md`](Documentation/guides/profiling.md) |
| 260 | +- Leverage tracing features documented in [`Documentation/guides/tracing.md`](Documentation/guides/tracing.md) |
| 261 | +- Monitor build performance and optimize accordingly |
| 262 | + |
| 263 | +### Native Development |
| 264 | +- Use appropriate CMake patterns from existing code |
| 265 | +- Handle different Android ABIs (arm64-v8a, armeabi-v7a, x86_64, x86) |
| 266 | +- Note: Native CoreCLR components in `src/native/clr` only target 64-bit platforms (arm64-v8a, x86_64) |
| 267 | +- Follow Android NDK security best practices |
| 268 | +- Test on multiple Android API levels when relevant |
| 269 | + |
| 270 | +### Android API Management |
| 271 | +- Follow [`Documentation/workflow/HowToAddNewApiLevel.md`](Documentation/workflow/HowToAddNewApiLevel.md) for adding new Android API levels |
| 272 | +- Use existing patterns for Java-to-C# API bindings |
| 273 | +- Understand Android backward/forward compatibility requirements |
| 274 | + |
| 275 | +## Contributing Guidelines |
| 276 | + |
| 277 | +### Updating AI Instructions |
| 278 | +- Always update `copilot-instructions.md` when making changes that would affect how AI assistants should work with the codebase |
| 279 | +- This includes new patterns, conventions, build processes, or significant structural changes |
0 commit comments