md_files/Java/安卓开发.md
2025-03-18 12:46:59 +08:00

52 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 安卓开发
## 导入功能模块心得
最近想在我的书城中开发一下阅读器的功能难度颇高因此在github上找到了一个封装了阅读器功能的项目仅需获得文件本地存储地址调用其提供的函数即可进行阅读。
**但是**github介绍的使用方法并不总是有效比如我就经常无法正确添加依赖
![image-20240503200121198](D:/folder/test/output/9a28a61a-bb35-4a7a-9f09-db4c300212f1.png)
因此,我将其项目代码拷贝到本地,手动集成。
![image-20240503200221147](D:/folder/test/output/3a17e26d-cc39-4823-802b-92f7d5f6e3ba.png)
依据项目结构可以发现app是主项目hwtxtreaderlib是功能模块根据是这张图
![image-20240503200343665](D:/folder/test/output/70cd971c-21ec-4914-9fe7-1f5aac7b85b2.png)
build.gradle(:app)中引入了hwtxtreaderlib的依赖而app只是个demo测试模块相当于演示了如果在自己的项目中引用hwtxtreaderlib。因此手动步骤如下
- 将hwtxtreaderlib复制到自己的项目文件夹中
![image-20240503200651488](D:/folder/test/output/e05bc95d-b8e4-466f-8d1f-ddf21c9afe10.png)
- 在app的build.gradle中添加依赖
```
implementation project(':hwtxtreaderlib')
```
- 在settings.gradle中设置项目包括的模块
```
include ':app', ':hwtxtreaderlib'
```
- syn now 同步一下然后android studio中项目结构变成如下图
![image-20240503201012590](D:/folder/test/output/3efab097-d5fd-411c-8641-2ef0977eded6.png)
- build没报错基本就稳了然后就运行试试
![image-20240503201211104](D:/folder/test/output/98ab47e6-d406-4c5c-84c1-4470bd803ef2.png)
这里可能AndroidManifest.xml报错需要查看原项目中app模块如何编写的做些适当的修改我这里卡了很久.
**非常重要!!!**有时候github项目会将项目的详细信息写在wiki中
![image-20240503213919450](D:/folder/test/output/bbcc458c-16c2-455f-8853-441379e5807f.png)