天天看点

自己创建一个android studio在线依赖compile

引言

相信大家在使用AS(android studio)的时候添加依赖的时候有没见过如下方式:

自己创建一个android studio在线依赖compile

很酷炫 本人将教你如何做到.

实现方法

  1. 使用 jcenter()实现— 在创建的时候as自动帮我导入了
    自己创建一个android studio在线依赖compile
    但是上传代码到jcenter非常繁琐所以本文不做此方法
  2. jitpack.io()实现 — 此方法配合github使用相比第一种简单非常多 本文以此方法教学.官方文档jitpack文档

具体步骤

  1. 在github 新建一个空白仓库github地址
    自己创建一个android studio在线依赖compile
    自己创建一个android studio在线依赖compile
  2. TortoiseGit克隆到本地
    自己创建一个android studio在线依赖compile
  3. 在克隆下的文件夹下创建一个as项目(用as)
    自己创建一个android studio在线依赖compile
    自己创建一个android studio在线依赖compile
    自己创建一个android studio在线依赖compile
  4. 在as创建一个library module

    在菜单栏File-New-New Module

    自己创建一个android studio在线依赖compile

    选择Android Libray(这种叫aar可以带入资源如图片)

    这里我顺便补充下java Libary 不会带入android资源文件 所以我们一般使用android library

    自己创建一个android studio在线依赖compile
  5. 编写library module

    这里看你想怎么写了 我这里随便写了个类FmyUtils

    自己创建一个android studio在线依赖compile
  6. gradle设置
    1. 在你工程的gradle下添加如下信息
    buildscript { 
      dependencies {
        ....
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // Add this line
        ...
        }
               
    自己创建一个android studio在线依赖compile
    1. 在你的library 的gradle 添加如下依赖
    apply plugin: 'com.github.dcendents.android-maven'  
     group='com.github.YourUsername'
               
    自己创建一个android studio在线依赖compile
  7. 上传到github
    忽略工程中原有app(没用) Android项目一般需要忽略.idea文件夹、.gradle文件夹、所有的build文件夹、所有的.iml文件及local.properties文件。svn忽略和使用 和github差不多 大家可以当作扩张知识
  8. 在github创建release
    自己创建一个android studio在线依赖compile
    自己创建一个android studio在线依赖compile
  9. jitpack搜索对应github仓库
    1. 打开jitpack官网 点击搜索框 输入github地址
      自己创建一个android studio在线依赖compile
自己创建一个android studio在线依赖compile

然后网页的下方会有提示

自己创建一个android studio在线依赖compile

把这里信息复制到 你想导入依赖的工程

如下:

我先新建一个AS 工程

然后再工程的gradle添加上面获取的信息

自己创建一个android studio在线依赖compile

最后在你想要将依赖添加到的module的gradle中添加如下代码

自己创建一个android studio在线依赖compile

最后同步一下即可

最后我们测试下 ---->>ok
           
自己创建一个android studio在线依赖compile