当前位置:   article > 正文

Android如何构建自己的库在build.gradle中引用-教程+跳坑_在build.gradle中添加资源引用

在build.gradle中添加资源引用

开发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中获取状态信息)

  1. Build starting...
  2. Start: Thu Jun 27 14:34:38 UTC 2019 861df077f5ba
  3. Git:
  4. 1.2.3-0-gd0f9aee
  5. commit d0f9aeec13db0bbe6abd4aafeffc6bda18f423a7
  6. Author: KubyHuang
  7. Date:   Thu Jun 27 22:29:49 2019 +0800
  8.     使用1.5的插件地址
  9.     com.github.dcendents:android-maven-gradle-plugin:1.5
  10. Found Android manifest
  11. Android SDK version: 28. Build tools: 29.0.0
  12. Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
  13. Warning: File /opt/android-sdk-linux/.android/repositories.cfg could not be loaded.
  14. Installing Android platform 28
  15. Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
  16. Warning: File /opt/android-sdk-linux/.android/repositories.cfg could not be loaded.
  17. Installing Build-tools 29.0.0
  18. Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
  19. Warning: File /opt/android-sdk-linux/.android/repositories.cfg could not be loaded.
  20. Found gradle
  21. Gradle build script
  22. Using gradle wrapper
  23. Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
  24. Downloading https://services.gradle.org/distributions/gradle-5.1.1-all.zip
  25. .
  26. 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
  27. Set executable permissions for: /home/jitpack/.gradle/wrapper/dists/gradle-5.1.1-all/97z1ksx6lirer3kbvdnh7jtjg/gradle-5.1.1/bin/gradle
  28. Welcome to Gradle 5.1.1!
  29. Here are the highlights of this release:
  30. - Control which dependencies can be retrieved from which repositories
  31. - Production-ready configuration avoidance APIs
  32. For more details see https://docs.gradle.org/5.1.1/release-notes.html
  33. ------------------------------------------------------------
  34. Gradle 5.1.1
  35. ------------------------------------------------------------
  36. Build time:   2019-01-10 23:05:02 UTC
  37. Revision:     3c9abb645fb83932c44e8610642393ad62116807
  38. Kotlin DSL:   1.1.1
  39. Kotlin:       1.3.11
  40. Groovy:       2.5.4
  41. Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
  42. JVM:          1.8.0_191 (Oracle Corporation 25.191-b12)
  43. OS:           Linux 4.14.63-xxxx-std-ipv6-64 amd64
  44. Getting tasks: ./gradlew tasks --all
  45. 0m4.655s
  46. Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
  47. Tasks: 
  48. WARNING:
  49. Gradle 'install' task not found. Please add the 'maven' or 'android-maven' plugin.
  50. See the documentation and examples: https://jitpack.io/docs/
  51. Adding maven plugin
  52. Found android library build file in app
  53. Running: ./gradlew clean -Pgroup=com.github.KubyWong -Pversion=1.2.3 install
  54. Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
  55. > Configure project :
  56. Gradle version Gradle 5.1.1
  57. FAILURE: Build failed with an exception.
  58. * What went wrong:
  59. Task 'install' not found in root project 'build'.
  60. * Try:
  61. 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.
  62. * Get more help at https://help.gradle.org
  63. BUILD FAILED in 1s
  64. Build tool exit code: 0
  65. Looking for artifacts...
  66. Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
  67. Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
  68. Looking for pom.xml in build directory and ~/.m2
  69. 2019-06-27T14:35:20.897507593Z
  70. Exit code: 0
  71. ERROR: No build artifacts found

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/796510
推荐阅读
相关标签
  

闽ICP备14008679号