在做大创的过程中经常在github上面找开源的项目用,但有的时候发现很难找到完全适合自己框架,于是突发奇想自己release一个项目自己用。下面记录一下具体步骤:
发布
首先完成自己制作的框架代码,然后去github上面新建一个对应的代码仓库,在这就不多说了。
在项目根目录的build.gradle中添加配置
buildscript {
...
dependencies {
...
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' // 添加本行,这个版本与gradle版本有关
}
}
在Library Module的build.gradle添加配置
把 apply plugin: 'com.android.application' 改为 apply plugin: 'com.android.library'
添加apply plugin: 'com.github.dcendents.android-maven'和group='com.github.xxx' ,xxx是你的github的用户名。
去掉 applicationId
//apply plugin: 'com.android.application' 注释掉
apply plugin: 'com.android.library' //添加列
apply plugin:'com.github.dcendents.android-maven' //添加列
group='com.github.12313kaihuang' //添加列
android {
compileSdkVersion 26
defaultConfig {
// applicationId "android.searchview" 注释掉
...
}
}
【注】添加以下配置,否则上传后的jar包看不到注释
// 指定编码
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
// 打包源码
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
failOnError false
source = android.sourceSets.main.java.sourceFiles
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
classpath += configurations.compile
}
// 制作文档(Javadoc)
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
修改完文件别忘了点击Sync Now重新编译一下。
将AndroidManifest.xml文件中的标签注释掉,否则会出现引用后出现两个app图标的情况。
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
release发布
点击release
点击Create a new release
填好信息就可以发布了
进入https://jitpack.io/网址,然后输入项目名称
发布失败的话可以点击log在最后面查看失败原因,成功的话就点击Get It查看在gradle,Maven等导入方式。
导入AndroidStudio
发布成功的话导入就比较简单了,按照提示Ctrl+C,Ctrl+V就好了。
在项目根目录的build.gradle中加入依赖
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
在app的build.gradle中加入依赖
dependencies {
implementation 'com.github.12313kaihuang:SearchView:2.0'
}