build.gradle 1.46 KB
import java.util.regex.Matcher

apply plugin: 'com.android.library'

def versionName() {
    return "0.1.1"
}

def versionNameToCode(String version) {
    String v = version.replaceAll(/\./, '')
    return v.toLong()
}

String version = versionName()
int code = versionNameToCode(version)

android {
    compileSdkVersion 26
    buildToolsVersion '27.0.0'
    defaultConfig {
        //applicationId "com.qiniu.android"
        minSdkVersion 9
        targetSdkVersion 24
        versionCode code
        versionName version
    }

    lintOptions {
        warning 'InvalidPackage'
    }
}

dependencies {
//    compile 'com.android.support:appcompat-v7:21.0.3'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
}

task releaseJar(type: Jar, dependsOn: 'build') {
    //指定生成的jar名
    baseName 'android-netdiag-' + version
    //去掉不需要打包的目录和文件
    exclude('test/', 'BuildConfig.class', 'R.class')
    //去掉R$开头的文件
    exclude { it.name.startsWith('R$'); }
}

android.libraryVariants.all { variant ->
    def name = variant.buildType.name
    def task = project.tasks.create "jar${name.capitalize()}", Jar
    task.dependsOn variant.javaCompile
    task.from variant.javaCompile.destinationDir
    task.exclude '**/R.*', '**/R$*.*', '**/BuildConfig.class'
    artifacts.add('archives', task);
}

//setProperty('VERSION_NAME', version)
//setProperty('VERSION_CODE', code)

//apply from: '../mvn_push.gradle'