Android 如何搜索对 GitHub 的依赖?

How does Android search for dependencies on GitHub?

我想在我的 android 项目中实现来自 GitHub 的依赖项,但它给了我这个错误

Could not find com.github.RobertApikyan:SegmentedControl:1.2.0

我正在实施这个:

implementation 'com.github.RobertApikyan:SegmentedControl:1.2.0'

我认为是这样,因为 build.gradle 文件不会在 GitHub 上搜索回购协议。

这是我的 build.gradle 文件:

buildscript {
    ext.kotlin_version = '1.3.72'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

解决方法 1:

您可以使用 github 将项目发布托管到 mavenCentral,它位于:

https://github.com/{user}/{repository}/packages?package_type=Maven

为了从中提取包,请在 build.gradle:

中添加新的存储库
mavenCentral()

措辞 2:

您可以在 jitpack.io 托管项目的任何分支或版本 最棒的是你不需要设置任何东西它会在他们的服务器上构建你的包并通知你。您的项目将位于:

https://jitpack.io/#{user}/{repository}

为了从中提取包,请在 build.gradle:

中添加新的存储库
maven { url 'https://jitpack.io' }