開發Android也有一定的年頭的,承蒙大神們通過不懈的努力帶給我們衆多的便利!或許也到自己貢獻的時候了,那麼我們先學習一下如何構建自己的庫,並且在gradle中的引用!
步驟
前期準備:
新建一個project,提交到github上面去
創建lib的module
這個module裏的代碼就是別人可以引用的代碼
創建你分享的代碼,例如下圖
在github上創建release版本
把所有的代碼提交到github上面後,如下圖所示在github上創建release版本
jitpack上獲取路徑
生成release包之後開始,打開https://jitpack.io,登錄自己的github賬號,把倉庫的地址複製進去即可,如果log圖標和status的按鈕都是原諒色,那麼恭喜你,成功了。點擊get it,下面有引入教程
引用自己的庫
跳坑
project目錄下的build.gradle設置
//低版本的gradle使用的plugin也相應會低一點 classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
module目錄下的build.gradle設置
apply plugin: 'com.github.dcendents.android-maven' group='com.github.KubyWong'//com.github.{你的的賬號名}
https://jitpack.io紅色log如何處理
如上圖,正確的情況下log是綠色的,搞這個的時候感覺有點背,無論怎麼提交都是出錯的,在項目中當然也無法正常引入。當出現下面這個問題的時候,別想了,重新來一次創建流程。(起一個project,放到github上,創建release版本,jitpack中獲取狀態信息)
Build starting...
Start: Thu Jun 27 14:34:38 UTC 2019 861df077f5ba
Git:
1.2.3-0-gd0f9aee
commit d0f9aeec13db0bbe6abd4aafeffc6bda18f423a7
Author: KubyHuang
Date: Thu Jun 27 22:29:49 2019 +0800
使用1.5的插件地址
com.github.dcendents:android-maven-gradle-plugin:1.5
Found Android manifest
Android SDK version: 28. Build tools: 29.0.0
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Warning: File /opt/android-sdk-linux/.android/repositories.cfg could not be loaded.
Installing Android platform 28
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Warning: File /opt/android-sdk-linux/.android/repositories.cfg could not be loaded.
Installing Build-tools 29.0.0
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Warning: File /opt/android-sdk-linux/.android/repositories.cfg could not be loaded.
Found gradle
Gradle build script
Using gradle wrapper
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Downloading https://services.gradle.org/distributions/gradle-5.1.1-all.zip
.
Unzipping /home/jitpack/.gradle/wrapper/dists/gradle-5.1.1-all/97z1ksx6lirer3kbvdnh7jtjg/gradle-5.1.1-all.zip to /home/jitpack/.gradle/wrapper/dists/gradle-5.1.1-all/97z1ksx6lirer3kbvdnh7jtjg
Set executable permissions for: /home/jitpack/.gradle/wrapper/dists/gradle-5.1.1-all/97z1ksx6lirer3kbvdnh7jtjg/gradle-5.1.1/bin/gradle
Welcome to Gradle 5.1.1!
Here are the highlights of this release:
- Control which dependencies can be retrieved from which repositories
- Production-ready configuration avoidance APIs
For more details see https://docs.gradle.org/5.1.1/release-notes.html
------------------------------------------------------------
Gradle 5.1.1
------------------------------------------------------------
Build time: 2019-01-10 23:05:02 UTC
Revision: 3c9abb645fb83932c44e8610642393ad62116807
Kotlin DSL: 1.1.1
Kotlin: 1.3.11
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 1.8.0_191 (Oracle Corporation 25.191-b12)
OS: Linux 4.14.63-xxxx-std-ipv6-64 amd64
Getting tasks: ./gradlew tasks --all
0m4.655s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Tasks:
WARNING:
Gradle 'install' task not found. Please add the 'maven' or 'android-maven' plugin.
See the documentation and examples: https://jitpack.io/docs/
Adding maven plugin
Found android library build file in app
Running: ./gradlew clean -Pgroup=com.github.KubyWong -Pversion=1.2.3 install
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
> Configure project :
Gradle version Gradle 5.1.1
FAILURE: Build failed with an exception.
* What went wrong:
Task 'install' not found in root project 'build'.
* Try:
Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
Build tool exit code: 0
Looking for artifacts...
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Looking for pom.xml in build directory and ~/.m2
2019-06-27T14:35:20.897507593Z
Exit code: 0
ERROR: No build artifacts found