笔记:Android Studio发布项目到Bintray

首先上代码

Project的Build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'me.tatarka:gradle-retrolambda:3.3.1'
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }

    tasks.withType(Javadoc) {
        options.addStringOption('Xdoclint:none', '-quiet')
        options.addStringOption('encoding', 'UTF-8')
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Module的build.gradle:

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
//使用java 8时需要
apply plugin: 'me.tatarka.retrolambda'

//版本号
version = "1.0.1"

android {
    ...

    //这个没写的话在执行gradlew bintrayupload时也会提示加上
    lintOptions {
        abortOnError false
    }
}

dependencies {
    ...
}

//siteUrl和gitUrl没有的话在GitHub上创建个项目就有了
def siteUrl = 'https://github.com/***/BaseLibrary' // 项目的主页
def gitUrl = 'https://github.com/***/BaseLibrary.git' // Git仓库的url
group = "com.***.***" // Maven Group ID for the artifact,我这里填的包名
install {
    repositories.mavenInstaller {
        // 配置POM.xml的参数
        pom {
            project {
                packaging 'aar'
                name '***' //项目描述
                url siteUrl
                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        id '***' //我这里填了公司
                        name '***' //我这里填了自己名字
                        email '***' //我这里填了自己邮箱
                    }
                }
                scm {
                    connection gitUrl
                    developerConnection gitUrl
                    url siteUrl
                }
            }
        }
    }
}
task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}
task javadoc(type: Javadoc) {
    options.encoding = "UTF-8"
    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
}
javadoc {
    options {
        encoding "UTF-8"
        charSet 'UTF-8'
        author true
        version true
        links "http://docs.oracle.com/javase/7/docs/api"
        title 'A Library For Android'   // 文档的标题
    }
}
artifacts {
    archives javadocJar
    archives sourcesJar
}
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 = "***"
        name = "***"    //发布到JCenter上的项目名字
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = ["Apache-2.0"]
        publish = true
    }
}

local.properties:

#...
ndk.dir=C\:\\Sdk\\ndk-bundle
sdk.dir=C\:\\Sdk

bintray.user=***
bintray.apikey=***

遇到的问题

1、上传后在bintray中找不到Add To Jcenter按钮,网上有很多说是注册了企业版,但我注册的是个人的,后来找到是未登录的原因。
未登录时网站右上角是这样的:
笔记:Android Studio发布项目到Bintray_第1张图片
登录后是这样的:
笔记:Android Studio发布项目到Bintray_第2张图片

2、throws java.io.FileNotFoundException: …\build\poms\pom-default.xml (系统找不到指定的路径)
这是在执行bintrayupload命令时报的错,该命令不生成pom-default.xml文件,需要先执行install命令生成。

3、`FAILURE: Build failed with an exception.

  • What went wrong:
    Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)

在执行gradlew install时遇到该问题,改用gradlew build install就行了。

4、`FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:baselib:bintrayUpload’.
    java.net.SocketTimeoutException: Read timed out`

在执行gradlew bintrayupload时遇到该问题,换了个网络就没行了,当时的网络连打开网页都很慢。

5、`FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:testlibrary:bintrayUpload’.
    java.net.UnknownHostException: api.bintray.com`

同上,网络原因。

你可能感兴趣的:(Android,android,studio,bintray)