本人是一个消息不灵敏的开发小白,之前听学长学姐说建议在github上学习开源项目,但是苦于本地运行github开源Android项目实在搞不定,一直不能开始。今天终于搞好了,记录一下。
准备工作:
提前下好github开源Android项目,下载gradle到本地(更简单,也不浪费空间)
1.解压缩github开源Android项目到你想要的目录,用Android Studio打开该项目。
2.修改
该文件
classpath 'com.android.tools.build:gradle:8.1.0'
如果你的本地gradle不是8.7,请根据你的gradle版本将其修改为对应版本号,具体可以查阅官方文档
https://developer.android.com/build/releases/gradle-plugin?hl=zh-cn
Android Gradle 插件 8.9 版本说明 | Android Studio | Android Developers
3.修改
该文件
distributionUrl=file:///D:/gradle-8.7-bin.zip
如果你的本地gradle没有解压到D盘根目录下,请根据你的gradle所在位置进行修改
4.添加命名空间
经典的github开源Android项目的build.gradle里可能没有命名空间代码,所以当我们构建项目的时候可能会出现报需要添加命名空间的错误,比如
A problem occurred configuring project ':chatkit'.
> Failed to notify project evaluation listener.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
> Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.
这个时候,注意命名空间要加上github!!!
例如:
namespace 'com.github.stfalcon.chatkit' // 保持和groupId、artifactId逻辑一致
可参考AndroidManifest.xml的根目录。
5.重新构建项目
可能有缓存,可以尝试
失效并重启即可。
6.如果还有别的问题,仔细观察,阅读错误信息,询问AI,善用搜索引擎,必要时请求他人帮助,希望你的问题能早日解决~