首页 > 解决方案 > 无法将 git 存储库解析为 android gradle 中的依赖项

问题描述

我正在尝试使用 Gradle 将 git 存储库(https://github.com/FHNW-IP5-IP6/ComposeForms)作为依赖项添加到我的项目中,并尝试了以下列出的变体(1.-3)。可以在 android gradle 中将 git 存储库声明为依赖项吗?但每次同步项目时,我都会收到一条错误消息:“Could not resolve com.github.FHNW-IP5-IP6:ComposeForms:master-SNAPSHOT”

我尝试了以下方法:

  1. Jitpack ( https://jitpack.io/#FHNW-IP5-IP6/ComposeForms/master-SNAPSHOT )

    allprojects {
      repositories {
        ...
        maven("https://jitpack.io") // also tried uri https://www.jitpack.io
      }
    }
    

    并在应用程序 build.gradle

    kotlin {
      sourceSets {
        named("main") {
          dependencies {
            ...
            implementation("com.github.FHNW-IP5-IP6:ComposeForms:master-SNAPSHOT")
          }
        }
      }
    }
    
  2. Git 子模块(命名为 compose-forms)

    include(":compose-forms")在 settings.gradle 里面

    kotlin {
      sourceSets {
        named("main") {
          dependencies {
            ...
            implementation(project(":compose-forms"))
          }
        }
      }
    }
    
  3. gradle 中的新功能

    里面 settings.gradle

    sourceControl {
      gitRepository(uri("https://github.com/FHNW-IP5-IP6/ComposeForms.git")) {
        producesModule("compose-forms")
      }
    }
    

    并在应用程序 build.gradle

    kotlin {
      sourceSets {
        named("main") {
          dependencies {
            ...
            implementation("compose-forms") {
              version {
                branch = "master"
              }
            }
          }
        }
      }
    }
    

我用完了选项,真的需要 git 存储库作为依赖项。我不希望我的项目中有任何 git 子模块,所以我更喜欢数字 1 和 3 工作。提前感谢您的任何提示:)

标签: androidgradlegit-submodulesgradle-kotlin-dsljitpack

解决方案


以管理员身份打开 Android Studio,然后将maven { url 'https://jitpack.io' }添加到build.gradle(project)settings.gradle(project)以及各自的实现 [...]build.gradle( :应用程序)。这对我有用,因为提出的所有其他解决方案都失败了。


推荐阅读