LoginSignup
0
1

More than 3 years have passed since last update.

GitリポジトリのライブラリをAndroidアプリから参照する

Last updated at Posted at 2019-12-03

Gitのリポジトリのライブラリを参照する方法

色々調べてトライしたけれど、ブランチ指定した場合にうまく動作するのがこの方法だったのでメモ
他の方法はmaster指定しかうまく動かなかった・・・

詳細は以下のソースコードをみてください。

[ライブラリのリポジトリ]
https://github.com/tokuyama-san/MyLibrary

build.gradle(Module)
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply from: 'maven.gradle'  ←ここを追加

android {
    compileSdkVersion 29


    defaultConfig {
        minSdkVersion 28
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles 'consumer-rules.pro'
    }

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

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

maven.gradle
def versionName = "0.9.1beta"
def repo = new File(rootDir, "repository")

apply plugin: 'maven'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

uploadArchives {
    repositories {
        mavenDeployer {
            repository url: "file://${repo.absolutePath}"
            pom.version = "${versionName}"      // version
            pom.groupId = 'toku.san.mylibrary'      // グループ名
            pom.artifactId = 'MyLibrarySDK' // ライブラリ名
        }
    }
}

[アプリのリポジトリ]
https://github.com/tokuyama-san/MyApplication

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

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
        maven { url "https://github.com/layerhq/releases-gradle/raw/master/releases" } ←これを追加
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath group: 'com.layer', name: 'git-repo-plugin', version: '1.0.0' ←これを追加
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
build.gradle(app)
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "toku.san.myapplication"
        minSdkVersion 28
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

apply plugin: 'git-repo' ←これを追加

repositories {
    git("git@github.com:tokuyama-san/MyLibrary.git", "toku.san.mylibrary:MyLibrarySDK", "master", "repository") ←これを追加
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'toku.san.mylibrary:MyLibrarySDK:0.9.0' ←これを追加
}

ライブラリの更新方法

ライブラリのリポジトリですること

1.maven.gradleに記載しているバージョン(VersionName)を変更する(例. "0.9.1beta")

2.ライブラリのルートディレクトリで以下のコマンド

./gradlew uploadArchives

3.repository配下に指定したバージョンのファイルがいくつか出来上がるのでGitにコミット&プッシュする

アプリのリポジトリですること

アプリのbuild.gradleに記載されているdependenciesスコープ内の
ライブラリのバージョン部分を変更する。

implementation 'toku.san.mylibrary:MyLibrarySDK:0.9.0'

implementation 'toku.san.mylibrary:MyLibrarySDK:0.9.1beta'

あとはビルドすればOK

0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1