AS构建本地maven或者远程maven仓库

AS构建本地maven或者远程maven仓库

构建maven,配置生成arr,Library下的build.gradle完整配置

apply plugin: 'com.android.library'

apply plugin: 'maven'

android {
  compileSdkVersion 28
  defaultConfig {
    minSdkVersion 19
    targetSdkVersion 28
    versionCode 1
    versionName "1.0.0.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  }

  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }

}

dependencies {
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  testImplementation 'junit:junit:4.12'
  implementation 'com.android.support:design:28.0.0-alpha3'
  androidTestImplementation 'com.android.support.test:runner:1.0.1'
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

ext {
  GITHUB_REPO_PATH = "F:\\private_code_source\\wheel"//本地储存路径
 
  PUBLISH_GROUP_ID = 'com.wheel'//包名

  PUBLISH_ARTIFACT_ID = 'tools'//自定义名

  PUBLISH_VERSION = '1.1.6'//版本号,每一次更新迭代升级版本
}
/**
 *uploadArchives,运行生成aar包
 **/
uploadArchives {
  repositories.mavenDeployer {
    def deployPath = file(project.GITHUB_REPO_PATH)
    repository(url: "file://${deployPath.absolutePath}")
    pom.project {
       groupId project.PUBLISH_GROUP_ID
       artifactId project.PUBLISH_ARTIFACT_ID
       version project.PUBLISH_VERSION
    }
  }
}
// 源代码一起打包(不需要打包源代码的不要添加这几行)
task androidSourcesJar(type: Jar) {
  classifier = 'sources'
  from android.sourceSets.main.java.sourceFiles
}
artifacts {
  archives androidSourcesJar
}
repositories {
  mavenCentral()
}
  1. 配置完成以后,在工具Terminal运行编译 gradlew uploadArchives,如下图

    微信截图_20181212174425.png
  2. 编译成功后,在本地打开上边配置的路径,如下图

    微信截图_20181212174846.png
    微信截图_20181212174904.png

以上步骤完成,到此aar maven生成完毕,下边我们来引用

引用本地maven aar

  1. 项目根build.gradle,添加配置添加依赖路径,如下图

    微信截图_20181212180318.png
  2. app/build.gradle,添加配置引用依赖

    微信截图_20181212180400.png

运行编译成功即可

提交本地maven aar到远程仓库github,引用远程依赖

  1. 注册github账号,新建project创建仓库,如下图

    微信截图_20181213093122.png
  2. 创建远程仓库成功,把本地的maven通过git命令上传到此仓库(git命令参考 https://www.jianshu.com/p/129d98b2098d,https://www.jianshu.com/p/8885b6cd5aca),如下图上传成功

    微信截图_20181213093307.png
  3. aar上传远程仓库,引用远程依赖,配置方式跟本地maven一样,只是引用路径修改一下,GitHub远程仓库路径(https://raw.githubusercontent.com/路径),如下图

    微信截图_20181213094738.png

到此AS构建本地maven或者远程maven仓库完成,多谢大家支持!

你可能感兴趣的:(AS构建本地maven或者远程maven仓库)