2018-04-26 遇到的一点小问题
准备把项目里的一个库,打包成aar后引用,网上找了下,很多相关的,步骤也很简单。但是引用后运行却出错了java.lang.NoClassDefFoundError: Failed resolution of
。网上找了下看到2.1 以外部compile形式所依赖的包,也不会被打包进aar难怪打的aar那么小。需要的外部引用还要自己用这个aar的时候再写一遍好吧,感觉太麻烦了。放弃,换个方法。
网上找了下,很多制作maven的方法,而且刚好看到依赖本地maven仓库的方法,挺好的,试试看。
虽然遇到些问题,但弄出来了,不过还得搭本地仓库,算了,这些留着下次想起来另外写一篇。
使用jCenter仓库
试试使用jCenter仓库,这样下次依赖可以方便点。网上找了下正好看到这篇写了很多字数的文,试试看。先去Bintray注册账号,这个网上找一下很多,懒得复制了。
不过我用GitHub账号登录时却失败了,因为GitHub那里用的是qq邮箱注册,而Bintray无法使用又无法修改。twitter基本不用,所以用的Google账号登录绑定注册。为了下次也能直接用GitHub账号登录,又上个人中心的Accounts里绑定GitHub账号,这样下次也能直接GitHub登录了。
.
弄好相关信息后,开始按照文章里写的在项目的build.gradle
里添加classpath 'com.novoda:bintray-release:0.3.4'
,但马上就报错了。Gradle sync failed: Cause: org.gradle.api.internal.component.Usage
Consult IDE log for more details
Unable to load class 'org.gradle.api.internal.component.Usage'.
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)</li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)</li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
虽然详细信息看不懂,但可以猜测是版本过低导致的。
因为作者没说他使用的是novoda/bintray-release来进行打包上传。所以只好网上再找找相关资料,正好看到里面写的第二种方法讲到novoda/bintray-release,然后点进去看了下,最新版本是
0.8.1
。然后在项目的build.gradle
里添加新版本就可以了。
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.novoda:bintray-release:0.8.1'
}
.
按README.md里的说明,在Module的build.gradle
填写:
apply plugin: 'com.novoda.bintray-release'
publish {
userOrg = 'novoda'//bintray.com用户名
groupId = 'com.novoda'//引用路径
artifactId = 'bintray-release'//项目名称
publishVersion = '0.6.1'//版本号
desc = 'Oh hi, this is a nice description for a project, right?'//描述
website = 'https://github.com/novoda/bintray-release'//网站
}
.
填写好后继续按要求在Terminal面板操作,输入命令:
gradlew clean build bintrayUpload -PbintrayUser=用户名 -PbintrayKey=APIKey -PdryRun=false
.
然后并没有按文章上说的正常完成,而是出现错误信息:Android gradle Unsupported major.minor version 52.0。网上查了下,说是JDK版本问题,正好也有提示Support for running Gradle using Java 7 has been deprecated and is scheduled to be removed in Gradle 5.0. Please see https://docs.gradle.org/4.4/userguide/java_plugin.html#sec:java_cross_compilation for more details.
。因为之前电脑的jdk是jdk1.7.0_79,所以这次就顺便下载了最新的jdk1.8.0_172并配置了环境变量。配好后又测试,结果还是一直不行。折腾很久无奈又网上找了下,才发现配置环境变量后要重启电脑。。。
.
重启后再测试,这次运行时间长了点,以为快可以时,又出问题了。错误: 编码GBK的不可映射字符
> Task :jpush:releaseAndroidJavadocs FAILED
错误: 编码GBK的不可映射字符
100 个错误
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':jpush:releaseAndroidJavadocs'.
> Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting):
'D:\rrg\OD\Lib\wannoo\build\tmp\releaseAndroidJavadocs\javadoc.options'
试着在网上找找解决方法,出来的一堆都是类似方法,比如在项目的
build.gradle
最外层添加tasks.withType(JavaCompile){options.encoding = 'UTF-8'},
或者GroovyCompile
或者Javadoc
可惜都试了遍还是不行,问题依然存在。又试着改Android Studio的File Encodings设置、新建GRADLE_OPTS环境变量、修改单文件的encoding、、、结果统统不行。
快放弃时突然想起用的是novoda/bintray-release,说不定issues里会有相关的问题。找了一下,果然看到了LuckyJayce的回答。赶紧在项目的build.gradle
的allprojects
里添加添加代码试一下:
tasks.withType(Javadoc) {
options{
encoding "UTF-8"
charSet 'UTF-8'
links "http://docs.oracle.com/javase/7/docs/api"
}
}
编码的问题总是解决了,不过,重试又出现了新的问题了。
org.apache.http.conn.HttpHostConnectException: Connection to https://api.bintray.com refused
网络问题,应该是小问题,再试试看。出现绿色的BUILD SUCCESSFUL,总算可以了。
然后就是项目里引用,奇怪的是在Add toJCenter审核通过前一直无法连接上,试了好多方法,一直没搞懂。然后审核通过了,不用写个人地址也能连接上了,没法再测试了,过阵子不忙再试试看吧。