2018-04-26 遇到的一點(diǎn)小問題
準(zhǔn)備把項(xiàng)目里的一個(gè)庫,打包成aar后引用,網(wǎng)上找了下,很多相關(guān)的,步驟也很簡單。但是引用后運(yùn)行卻出錯(cuò)了java.lang.NoClassDefFoundError: Failed resolution of。網(wǎng)上找了下看到2.1 以外部compile形式所依賴的包,也不會(huì)被打包進(jìn)aar難怪打的aar那么小。需要的外部引用還要自己用這個(gè)aar的時(shí)候再寫一遍好吧,感覺太麻煩了。放棄,換個(gè)方法。

網(wǎng)上找了下,很多制作maven的方法,而且剛好看到依賴本地maven倉庫的方法,挺好的,試試看。
雖然遇到些問題,但弄出來了,不過還得搭本地倉庫,算了,這些留著下次想起來另外寫一篇。
使用jCenter倉庫
試試使用jCenter倉庫,這樣下次依賴可以方便點(diǎn)。網(wǎng)上找了下正好看到這篇寫了很多字?jǐn)?shù)的文,試試看。先去Bintray注冊賬號(hào),這個(gè)網(wǎng)上找一下很多,懶得復(fù)制了。
不過我用GitHub賬號(hào)登錄時(shí)卻失敗了,因?yàn)镚itHub那里用的是qq郵箱注冊,而Bintray無法使用又無法修改。twitter基本不用,所以用的Google賬號(hào)登錄綁定注冊。為了下次也能直接用GitHub賬號(hào)登錄,又上個(gè)人中心的Accounts里綁定GitHub賬號(hào),這樣下次也能直接GitHub登錄了。
.
弄好相關(guān)信息后,開始按照文章里寫的在項(xiàng)目的build.gradle里添加classpath 'com.novoda:bintray-release:0.3.4',但馬上就報(bào)錯(cuò)了。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.

雖然詳細(xì)信息看不懂,但可以猜測是版本過低導(dǎo)致的。
因?yàn)樽髡邲]說他使用的是novoda/bintray-release來進(jìn)行打包上傳。所以只好網(wǎng)上再找找相關(guān)資料,正好看到里面寫的第二種方法講到novoda/bintray-release,然后點(diǎn)進(jìn)去看了下,最新版本是
0.8.1。然后在項(xiàng)目的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'//項(xiàng)目名稱
publishVersion = '0.6.1'//版本號(hào)
desc = 'Oh hi, this is a nice description for a project, right?'//描述
website = 'https://github.com/novoda/bintray-release'//網(wǎng)站
}
.
填寫好后繼續(xù)按要求在Terminal面板操作,輸入命令:
gradlew clean build bintrayUpload -PbintrayUser=用戶名 -PbintrayKey=APIKey -PdryRun=false

.
然后并沒有按文章上說的正常完成,而是出現(xiàn)錯(cuò)誤信息:Android gradle Unsupported major.minor version 52.0。網(wǎng)上查了下,說是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.。因?yàn)橹半娔X的jdk是jdk1.7.0_79,所以這次就順便下載了最新的jdk1.8.0_172并配置了環(huán)境變量。配好后又測試,結(jié)果還是一直不行。折騰很久無奈又網(wǎng)上找了下,才發(fā)現(xiàn)配置環(huán)境變量后要重啟電腦。。。
.
重啟后再測試,這次運(yùn)行時(shí)間長了點(diǎn),以為快可以時(shí),又出問題了。錯(cuò)誤: 編碼GBK的不可映射字符
> Task :jpush:releaseAndroidJavadocs FAILED
錯(cuò)誤: 編碼GBK的不可映射字符
100 個(gè)錯(cuò)誤
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'

試著在網(wǎng)上找找解決方法,出來的一堆都是類似方法,比如在項(xiàng)目的
build.gradle最外層添加tasks.withType(JavaCompile){options.encoding = 'UTF-8'},或者GroovyCompile或者Javadoc可惜都試了遍還是不行,問題依然存在。又試著改Android Studio的File Encodings設(shè)置、新建GRADLE_OPTS環(huán)境變量、修改單文件的encoding、、、結(jié)果統(tǒng)統(tǒng)不行。
快放棄時(shí)突然想起用的是novoda/bintray-release,說不定issues里會(huì)有相關(guān)的問題。找了一下,果然看到了LuckyJayce的回答。趕緊在項(xiàng)目的build.gradle的allprojects里添加添加代碼試一下:
tasks.withType(Javadoc) {
options{
encoding "UTF-8"
charSet 'UTF-8'
links "http://docs.oracle.com/javase/7/docs/api"
}
}

編碼的問題總是解決了,不過,重試又出現(xiàn)了新的問題了。
org.apache.http.conn.HttpHostConnectException: Connection to https://api.bintray.com refused

網(wǎng)絡(luò)問題,應(yīng)該是小問題,再試試看。出現(xiàn)綠色的BUILD SUCCESSFUL,總算可以了。
然后就是項(xiàng)目里引用,奇怪的是在Add toJCenter審核通過前一直無法連接上,試了好多方法,一直沒搞懂。然后審核通過了,不用寫個(gè)人地址也能連接上了,沒法再測試了,過陣子不忙再試試看吧。