将项目添加到jCenter库 - novode

当我们写完一个项目后,如果有个非常好的组件想要共享给其他开发者使用,我们就需要将组件上传到JCenter库中,通过gradel进行组件下载使用。

JCenter仓库的管理网站是 Bintray  https://bintray.com/helloing6/maven/MyLibrary 。 需要将我们的代码上传到该网上,才可以共大家使用,但是因为Bintray提供的上传步骤太复杂,我们现在使用第三方的组件进行上传novode plug。

使用novede上传代码的配置如下:

第一步:在项目gradle中添加插件

classpath 'com.novoda:bintray-release:0.5.0'

第二步:在lib modle 模块的gradle中添加插件(必须是lib module才可以)

apply plugin: 'com.novoda.bintray-release'//上传jcenter

//上传jcenter
publish {
    userOrg = 'helloing6'//bintray.com用户名
    groupId = 'com.malei.mylib'//jcenter上的路径,根据自己项目自定义填写
    artifactId = 'MyLibrary'//项目名称
    publishVersion = '1.0.0'//版本号
    desc = 'this is for test'//描述,不重要
    website = 'https://bintray.com/malei/MyLibrary'//网站,最好有,不重要
}
第三步:添加完配置后,我们就需要将lib module添加到bintray上了。

在Android Studio的Terminal window,执行命令行:

./gradlew clean build bintrayUpload -PbintrayUser={bintray user} -PbintrayKey={bintray api key} -PdryRun=false -x releaseAndroidJavadocs
(注意,windows系统,命令行前面不需要./)
bintray user 就是bintray注册用户名;
bintray api key 是 API Key.
最后,在过程中遇到的问题总结:

1.Error:Execution failed for task ‘:viewpagerutilslib-v1:bintrayUpload’.> Could not create package> ‘xxxxx/maven/xxxxxxxxx’: HTTP/1.1 401 Unauthorized

401 这个错误很明显是认证错误,可能是你的用户名或者API key错了


2.Error:Execution failed for task ‘:viewpagerutilslib-v1:bintrayUpload’.> Could not create package> ‘xxxxxx/maven/xxxxx’: HTTP/1.1 404 Not Found

这个404问题比较坑爹,卡在这里绝大部分时间首先你在上传library到bintray之前,你需要先在bintrary new一个仓库名称和type都应该是maven 
这里写图片描述 
其次:新建maven项目后从网址能看到你的用户名,比如我的https://bintray.com/huyuxin95/maven
与userOrg = ‘huyuxin95’对应,但是userOrg不一定与登录用户名-PbintrayUser=*一样!) 
这里写图片描述


3.androidstudio mavenAndroidJavadocs FAILED GBK编码不可映射

这是因为你的注释有中文,在项目的build.gradle中添加:

 allprojects {
    tasks.withType(Javadoc) {
        options{
            encoding "UTF-8"
            charSet 'UTF-8'
            links "http://docs.oracle.com/javase/7/docs/api"
        }
    }
}
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

4.批处理macOS与windows的区别 
macos:

 ./gradlew clean build bintrayUpload 
 -PbintrayUser=hyman 
 -PbintrayKey=xxxxxxxxxxxxxxxxxxxxxx 
 -PdryRun=false
   
   
  • 1
  • 2
  • 3
  • 4

windows

gradlew.bat clean build bintrayUpload 
 -PbintrayUser=huyuxin 
 -PbintrayKey=32d8bc328c5131d7c76f5205333f2df5d2744632
 -PdryRun=false
   
   
  • 1
  • 2
  • 3
  • 4

如果你的windows还没安装gradlew.bat,他会帮你先下载,大概70M,但是如果网络差你可以将提示的下载地址复制到浏览器或者迅雷用第三方下载工具下载,这样快点,手动下载完复制到C:\Users\username\.gradle\wrapper\dists\gradle-指定版本-all\随机字符的文件夹下重启AS,再运行

gradlew.bat clean build bintrayUpload 
 -PbintrayUser=huyuxin 
 -PbintrayKey=32d8bc328c5131d7c76f5205333f2df5d2744632
 -PdryRun=false
   
   
  • 1
  • 2
  • 3
  • 4

他解压好压缩包就可以了


5.提示这样的错误

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:lint'.
> Lint found errors in the project; aborting build.

Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
    lintOptions {
        abortOnError false
    }
}
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

直接在library的build.gradle的android下 添加即可 
如:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    lintOptions{
        abortOnError false
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

问题解决来源:

https://blog.csdn.net/daydayplayphone/article/details/53503856








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值