Android创建一个依赖库


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

Android创建一个依赖库

实现方法:

1.先创建一个空项目上传到Github

2.使用 jcenter()实现— 在创建的时候as自动帮我导入了 (工程下buile)

Android创建一个依赖库

classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

3.model下build.gradle中application改为library(一个库),并添加下面两行

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.dialog'

最后一行是你github的名字


4.将这个中的applicationId删除掉

defaultConfig {
    applicationId "com.github.mytest"
    minSdkVersion 18
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
删掉后为:

defaultConfig {
    minSdkVersion 18
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
5.在github创建release 

Android创建一个依赖库

6.点击release   (对应的是库的版本号)

Android创建一个依赖库

7.jitpack搜索对应的github仓库

打开jitpack官网 点击搜索框 输入github地址 

Android创建一个依赖库

Android创建一个依赖库

然后会出现提示:

Android创建一个依赖库

把这里信息复制到 你想导入依赖的工程 
如下: 
我先新建一个AS 工程 
然后再工程的gradle添加上面获取的信息 

Android创建一个依赖库

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

Android创建一个依赖库

最后同步一下,就可以测试了。

相关文章:

  • 2021-09-08
  • 2021-07-28
  • 2022-01-07
  • 2021-07-18
  • 2022-02-14
  • 2021-10-24
  • 2021-08-20
猜你喜欢
  • 2021-09-13
  • 2022-12-23
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
相关资源
相似解决方案