diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 18cbac3..bea40c8 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -37,7 +37,19 @@ "state": { "type": "markdown", "state": { - "file": "工具相关文档/VSCode/VSCode 相关.md", + "file": "日志检索.md", + "mode": "source", + "source": false + } + } + }, + { + "id": "90f44bcb7cbd1134", + "type": "leaf", + "state": { + "type": "markdown", + "state": { + "file": "Android Hilt.md", "mode": "source", "source": false } @@ -56,7 +68,7 @@ } } ], - "currentTab": 2 + "currentTab": 3 } ], "direction": "vertical" @@ -122,7 +134,7 @@ "state": { "type": "backlink", "state": { - "file": "工具相关文档/VSCode/VSCode 相关.md", + "file": "Android Hilt.md", "collapseAll": false, "extraContext": false, "sortOrder": "alphabetical", @@ -139,7 +151,7 @@ "state": { "type": "outgoing-link", "state": { - "file": "工具相关文档/VSCode/VSCode 相关.md", + "file": "Android Hilt.md", "linksCollapsed": false, "unlinkedCollapsed": true } @@ -162,7 +174,7 @@ "state": { "type": "outline", "state": { - "file": "工具相关文档/VSCode/VSCode 相关.md" + "file": "Android Hilt.md" } } } @@ -183,8 +195,11 @@ "command-palette:打开命令面板": false } }, - "active": "30e0a2943950d852", + "active": "90f44bcb7cbd1134", "lastOpenFiles": [ + "日志检索.md", + "Android Hilt.md", + "工具相关文档/VSCode/VSCode 相关.md", "工具相关文档/Android Studio", "工具相关文档/git/Git 笔记.md", "README.md", @@ -192,7 +207,6 @@ "工具相关文档/git", "工具相关文档/未命名.md", "开发愿望清单.md", - "日志检索.md", "开发中/本地版本的cos图床.md", "工具相关文档/VSCode/VSCode 连接 云服务器.md", "工具相关文档/VSCode/VSCode 文件嵌套.md", @@ -218,8 +232,6 @@ "文档编写/PRD.md", "文档编写", "工具相关文档", - "UI学习/PS 学习/日志.md", - "web/js/`JS` `setTimeout` 和 `clearTimeout`.md", - "web/css" + "UI学习/PS 学习/日志.md" ] } \ No newline at end of file diff --git a/Android Hilt.md b/Android Hilt.md new file mode 100644 index 0000000..e884505 --- /dev/null +++ b/Android Hilt.md @@ -0,0 +1,55 @@ +暂时不写博客,看[官方教程](https://developer.android.google.cn/training/dependency-injection/hilt-android?hl=zh-cn#generated-components)) + +不纠结于底层细节,就看看在学了Android官方的教程之后的总结 +### 引入依赖 +- 项目根级 `build.gradle.kts` +``` +plugins { + // hilt + id("com.google.dagger.hilt.android") version "2.48.1" apply false +} +``` +- app 级 `build.gradle.kts` +``` +plugins { + ... + kotlin("kapt") + id("com.google.dagger.hilt.android") +} + +android { + ... +} + +dependencies { + ... + // hilt + implementation("com.google.dagger:hilt-android:2.48.1") + kapt("com.google.dagger:hilt-android-compiler:2.48.1") +} + +kapt { + correctErrorTypes = true +} +``` +### 为当前的App启用Hilt (必须) +创建一个 Application 的继承类,在 `AndroidManifest.xml` 中的 `application` 中设置当前的Application,为这个 `Application` 添加 `@HiltAndroidApp` + +### Android Hilt 使用时的容器及层次结构 +Hilt 的顶层容器是 `Application` 容器, 这些容器,存在层级关系 +- 层级关系如下 + - `SingletonComponent::class` -- `Hilt` 根容器, 就是 Application 容器 + - `ActivityComponent::class` -- `` + - `FragmentComponent::class` + - `ViewComponent::class` + - `ServiceComponent::class` + - `BroadcastReceiver::class` + - + 上面的层级关系中,`SingletonComponent` 是最高层次,依次类推 + +### Android Hilt 中的作用 + +- 标注Hilt容器的注解 + - `@HiltAndroidApp` + - `@AndroidEntryPoint` + - \ No newline at end of file diff --git a/日志检索.md b/日志检索.md index 24dd3d7..5db2790 100644 --- a/日志检索.md +++ b/日志检索.md @@ -47,3 +47,6 @@ ## 2024-04-12 > Android 中的Service是在app的主线程中进行执行的,如果在主线程中执行了耗时操作,可能导致ANR + +## 2024-04-24 +- [[Android Hilt]] \ No newline at end of file