Gradle Maven plugin “install” task does not work with Android library project

后端 未结 5 1542
[愿得一人]
[愿得一人] 2020-12-07 17:54

I want to install android library project to local maven repository. Here is build.gradle:

buildscript {
    repositories {
        mavenCentral()
          


        
5条回答
  •  遥遥无期
    2020-12-07 18:31

    UPDATE 2014-11-26

    The answer below made sense at the time of writing, when Android Build Tools were at version 0.5.5. It is most likely outdated now and probably does not work anymore.

    I have personally switched my projects to use android-maven-plugin as described in the answer above, the plugin works fine with the recent versions of Android Build Tools too.

    THE ORIGINAL ANSWER FROM FEBRUARY 2014

    Publishing as AAR

    If you don't mind using an older version of com.android.tools.build:gradle (i.e. 0.5.4), you can use the approach described in this blogpost. Not that according to the discussion in adt-dev mailing-list, this does not work in 0.5.5.

    Add the following lines to your build.gradle:

    apply plugin: 'maven-publish'
    
    // load bundleRelease task
    // this will not load the task in 0.5.5
    android.libraryVariants
    
    publishing {
        publications {
            maven(MavenPublication) {
                artifact bundleRelease
            }
        }
    }
    

    To publish to your local maven repo, call this command:

    gradle publishToMavenLocal
    

    Publishing as JAR

    If your Android Library does not have custom resources and can be published as JAR, then you can use the following build.gradle that works even with 0.5.5.

    // build JAR file
    task androidReleaseJar(type: Jar, dependsOn: assembleRelease) {
        from "$buildDir/classes/release/"
    }
    
    apply plugin: 'maven-publish'
    
    publishing {
        publications {
            maven(MavenPublication) {
                artifact androidReleaseJar
            }
        }
    }
    

    To publish to your local maven repo, call this command:

    gradle publishToMavenLocal
    

提交回复
热议问题