Android Studio项目如何上传至JCenter

Android studio Library项目上传至JCenter

  1. 配置Project目录下build.gradle
 dependencies {
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
    }
  1. 注册登录jcenter后
    —>右上角头像处选择View Profile
    —>点击Add New Repository
    —>进入Create Repository页面填写
    —> name(输入仓库名)
    —> Type (选择Maven)
    —>Default Licenses (可选填)(选择Apache-2.0)
    —>Description (可选填)(填写描述)

  2. 在Project目录下的local.properties中配置

bintray.username=
bintray.apikey=
    • 注意:
      username:为登录jcenter的用户名 即注册时填写的username,不是邮箱地址
      apikey:获取方式 —>点击顶部右上角头像处—>选择Edit Profile—>选择API Key填写密码后Submit获取
  1. 在Project目录下新建bintray.gradle
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
def siteUrl = 'https://github.com'      // 项目的主页   这个是说明,可随便填,必须能访问
def gitUrl = 'https://github.com'      // Git仓库的url  这个是说明,可随便填,必须能访问
group = "com.test.mylibrary"    // 这里是groupId ,必须填写  一般填你唯一的包名,对应com.squareup.okhttp3:okhttp:3.4.1中的com.squareup.okhttp3部分
version = "1.0.0"//发布到JCenter上的项目版本号
android.compileSdkVersion = 28//填当前项目的compileSdkVersion
install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters
        pom {
            project {
                packaging 'aar'
                // Add your description here
                name 'test 测试'     //项目描述
                url siteUrl
                // Set your license
                licenses {
                    license {
                        name 'The Util Software License, Version 1.0.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        id 'hong'        //填写开发者的一些基本信息
                        name 'hong'    //填写开发者的一些基本信息
                        email '@gmail.com'   //填写开发者的一些基本信息
                    }
                }
                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"
        charSet 'UTF-8'
        author true
        version true
        links "http://docs.oracle.com/javase/7/docs/api"
    }
    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
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
bintray {
//    userOrg=properties.getProperty("bintray.user")
    user = properties.getProperty("bintray.username")    //读取 local.properties 文件里面的 bintray.username
    key = properties.getProperty("bintray.apikey")   //读取 local.properties 文件里面的 bintray.apikey
    configurations = ['archives']
    pkg {
        repo = "maven" //需要上传到的仓库名(Repository)对应(Create Repository页面填写的name)
        name = "mylibrary"    //发布到JCenter上的项目名字,必须填写,对应com.squareup.okhttp3:okhttp:3.4.1中的okhttp
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = ["Apache-2.0"]
        publish = true
    }
}
  1. 在需上传的library的build.gradle中配置
apply from: '../bintray.gradle'
  1. 在Terminal中 依次输入
gradlew install

显示BUILD SUCCESSFUL

gradlew bintrayUpload

显示BUILD SUCCESSFUL

  1. 在View Profile页中进入自己建的仓库中
    —>点击进入自己上传的项目
    —>点击Files 查看目录下是否含有xx-javadoc.jar、xx-sources.jar、xx.aar、xx.pom等四个文件(即上传成功)
    —>然后点击Add to JCenter填写信息直接提交

从JCenter中拉取代码

1.直接在app 的build.gradle中添加依赖

implementation 'xxx:1.0.0'
  1. Add to JCenter审核通过之前需要在project 中的build.gradle中配置,审核通过后则无需配置
allprojects {
    repositories {
        jcenter()
        maven {
            url "https://dl.bintray.com/username/RepositoryName/" //在所在仓库界面有直接复制即可
        }
    }
}
  • 注:借鉴多人的博客,做个笔记

你可能感兴趣的:(Android)