Sharing an Android library between multiple Android apps using Gradle

橙三吉。 提交于 2019-12-05 01:47:18

Your best bet is to go the aar route and publish it to maven http://www.vandalsoftware.com/post/52468430435/publishing-an-android-library-aar-to-a-maven

According to official document of Android(https://developer.android.com/studio/projects/android-library.html): By importing module, the library module is copied to your project, so you can actually edit the library code. If you want to maintain a single version of the library code, then this is probably not what you want and you should instead import the compiled AAR file as described above.

There is another option, git submodule. You can make your app refer to a SHA of your library. So there is only one copy for the library. Each app is using only a SHA. You should pay little bit more attention for branch management of the library. Check this for detail: https://github.com/blog/2104-working-with-submodules

I was able to remove a lot of the SonaType auth stuff, since we have our own Nexus repo that doesn't use it. My gradle.build file (the module file, not the root) ended up looking like this:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.1'
    }
}
apply plugin: 'android-library'
apply plugin: 'maven'

version = 0.3
group = "com.whatevs.android.commons"

uploadArchives {
    repositories.mavenDeployer {

        repository(url: 'http://nexus.whatevs.net:8081/nexus/content/repositories/internal-release') {
        }

        pom.project {
            packaging 'aar'

            scm {
                url 'scm:git:ssh://git@whatevs.net:7999/Mobile/android-commons.git'
                connection 'scm:git:ssh://git@whatevs.net:7999/Mobile/android-commons.git'
                developerConnection 'scm:git:ssh://git@whatevs.net:7999/Mobile/android-commons.git'
            }
        }
    }
}

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
    }
    release {
        runProguard false
        proguardFile 'proguard-rules.txt'
        proguardFile getDefaultProguardFile('proguard-android.txt')
    }
}

dependencies {
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!