HTTP / 1.1 401在bintray上传二进制文件时未经授权

问题描述 投票:7回答:2

我正在尝试从android studio上传一个android库模块,然后是这个博客:https://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en

(1)

./gradlew安装

结果: - 建立成功

(2)

./gradlew build bintrayUpload

结果: - 低于错误 -

FAILURE:构建因异常而失败。

  • 出了什么问题:任务执行失败':acr:bintrayUpload'。 无法创建版本'1.0.0':HTTP / 1.1 401 Unauthorized [消息:此资源需要身份验证]

我检查了很多次,确保我的用户名和apikey是正确的。 (在用户名中我使用组织名称而不是bintray用户名,因为我的存储库是在组织下创建的)。如果有人有想法,我会很感激帮助:)

android android-studio-2.2 bintray
2个回答
12
投票

在Bintray中,您的用户名必须是您的用户帐户的用户名,而不是组织。如果您是回购的所有者,则权限机制将允许该操作。

在用户名中我正在使用组织名称

一些文档链接:

https://github.com/bintray/gradle-bintray-plugin#readme

https://bintray.com/docs/usermanual/formats/formats_mavenrepositories.html#_working_with_gradle

编辑:确保您使用的是userOrg参数,因为您的repo位于组织主题下,而不在用户下。

在这里查看第4步:https://github.com/bintray/gradle-bintray-plugin#step-4-add-your-bintray-package-information-to-the-bintray-closure

这是一个有效的build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
    }
}


plugins {
    id "com.jfrog.bintray" version "1.7"
}


apply plugin: 'com.jfrog.bintray'
apply plugin: 'java'

bintray {
    user = 'myuserusername'
    key = '**********'
    pkg {
        repo = 'gradlerepo'
        name = 'gradlepackage'
        userOrg = 'myorgname'
        version {
            name = '1.0-Final'
        }
    }
}

0
投票

我想补充更多@ gba的回答here

您应该将它们包含在项目根目录下的local.properties文件中,而不是直接包含您的bintray用户名和apikey。 local.properties文件默认添加到.gitignore,因此不会与其他文件一起上传到githup。它有助于保持您的用户名和apikey安全。

bintray.user=<your bintray username>
bintray.apikey=<your bintray apikey>

然后在你的模块gradle文件中添加:

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")

    configurations = ['archives']
    pkg {
        repo = "maven"
        name = "<Your library name>"
        websiteUrl = <your siteUrl>
        vcsUrl = gitUrl
        licenses = ["Apache-2.0"]
        publish = true
    }
}

参考:https://www.virag.si/2015/01/publishing-gradle-android-library-to-jcenter/

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