Github上发布自己的Android框架

作者: 12313凯皇 | 来源:发表于2019-01-31 19:11 被阅读201次

      在做大创的过程中经常在github上面找开源的项目用,但有的时候发现很难找到完全适合自己框架,于是突发奇想自己release一个项目自己用。下面记录一下具体步骤:

    发布

    1. 首先完成自己制作的框架代码,然后去github上面新建一个对应的代码仓库,在这就不多说了。
    2. 在项目根目录build.gradle中添加配置
     buildscript { 
      ...
      dependencies {
           ...
           classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'  // 添加本行,这个版本与gradle版本有关
      }
    }
    
    1. Library Modulebuild.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重新编译一下。

    1. AndroidManifest.xml文件中的<intent-filter>标签注释掉,否则会出现引用后出现两个app图标的情况。
    <application
          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">
          <activity android:name=".MainActivity">
               <!--注释掉-->
               <!--<intent-filter>-->
                    <!--<action android:name="android.intent.action.MAIN" />-->
    
                    <!--<category android:name="android.intent.category.LAUNCHER" />-->
                <!--</intent-filter>-->
          </activity>
     </application>
    
    1. release发布
    • 点击release
    • 点击Create a new release
    • 填好信息就可以发布了


    1. 进入https://jitpack.io/网址,然后输入项目名称

      发布失败的话可以点击log在最后面查看失败原因,成功的话就点击Get It查看在gradle,Maven等导入方式。

    导入AndroidStudio

    发布成功的话导入就比较简单了,按照提示Ctrl+C,Ctrl+V就好了。

    1. 在项目根目录的build.gradle中加入依赖
    allprojects {
            repositories {
                ...
                maven { url 'https://jitpack.io' }
            }
        }
    
    1. appbuild.gradle中加入依赖
    dependencies {
                implementation 'com.github.12313kaihuang:SearchView:2.0'
        }
    

    相关文章

      网友评论

        本文标题:Github上发布自己的Android框架

        本文链接:https://www.haomeiwen.com/subject/frdlsqtx.html