传一个jcenter

格式仿佛是乱了……

就这样吧……

=========================================================

工程的build.gradle下加上

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath 'com.github.dcendents:android-maven-plugin:1.2'

如果gradle版本在2.4.0以上,就把第二个改成[1]

classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'

——以下加粗内容是需要自己修改的部分

然后进入库模块的build.gradle,根节点里——以下不特别说明都是在根节点里——添加插件

apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

定义版本

version = "0.1"

添加网站,其中siteUrl是项目官网,没有的话就用Github吧

def siteUrl = 'https://github.com/<user>/<project>'
def gitUrl = 'https://github.com/<user>/<project>.git'

定义包名

group = "com.user.project"

添加打包脚本

// 根节点添加
install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters
        pom {
            project {
                packaging 'aar'
                name 'ProjectName'
                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 'myid'
                        name 'myname'
                        email 'email@host.com'
                    }
                }
                scm {
                    connection gitUrl
                    developerConnection gitUrl
                    url siteUrl
                }
            }
        }
    }
}

添加文档和源码打包脚本

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

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
}

然后在local.properties里加上bintray上的用户名和密码,另外这个文件就不要往Github上传了

bintray.user=username
bintray.apikey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

然后回到库模块的build.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 = "project name in jcenter"
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = ["Apache-2.0"]
        publish = true
    }
}

于是就修改完成。

然后依次跑

javadocJar

sourcesJar

install

bintrayUpload

这四个脚本任务,用Android Studio右侧的Gradle栏直接双击执行更方便一点。

不出问题的话Bintray上的last activity里就会显示你已经创建了一个新项目,进去之后把鼠标放在MavenCentral标签上会有提示,点一下get it included,之后等审核就行了。

但出了问题的话。

我也救不了你……

感谢前人指路。给您磕个头。↓

http://www.cnblogs.com/qianxudetianxia/p/4322331.html

参考来源:

[1]:http://stackoverflow.com/questions/30514274/cannot-build-library-project-bintray-gradle-classnotfoundexception

原文地址:https://www.cnblogs.com/chihane/p/4882912.html