1. 程式人生 > >《GitHub》上傳自己的module到github作為庫給別人使用(草稿待修正)

《GitHub》上傳自己的module到github作為庫給別人使用(草稿待修正)

一直在想做這個,昨天試了一天終於完成了

首先我們要明確的第一點內容就是我們是module作為庫給別人使用的。

所以我們建立的project的時候一定要再建立一個module,然後將庫的內容放在這個module裡面。

1: 建立一個專案

2: 建立一個新的module,選擇Android Library

3: 上傳改專案到github上面

4: 在gihub 上面生成release

5: 使用github的賬號 https://jitpack.io  ,然後會在專案裡面找到這個專案,點選該專案的“git”的按鈕

6: 在其他的專案裡面就可以訪問了

修改project的gradle,新增classpath兩個,

還有就是maven的那個 maven { url 'https://jitpack.io' }


// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

        //下面這兩句
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

6: 在module 的gradle裡面新增:


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    //implementation 'com.github.kodulf:TryToGetMyGithubRepo:1.0'
    implementation 'com.github.kodulf:Delete:v1.0'
    //implementation 'com.github.kodulf:Try:v1.0.0'
    //implementation 'com.github.kodulf:TryNotLibarary:v2.0.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

}

 

當“git it” 是綠色的時候,說明可以使用了,如果是report 那麼就是不可以使用的,千萬要注意

 

參考:

https://jitpack.io

https://blog.csdn.net/deng0zhaotai/article/details/77935138

https://blog.csdn.net/xuchao_blog/article/details/62893851