您的位置:首页 > 产品设计 > UI/UE

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

2015-07-30 19:08 731 查看
在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)
            }
        }
    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: