在 Android 项目中使用 GitHub 存储库作为 Gradle 依赖项

问题描述 投票:0回答:1

我已经从 github 分叉了一个项目,对其进行了修改,现在我想在我的项目中使用修改后的版本作为依赖项。像这样:

implementation("com.github.my_user_name:library_name:master-SNAPSHOT")

为此,我在 JitPack 上查看了我的存储库,看看它是否可以正常构建,结果确实如此 但是当我运行该项目时,我收到此错误:

Configuration cache state could not be cached: field __librarySourceSets__ of task :app:mapDebugSourceSetPaths of type com.android.build.gradle.tasks.MapSourceSetPathsTask`: error writing value of type 'org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection
> Could not resolve all files for configuration ':app:debugRuntimeClasspath.
//build.gradle,kts(MyAppName)
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
    alias(libs.plugins.androidApplication) apply false
    alias(libs.plugins.kotlinAndroid) apply false
    alias(libs.plugins.androidLibrary) apply false
    alias(libs.plugins.hiltAndroid) apply false
    alias(libs.plugins.kotlin.plugin.serialization) apply false // needs to be as the project's JVM version
    alias(libs.plugins.ksp) apply false
    alias(libs.plugins.org.jetbrains.kotlin.jvm) apply false
}
true // Needed to make the Suppress annotation work for the plugins block

//settings.gradle.kts(MyAppName)
pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven {
            url = uri("https://www.jitpack.io" )
        }
    }
}

rootProject.name = "MyAppNAme"
include(":app")
include(":feature:profile") // this is where I want to use the library



//build.gradle.kts(:feature:profile)
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
    alias(libs.plugins.androidLibrary)
    alias(libs.plugins.kotlinAndroid)
    alias(libs.plugins.hiltAndroid)
    alias(libs.plugins.kotlin.plugin.serialization)
    alias(libs.plugins.ksp)
}

android {
    namespace = "com.example.feature.profile"
    compileSdk = 34

    defaultConfig {
        minSdk = 24

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles("consumer-rules.pro")
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }

    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
            // excludes += "META-INF/DEPENDENCIES"
            // Avoid SRT and RTMP clash, from StreamPack
            pickFirsts += "**/*.so"
        }
    }
    buildFeatures {
        compose = true
    }
    composeOptions {
        //kotlinCompilerExtensionVersion = "1.5.4" // !important to keep this version
        kotlinCompilerExtensionVersion = "1.5.8"
    }
}

dependencies {
    implementation("com.github.my_user_name:library_name:master-SNAPSHOT")
}

这是使用 github repo 作为依赖项的正确方法吗?如果不是,我做错了什么?

android github gradle jitpack
1个回答
0
投票

仅分叉存储库不足以让插件管理系统识别/发现/拉入它 - 您需要将其发布...可能到 Maven。

我首先建议在本地发布以验证内容 - 这会将本地 Maven 安装作为“源”加载,并且您可以测试该库。

当您准备好/如果需要时,您可以发布到 Maven Central。

这是一个不错的参考 使用 Gradle 将 Java 工件发布到 Maven Local

© www.soinside.com 2019 - 2024. All rights reserved.