記一次提交項(xiàng)目到j(luò)itpack,按正常邏輯是
1.上傳項(xiàng)目至github
2.添加release
3.jitpack.io去get it
流程圖如下:
項(xiàng)目提交到github后拼苍,去創(chuàng)建一個release版本
點(diǎn)擊添加Release版本,填寫版本號纷妆、標(biāo)題猾担、描述
jitpack點(diǎn)擊get it拧抖,log圖標(biāo)綠色是成功秃殉,紅色是報(bào)錯
步驟可以說是非常簡潔了,但是就這幾步驟,卻從昨天下午就開始難住了我,
jitpack.io上一直打包不成功奸鸯。
1.查看版本庫對應(yīng)
第一步看報(bào)錯信息咪笑,log報(bào)錯提示Minimum supported Gradle version is 5.4.1.
> Failed to apply plugin [id 'com.android.library']
> Minimum supported Gradle version is 5.4.1. Current version is 4.8. If using the gradle wrapper, try editing the distributionUrl in /home/jitpack/build/gradle/wrapper/gradle-wrapper.properties to gradle-5.4.1-all.zip
就是提示項(xiàng)目最少支持5.4.1,但是我使用的4.8娄涩。
這里我們需要去檢查項(xiàng)目下build.gradle使用的插件版本和/gradle/wrapper/gradle-wrapper.properties文件所使用的版本窗怒。
放一張版本對比圖,最新的版本可以去google官網(wǎng)查看gradle插件對應(yīng)版本
build.gralde使用3.5.0-3.5.3
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
}
}
/gradle/wrapper/gradle-wrapper.properties文件中使用的為5.4.1
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
2.使用android-maven-gradle-plugin
檢查發(fā)現(xiàn)項(xiàng)目對應(yīng)的版本沒錯蓄拣,找到其他文章說使用android-maven-gradle-plugin插件來解決
首先繼續(xù)到官網(wǎng)查找版本對應(yīng)庫android-maven-gradle-plugin版本對應(yīng)庫
看到最新版為2.1支持gradle4.6以上,我們在項(xiàng)目的build.gradle中添加依賴如下
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}
在module的build.gradle中添加
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven' //幫你發(fā)布到j(luò)center
group="com.github.xxxx"http://xxxx為你的用戶名
到這里我們在去嘗試打包發(fā)布扬虚,失敗,報(bào)錯信息相同G蛐簟9缄恰!
3.全局忽略文件夾.gitignore_global
繼續(xù)查找發(fā)現(xiàn)github提交的里面具體無/gradle/wrapper/文件夾
這是個什么坑咽斧,我再次新建了一個新的項(xiàng)目查看原因發(fā)現(xiàn)項(xiàng)目創(chuàng)建時添加了默認(rèn)的ignore配置堪置,為.gitignore_global,這是個全局的忽略配置。全局配置中忽略了/gradle/wrapper/文件夾
window的文件路徑是C:\Users\xxxx.gitignore_global
mac該文件的路徑為/Users/xxx/.gitignore_global
當(dāng)時創(chuàng)建該配置信息是在公司為了方便拉取代碼张惹,當(dāng)然我也無權(quán)創(chuàng)建新項(xiàng)目舀锨,誰能想到我自己還去開源,就是如此的安逸且枯燥巴鸲骸?材洹!
為了防止該問題繼續(xù)發(fā)生拧额,直接刪除了全局配置碑诉,然后直接去修改androidstudio生成新項(xiàng)目所使用ignore模板彪腔,這樣直觀的查看文件是否被忽略
mac修改路徑為
/Applications/Android Studio.app/Contents/plugins/android/lib/templates/gradle-projects/NewAndroidProject/root
window修改路徑為
Android Studio安裝目錄/plugins/android/lib/templates/gradle-projects/NewAndroidProject/root
我們?nèi)バ薷膒roject_ignore文件侥锦,給出github上的gitignore模板,按需要自行修改德挣。我們保存好后重啟即可恭垦。
# Built application files
*.apk
*.aar
*.ap_
*.aab
# Files for the ART/Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
out/
# Uncomment the following line in case you need and you don't have the release build type files in your app
# release/
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
# Android Studio captures folder
captures/
# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml
# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore
# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
.cxx/
# Google Services (e.g. APIs or Firebase)
# google-services.json
# Freeline
freeline.py
freeline/
freeline_project_description.json
# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md
# Version control
vcs.xml
# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/
到這里我重新關(guān)聯(lián)git,再去提交就可以生成了!