|
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/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** for consistent .NET build infrastructure |
| 38 | +- **CMake** for native C/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` - 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 | +- Handle Java-to-.NET type mappings carefully |
| 53 | + |
| 54 | +### MSBuild Integration |
| 55 | +- Build tasks extend `Microsoft.Build.Utilities.Task` or related base classes |
| 56 | +- Place custom MSBuild logic in `src/Xamarin.Android.Build.Tasks/Tasks/` |
| 57 | +- Follow existing error code patterns (e.g., `XA####` for errors, `XA####` for warnings) |
| 58 | +- Support incremental builds where possible |
| 59 | + |
| 60 | +### Native Code |
| 61 | +- C/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 |
6 | 71 |
|
7 | 72 | ## Nullable Reference Types |
8 | 73 |
|
@@ -107,3 +172,74 @@ try { |
107 | 172 | // Code here |
108 | 173 | } |
109 | 174 | ``` |
| 175 | + |
| 176 | +## Error and Warning Patterns |
| 177 | + |
| 178 | +### Error Codes |
| 179 | +- Use `XA####` for MSBuild errors (e.g., `XA1234`) |
| 180 | +- Use `XA####` for MSBuild warnings |
| 181 | +- Use `APT####` for Android Asset Packaging Tool errors |
| 182 | +- Include clear, actionable error messages |
| 183 | +- Reference documentation when available |
| 184 | + |
| 185 | +### Logging |
| 186 | +- Use MSBuild logging (`Log.LogError`, `Log.LogWarning`, `Log.LogMessage`) |
| 187 | +- Include relevant context (file paths, line numbers when available) |
| 188 | +- Make error messages helpful for developers |
| 189 | + |
| 190 | +## Documentation Patterns |
| 191 | + |
| 192 | +### Code Documentation |
| 193 | +- Use XML documentation comments for public APIs |
| 194 | +- Document Android API level requirements where relevant |
| 195 | +- Include `<example>` tags for complex APIs |
| 196 | +- Reference official Android documentation where helpful |
| 197 | + |
| 198 | +### Project Documentation |
| 199 | +- Update relevant `.md` files in `Documentation/` when making significant changes |
| 200 | +- Follow existing documentation structure and formatting |
| 201 | +- Include code examples that actually work |
| 202 | + |
| 203 | +## Commit Message Guidelines |
| 204 | + |
| 205 | +Follow the patterns in `Documentation/workflow/commit-messages.md`: |
| 206 | + |
| 207 | +### Summary Format |
| 208 | +``` |
| 209 | +[Component] Summary |
| 210 | +``` |
| 211 | + |
| 212 | +Where Component is either: |
| 213 | +- Directory name (e.g., `[Mono.Android]`, `[Build.Tasks]`) |
| 214 | +- Broad category: `build`, `ci`, `docs`, `tests` |
| 215 | + |
| 216 | +### Dependency Bumps |
| 217 | +``` |
| 218 | +Bump to org/repo/branch@commit |
| 219 | +Bump to [Dependency Name] [Dependency Version] |
| 220 | +``` |
| 221 | + |
| 222 | +### Required Sections |
| 223 | +- **Changes**: What was modified |
| 224 | +- **Fixes**: Issues resolved (include GitHub issue numbers) |
| 225 | +- **Context**: Why the change was needed |
| 226 | + |
| 227 | +## Common Troubleshooting |
| 228 | + |
| 229 | +### Build Issues |
| 230 | +- Clean `bin/` and `obj/` directories |
| 231 | +- Ensure Android SDK/NDK are properly configured |
| 232 | +- Check `global.json` for required .NET SDK version |
| 233 | +- Use `make clean` for complete rebuild |
| 234 | + |
| 235 | +### MSBuild Task Development |
| 236 | +- Test tasks in isolation first |
| 237 | +- Handle incremental build scenarios |
| 238 | +- Consider cross-platform compatibility (Windows/macOS/Linux) |
| 239 | +- Validate inputs and provide clear error messages |
| 240 | + |
| 241 | +### Native Development |
| 242 | +- Use appropriate CMake patterns from existing code |
| 243 | +- Handle different Android ABIs (arm64-v8a, armeabi-v7a, x86_64, x86) |
| 244 | +- Follow Android NDK security best practices |
| 245 | +- Test on multiple Android API levels when relevant |
0 commit comments