1. 程式人生 > >Android studio build.gradle配置,debug下使用正式簽名,重新命名apk

Android studio build.gradle配置,debug下使用正式簽名,重新命名apk

在build.gradle檔案中,android節點下進行配置。

android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'

    signingConfigs {
        release {
            keyAlias 'xxx'
            keyPassword 'xxxxxxxxxxxx'
            storeFile file('./xxx.keystore')
            storePassword 'xxxxxxxxxxxxxxxx'
        }
        config {
            keyAlias 'xxxx'
            keyPassword 'xxxxxxx'
            storeFile file('./xxx.keystore')
            storePassword 'xxxxxxxx'
        }
    }

    defaultConfig {
        applicationId "com.xxx.xxxxx"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 7
        versionName "2.2.1"
        signingConfig signingConfigs.release
    }
    //配置debug模式下,使用正式版簽名,此操作主要為了方便除錯微信,新浪等第三方登入授權
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            debuggable true
            signingConfig signingConfigs.release
        }
        debug {
            signingConfig signingConfigs.release
        }
    }

    //渠道
    productFlavors {
        baidu {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "baidu"]
        }

        qihu360 {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "qihu360"]
        }

        tencent {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "tencent"]
        }

    }
    sourceSets {
        main { java.srcDirs = ['src/main/java', 'src/main/java/jniLibs', 'src/main/jniLibs'] }
    }

    //修改生成的apk名字
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def oldFile = output.outputFile
            if (variant.buildType.name.equals('release')) {
                def releaseApkName = 'pintuan_' + variant.productFlavors[0].name + '_release_' + defaultConfig.versionName + '.apk'
                output.outputFile = new File(oldFile.parent, releaseApkName)
            }
        }
    }

}