创建一个gradle依赖项以从git导入
这是Android Studio中导入依赖项的方式。 在这种情况下okhttp:
dependencies { compile 'com.squareup.okhttp:okhttp:2.5.0' }
我想导入自己创建的依赖项。 例如:
dependencies { compile 'my_library:1.0.0' }
此时,如果我学习如何创建依赖项并在Android Studio项目中导入就足够了。
但是如果可能的话,我想在git(github)存储库上托管我的库。 这太棒了。
要实现它,你有一些方法:
-
在中央maven或jcenter中发布您的库(工件)。
-
使用github repo和jitpack插件
-
在当地的maven回购中发布aar(本地私有)
第2点非常简单。 只需按下你的codein github并修改你想要使用它的项目中的gradle脚本。
只需将此repo tp添加到build.gradle
repositories { // ... maven { url "https://jitpack.io" } }
和依赖:
dependencies { compile 'com.github.User:Repo:Tag' }
要在Central Maven或JCenter中发布库,在答案中解释很长。 Hovewer你可以阅读这些post:
-
在JCenter上发布
-
在中央Maven上发布