Android 平台的开源天气 App 采用 MVP、RxJava、Retrofit2、OKHttp3、Dagger2、RetroLambda 等开源库来实现。
Android 平台的开源天气 App 采用 MVP、RxJava、Retrofit2、OKHttp3、Dagger2、RetroLambda 等开源库来实现。
MinimalistWeather 是一款 Kotlin-first、Compose-first 的 Android 天气应用。项目已从早期 Java/MVP 示例迁移为多模块 Clean Architecture,使用 Open-Meteo 提供城市搜索、天气预报和空气质量数据。
项目仍在持续开发中。当前包名:
cn.byronlab.weather。
| 类别 | 技术 |
|---|---|
| 语言与构建 | Kotlin 2.3.21、JDK 17、Gradle 9.4.1、AGP 9.2.0、KSP |
| UI | Jetpack Compose、Material 3、单 Activity、edge-to-edge |
| 架构 | Clean Architecture、UDF、ViewModel、不可变 StateFlow |
| 异步 | Kotlin Coroutines、suspend、Flow |
| 依赖注入 | Hilt + Dagger 构造注入 |
| 网络与 JSON | OkHttp 5.3.0、Kotlinx Serialization 1.11.0 |
| 本地数据 | DataStore Preferences、SharedPreferences migration |
| 后台任务 | WorkManager |
| 性能 | Baseline Profile、Startup Profile、Macrobenchmark |
| 测试 | JUnit 4、Kotlin Coroutines Test、AndroidX Benchmark |
依赖、插件、SDK 和应用版本统一声明在 gradle/libs.versions.toml。
flowchart LR
baseline[":baselineprofile"] -.-> app[":app"]
app --> presentation[":presentation"]
app --> data[":data"]
app --> domain[":domain"]
presentation --> domain
data --> domain
| 模块 | 职责 |
|---|---|
:app |
Application、Activity、Hilt 装配、Android 定位、WorkManager 与资源入口 |
:presentation |
Compose 页面、ViewModel、UI state/event/effect、UI mapper 与天气视觉引擎 |
:data |
Open-Meteo 网络边界、DTO/parser/mapper、DataStore 与 Repository 实现 |
:domain |
纯 Kotlin/JVM 的业务模型、Repository 契约、UseCase 与结果类型 |
:baselineprofile |
Baseline/Startup Profile 生成与冷启动 Macrobenchmark |
核心依赖方向为 app -> presentation -> domain 与 app -> data -> domain;domain 不依赖 Android framework。
LocationManager 与 Geocoder;当前实现不需要配置 API key。网络请求全部使用 HTTPS;定位能力需要用户授予粗略或精确位置权限。
使用 Android Studio 打开仓库根目录并等待 Gradle Sync 完成,或直接运行:
./gradlew assembleDebug
Debug APK 输出到:
app/build/outputs/apk/debug/app-debug.apk
完整的本地验证命令:
./gradlew test lint assembleDebug
开发过程中也可以只运行受影响模块:
./gradlew :domain:test
./gradlew :data:test
./gradlew :presentation:test
在已连接测试设备时生成 Baseline Profile:
./gradlew :app:generateBaselineProfile
启动性能数据容易受到设备状态影响;Macrobenchmark 结果应在固定状态的真机上重复采集后再比较。
项目最初用于展示 Android 工程架构与常用开源库的实践。当前 active app 已不再使用旧 MVP、RxJava、Retrofit、ORMLite、ButterKnife、FastJson 或 Stetho;旧架构图 framework_minimalist_weather.png 仅保留为历史资料。
欢迎关注微信公众号:BaronNode
Copyright 2017 Byron
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
暂无开放 Issues,或尚未同步最近议题。