Gradle: How to publish a Android library to local repository

后端 未结 5 1736
逝去的感伤
逝去的感伤 2020-12-04 10:47

I have a library and a Android app using Gradle and Android Studio. I can include the library directly in the project as following

compile project(\':library         


        
5条回答
  •  余生分开走
    2020-12-04 11:28

    For an Android Library you should use the Android Gradle-Maven plugin https://github.com/dcendents/android-maven-gradle-plugin:

    buildscript {
        repositories {
            mavenCentral()
        }
    
        dependencies {
            classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
        }
    }
    
    apply plugin: 'com.android.library'
    apply plugin: 'com.github.dcendents.android-maven'
    

    Then to publish to your local repository run:

    ./gradlew install
    

    which will install it in $HOME/.m2/repository. In your app or other project you can then include it by adding mavenLocal() to your repositories.

    Alternatively, if your library is on GitHub then you can simply include it in other projects using JitPack. Then you don't have to run the above command and can just use what's been pushed.

提交回复
热议问题