使用buildFlavors进行Android distZip

时间:2017-06-27 09:32:56

标签: android gradle android-gradle

我最近开始在Android Studio 2.3中使用buildFlavor

今天我想将我们的aar lib压缩分发,但distZip任务根本不会选择aar

我应该如何配置任务?

我想要一个包含以下内容的zip文件:

  • 自述
  • 的JavaDoc
  • AAR

的build.gradle

apply plugin: 'com.android.library'
apply plugin: 'distribution'


...

distributions {
    main {
        baseName = archivesBaseName
        contents {
            from 'README.md'
            from 'build/libs'
            from 'build/docs'
            from 'outputs/aar'
        }
    }
}

android {
    compileSdkVersion 19
    buildToolsVersion '25.0.3'
    publishNonDefault true
    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.test.InstrumentationTestRunner"

     //
    }

    productFlavors {
        dev {
            version version + "-dev"
          //
        }
        prod {}
    }

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

    lintOptions {
        checkReleaseBuilds false
        abortOnError false
        ignore 'AllowBackup'
    }

    packagingOptions {
        exclude "/META-INF/LICENCE"
        exclude "/META-INF/LICENSE"
        exclude "/META-INF/LICENCE.txt"
        exclude "/META-INF/LICENSE.txt"
        exclude "/META-INF/NOTICE"
        exclude "/META-INF/NOTICE.txt"
        exclude "/LICENCE"
        exclude "/LICENCE.txt"
        exclude "/NOTICE"
        exclude "NOTICE.txt"
    }
}

dependencies {
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.6.7'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.6.7'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.6.7'

    androidTestCompile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.6.7'
    androidTestCompile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.6.7'
    androidTestCompile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.6.7'

    androidTestCompile 'com.jayway.awaitility:awaitility:1.6.0'
    androidTestCompile 'com.jayway.jsonpath:json-path-assert:0.9.1'
    androidTestCompile 'com.squareup.okhttp:mockwebserver:1.5.4'
}

distZip.dependsOn {
    tasks.findByName('generateProdReleaseJavadoc')
}

// create javadoc
android.libraryVariants.all { variant ->
    task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
        description "Generates Javadoc for $variant.name."
        source = variant.javaCompile.source
        classpath += project.files(variant.javaCompile.classpath.files)
        classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    }

}

1 个答案:

答案 0 :(得分:1)

您可以像这样配置发行版吗? 这样,您可以扩展分发并根据需要进行配置。 然后应用程序插件中包含的distZip会将其拾取。

创建任务以执行您需要的任务

program.fs

扩展您的发行版:

task createDocs {
    def docs = file("$buildDir/docs")
    outputs.dir docs
    doLast {
        docs.mkdirs()
        new File(docs, "readme.txt").write("Read me!")
    }
}

同样检查distZip任务的依赖关系。 如果它取决于构建工件的任务。

来源:https://docs.gradle.org/3.3/userguide/application_plugin.html

相关问题