AGENT SKILL
android-networking
Standards for Retrofit, OkHttp, and API Communication. Use when integrating Retrofit, OkHttp, or API clients in Android apps. (triggers: **/*Api.kt, **/*Service.kt, **/*Client.kt, Retrofit, OkHttpClient, @GET, @POST)
- License 许可
- MIT
- 最近更新
- 2026-06-24
- Stars
- ★ 67
- Forks
- 24
01 前言 Front Matter
- name
- android-networking
- description
- Standards for Retrofit, OkHttp, and API Communication. Use when integrating Retrofit, OkHttp, or API clients in Android apps. (triggers: **/*Api.kt, **/*Service.kt, **/*Client.kt, Retrofit, OkHttpClient, @GET, @POST)
03 SKILL.md 正文
Android Networking Standards
Priority: P0
Implementation Guidelines
Libraries & Setup
- Client: Use Retrofit 2 with OkHttp 4 for all backend communication.
- Serialization: Use Kotlinx Serialization (preferred). Use
@SerialNamefor JSON field mapping. - Security: Implement Certificate Pinning for sensitive production domains. Use
NetworkSecurityConfigfor cleartext traffic control.
Network Ops
- Interceptors: Use OkHttp Interceptors for global concerns like
Bearer tokeninjection via theAuthorizationheader andHttpLoggingInterceptor(debug only). - Architecture: All API calls must be
suspendfunctions. Use aResultwrapper orEitherto handle success/failure in the Repository layer. - Minification: Ensure
isMinifyEnabledis true inbuild.gradleand define R8/ProGuard rules for Retrofit/OkHttp to prevent runtime crashes. - Testing: Use MockWebServer to simulate API responses in unit and integration tests. Ensure 100% test coverage for error cases (500, 401, 403).
Anti-Patterns
- No Blocking Network Calls: All API functions must be suspend.
- No Logic in API Interface: Only declare endpoints — handle errors in Repository.
- No Raw Converter Factory: Explicitly set "application/json" MediaType with kotlinx.serialization.