目前分類:Gradle (4)

瀏覽方式: 標題列表 簡短摘要


gradle新增

JBLin 發表在 痞客邦 留言(0) 人氣()

android {
    defaultConfig {
        versionCode gitVersionCode()
        versionName gitVersionTag()
    }
}
def gitVersionTag() {
  //依照tag名稱排序 列出s.開頭的TAG "git tag --sort=v:refname s.* -l"
  //依照commit時間排序 列出s.開頭的TAG "git tag --sort=committerdate s.* -l"
  //依照tag時間排序 列出s.開頭的TAG "git tag --sort=taggerdate s.* -l"
  // 同條支線最新的 tag => git describe --match \"s.*\" --tags --abbrev=0
    def tag = "git tag".execute().text.trim().split("\n").grep(~/^s.*/).last()
    return tag
}
def gitVersionCode() {
    def code = 'git rev-list HEAD --first-parent --count'
    return code.execute().text.trim().toInteger()
}
task printVersion {
    doLast { // add a task action
        println generateDebugBuildConfig.versionName
    }
}

 


JBLin 發表在 痞客邦 留言(0) 人氣()

gradle 加入 

android {

        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
}

gradle(project)

JBLin 發表在 痞客邦 留言(0) 人氣()

gradle裡面新增
 buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationVariants.all { variant ->
            (libraryVariants.all { variant ->)//aar
                variant.outputs.each{ output ->
          if(variant.productFlavors[0].name.equals(productFlavors name(flavor))) {//針對要某些類型apk做改名
                      def date = new Date();
                      def formattedDate = date.format('yyyy.MM.dd')//取得當前日期
                      //(要放的資料夾,檔名->加入版本及日期) 
                      output.outputFile = new File("C:/Users/acer/Desktop","apkname"+defaultConfig.versionName +"-"+formattedDate+".apk")
                    }
                }
            }
        }
    }

productFlavors {
    flavor {//第一個apk
        minSdkVersion 19
        applicationId 'frontier.kiwi.recognition'
        targetSdkVersion 23
        versionCode 2
        versionName '2'
        signingConfig signingConfigs.test1 //keystore
    }
    flavor1 {//第二個apk
        minSdkVersion 19
        applicationId 'frontier.kiwi.recognition'
        targetSdkVersion 23
        versionCode 2
        versionName '2'
        signingConfig signingConfigs.test2 //keystore
    }
signingConfigs {
test1 {
    storeFile file("D:/X2.jks")//file path
    storePassword 'x2keyx2' 
    keyAlias 'x2'
    keyPassword 'x2keyx2'
}
test2 {
    storeFile file("D:/X5.jks")//file path
    storePassword 'x5keyx5'
    keyAlias 'x5'
    keyPassword 'x5keyx5'
}
}
cmd : 
 gradlew assemble   //解出所有apk
 gradlew assembleDebug //解出單一Debug所有apk
 gradlew assembleFlavor //解出單一flavor所有apk
 gradlew assembleFlavorDebug //解出flavor下的Debug apk

文章標籤

JBLin 發表在 痞客邦 留言(0) 人氣()