我无法为刚刚发布的库的 gradle 依赖项声明导入

I cannot declare import for gradle dependency of my just published library

UPDATE2:我没有生成 aar 文件,现在它包含在包中,您可以在此处查看:https://github.com/fabrizioiacobucci/range-bar-preference/packages/787218 我看到 javadoc、sources 和 aar 在那里,但是当我将包添加为另一个项目中的依赖项时,我什至在外部库中都看不到它。

更新:这就是问题所在,我在下载的 jar 中看不到我的源文件:

我最近在 Github 上分叉了一个小项目,并将其旧代码版本迁移到 AndroidX 和新的 gradle 版本。 一段时间后一切正常,我也可以在 Git 包上发布库。 但是,我试图将其声明为对本地计算机上不同项目的依赖。它下载正常,但是当我尝试将其导入源文件时,我找不到包:

如果我进入项目文件夹,我会看到下载的库和相关文件。

这是已发布库的项目 build.gradle 文件。

build.gradle(项目)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.0'
        classpath 'io.github.gradle-nexus:publish-plugin:1.1.0'
    }
}

plugins {
    id 'maven-publish'
}
apply from: "${rootDir}/scripts/publish-root.gradle"
apply plugin: 'io.github.gradle-nexus.publish-plugin'

ext {
    VERSION = '1.0.0'
    DESCRIPTION = 'A range bar that can be used as an android shared preference'
    GROUPID = 'com.fabrizioiacobucci.android'
    ARTIFACTID = 'range-bar-preference'
    GITREPO = 'https://github.com/fabrizioiacobucci/tree/development/range-bar-preference.git'
    PROJECTURL = 'https://github.com/fabrizioiacobucci/tree/development/range-bar-preference'
    PUBLISHGIT = 1
    PUBLISHMAVEN = 0
}

nexusPublishing {
    repositories {
        sonatype {
            stagingProfileId = '1c4ab2dc896731'
            //packageGroup = "com.fabrizioiacobucci.android"
            username = ossrhUsername
            password = ossrhPassword
            nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"))
            snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
        }
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

build.gradle(模块)

apply plugin: 'com.android.library'

android {
    compileSdkVersion 30
    buildToolsVersion '31.0.0 rc3'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 30
        version VERSION

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        vectorDrawables.useSupportLibrary = true
        versionCode 1
        versionName VERSION
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test:runner:1.3.0'
    androidTestImplementation 'androidx.test:rules:1.3.0'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
    implementation 'com.appyvet:materialrangebar:1.3'
    implementation 'androidx.appcompat:appcompat:1.2.0'

    testImplementation 'junit:junit:4.13.2'
    testImplementation 'org.robolectric:robolectric:4.5.1'
}

apply from: "${rootDir}/scripts/publish-module-maven.gradle"
apply from: "${rootDir}/scripts/publish-module-githubpkg.gradle"

publish-module-maven.gradle

apply plugin: 'maven-publish'
apply plugin: 'signing'

task androidSourcesJar(type: Jar) {
    archiveClassifier.set('sources')
    from android.sourceSets.main.java.srcDirs
}

task javadoc(type: Javadoc) {
    failOnError false
    source = android.sourceSets.main.java.srcDirs
    classpath = configurations.compile
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    archiveClassifier.set('javadoc')
    from javadoc.destinationDir
}

artifacts {
    archives androidSourcesJar
    archives javadocJar
}

afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                // The coordinates of the library, being set from variables that
                // we'll set up later
                groupId GROUPID
                artifactId ARTIFACTID
                version VERSION

                artifact("$buildDir/outputs/aar/range-bar-preference-release.aar")

                artifact androidSourcesJar
                artifact javadocJar

                // Mostly self-explanatory metadata
                pom {
                    name = 'Range Bar Preference'
                    description = 'A range bar that can be used as an android shared preference'
                    url = PROJECTURL
                    groupId GROUPID
                    licenses {
                        license {
                            name = 'The Apache Software License, Version 2.0'
                            url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                            distribution = 'repo'
                        }
                    }
                    developers {
                        developer {
                            id = 'FabrizioIacobucci'
                            name = 'Fabrizio Iacobucci'
                            email = 'fabrizio.iacobucci90@mail.com'
                        }
                    }
                    scm {
                        connection = 'scm:git:github.com/fabrizioiacobucci/range-bar-preference.git'
                        developerConnection = 'scm:git:ssh://github.com/fabrizioiacobucci/range-bar-preference.git'
                        url = 'https://github.com/fabrizioiacobucci/range-bar-preference/'
                    }
                }
            }
        }
    }
}

ext["signing.keyId"] = rootProject.ext["signing.keyId"]
ext["signing.password"] = rootProject.ext["signing.password"]
ext["signing.secretKeyRingFile"] = rootProject.ext["signing.secretKeyRingFile"]

signing {
    sign publishing.publications
}

publish-module-githubpkg.gradle

artifacts {
    archives androidSourcesJar
    archives javadocJar
}

project.publishing {
    publications {
        maven(MavenPublication) {
            groupId = GROUPID
            artifactId = ARTIFACTID
            version = VERSION

            artifact("$buildDir/outputs/aar/range-bar-preference-release.aar")

            artifact androidSourcesJar
            artifact javadocJar

            versionMapping {
                usage('java-api') {
                    fromResolutionOf('runtimeClasspath')
                }
                usage('java-runtime') {
                    fromResolutionResult()
                }
            }
            pom {
                name = 'Range Bar Preference'
                packaging = 'aar'
                description = 'A range bar that can be used as an android shared preference'
                url = PROJECTURL
                licenses {
                    license {
                        name = 'The Apache Software License, Version 2.0'
                        url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        distribution = 'repo'
                    }
                }
                developers {
                    developer {
                        id = 'FabrizioIacobucci'
                        name = 'Fabrizio Iacobucci'
                        email = 'fabrizio.iacobucci90@mail.com'
                    }
                }
                scm {
                    connection = 'scm:git:github.com/fabrizioiacobucci/range-bar-preference/range-bar-preference.git'
                    developerConnection = 'scm:git:ssh://github.com/fabrizioiacobucci/range-bar-preference/range-bar-preference.git'
                    url = 'https://github.com/fabrizioiacobucci/range-bar-preference/'
                }
            }
        }
    }
    repositories {
        maven {
            name = "GitHubPackages"
            url = uri('https://maven.pkg.github.com/fabrizioiacobucci/range-bar-preference')
            credentials {
                username = System.getenv("GITHUB_USER")
                password = System.getenv("GITHUB_TOKEN")
            }
        }
    }
}

不知道还有什么相关的可以分享,万一告诉我一下。 你知道我错过了什么吗?

非常感谢您的帮助。

进口com.nfx.android.rangebarpreference

将 fabrizio iacobucci 更改为 nfx 将解决您的问题

正如承诺的那样,我将原始项目升级到 android,然后将所有依赖项升级到最新的。

为了快速发布SDK做POC,我发布到jitpack.io

如何将新库添加为依赖项。

  • 将其添加到您的根 build.gradle 存储库末尾:

     allprojects {
     repositories {
         ...
         maven { url 'https://jitpack.io' }
     }
    

    }

  • 将此添加到您的应用模块依赖项中:

     dependencies {
        implementation 'com.github.dk19121991:range-bar-preference:0.0.7'
     }
    

我自己试过了,它对我来说工作得很好,我在我的分叉版本中更新了应用程序模块,只使用来自 jitpack 的库,它工作顺利。

请尝试使用图书馆,如果您还有其他需要,请告诉我。

https://github.com/dk19121991/range-bar-preference