如何在Github上创建一个库,并通过Android Studio中的gradle依赖项使用它

Вла*_*ков 24 android github gradle android-studio jitpack

我想创建库并通过Internet访问它.在Android Studio中(通过Gradle),可以通过以下方式添加依赖项:

build.gradle(模块应用程序)中:

dependencies {
    ...
    compile 'com.android.support:design:23.1.0'
    compile 'com.squareup:otto:1.3.8'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.j256.ormlite:ormlite-core:4.48'
    compile 'com.j256.ormlite:ormlite-android:4.48'
    ...
}
Run Code Online (Sandbox Code Playgroud)

如何从github以这种方式添加自己的库?

Gab*_*tti 22

要实现它,你有一些方法:

  1. 在中央maven或jcenter中发布您的库(工件).
  2. 使用github repo和jitpack插件
  3. 使用私人专家

第2点非常简单.

只需按下你的codein github并修改你想要使用它的项目中的gradle脚本.

只需添加此repo tp即可 build.gradle

repositories {
        // ...
        maven { url "https://jitpack.io" }
    }
Run Code Online (Sandbox Code Playgroud)

和依赖:

dependencies {
        compile 'com.github.User:Repo:Tag'
    }
Run Code Online (Sandbox Code Playgroud)

在Central Maven或JCenter中发布库,在答案中解释很长.Hovewer你可以阅读这些帖子:


M D*_*M D 13

请参阅Jitpack最好将项目或库从Githubgradle导入

有关更多信息,请参阅Gabriele Mariotti的回答

  • 虽然这可能会回答这个问题,但最好在这里提供实际信息,而不仅仅是链接.[仅链接答案不被视为好答案,可能会被删除](http://stackoverflow.com/help/deleted-answers). (6认同)
  • JitPack对公共存储库非常有用.您可以在这篇文章中阅读一些示例:https://solidgeargroup.com/jitpack-public-repositories-android (3认同)