5

我最近将 Android Studio 更新到 2.0 版:Beta 7。我正在尝试使用 Instant Run,我刚刚安装了 Gradle 2.0。但现在由于与 bintray.gradle 相关的错误,我无法编译我的项目

编译时出现以下错误:

Error:Cannot configure the 'publishing' extension after it has been accessed.

调试器错误:

Error:FAILURE: Build failed with an exception.

* Where:
Script 'C:\Project\AtkApp\volley\bintray.gradle' line: 43

* What went wrong:
A problem occurred evaluating script.
> Cannot configure the 'publishing' extension after it has been accessed.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Bintray.gradle:

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

// apply the plugin with its class name rather than its Id to work around gradle limitation of
// not being able to find the plugin by Id despite the dependencies being added right above. Gradle
// is currently not capable of loading plugins by Id if the dependency is anywhere else than
// in the main project build.gradle. This file is "imported" into the project's build.gradle
// through a "apply from:".
apply plugin: com.jfrog.bintray.gradle.BintrayPlugin
apply plugin: 'maven-publish'

project.ext.group = 'com.android.volley'
project.ext.archivesBaseName = 'volley'
project.ext.version = '1.0.0'
project.ext.pomDesc = 'Volley Android library'

task sourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.srcDirs
}

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

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

artifacts {
    archives javadocJar
    archives sourcesJar
}

publishing {
    publications {
        library(MavenPublication) {
            groupId project.ext.group
            artifactId project.ext.archivesBaseName
            version project.ext.version

            // Release AAR, Sources, and JavaDoc
            artifact "$buildDir/outputs/aar/volley-release.aar"
            artifact sourcesJar
            artifact javadocJar
        }
    }
}

bintray {
    user = System.env.BINTRAY_USER
    key = System.env.BINTRAY_USER_KEY

    publications = [ 'library' ]

    publish = project.has("release")
    pkg {
        userOrg = 'android'
        repo = 'android-utils'
        group = project.ext.group
        name = project.ext.group + '.' + project.ext.archivesBaseName
        desc = project.ext.pomDesc
        licenses = [ 'Apache-2.0' ]
        websiteUrl = 'https://tools.android.com'
        issueTrackerUrl = 'https://code.google.com/p/android/'
        vcsUrl = 'https://android.googlesource.com/platform/frameworks/volley.git'
        labels = ['android', 'volley', 'network']
        publicDownloadNumbers = true

        version {
            name = project.ext.version
            desc = project.ext.pomDesc + ' version ' + project.ext.version
            gpg {
                sign = true
                passphrase = System.env.GPG_PASSPHRASE
            }
        }
    }
}
4

4 回答 4

2

注释 volley build.gradle 中的行

当我更新最新版本时,我遇到了同样的问题。我试过这样做并成功。

于 2016-04-09T02:43:03.347 回答
0

不要评论这一行:

apply from: 'bintray.gradle'

只需更改这些代码行

publishing {
publications {
    library(MavenPublication) {
        groupId project.ext.group
        artifactId project.ext.archivesBaseName
        version project.ext.version

        // Release AAR, Sources, and JavaDoc
        artifact "$buildDir/outputs/aar/volley-release.aar"
        artifact sourcesJar
        artifact javadocJar
    }
}
}

    publishing.publications {
library(MavenPublication) {
    groupId project.ext.group
    artifactId project.ext.archivesBaseName
    version project.ext.version

    // Release AAR, Sources, and JavaDoc
    artifact "$buildDir/outputs/aar/volley-release.aar"
    artifact sourcesJar
    artifact javadocJar
}
}
于 2016-05-10T13:05:41.943 回答
0

罪魁祸首是Volley 项目中publishing使用的标签。bintray.gradle随着 Gradle 2.0.0 更新,它抱怨publishing在访问后无法配置。

build.gradle现在评论项目的以下行Volley将使构建继续进行。

//apply from: 'bintray.gradle'

一旦有更好的解决方案,我会更新评论。

于 2016-04-19T19:01:40.883 回答
0

publishing{ Publications{}},它位于您添加到项目中的 volley 文件中。不要浪费时间查看项目 gradle。

于 2016-06-25T12:00:53.817 回答