Android studio 多渠道打签名包的配置

Android studio打包方式:
1.手动打包:通过Build-->Generate Signed APK方式,这种方式打包,需要手动添写签名文件信息
2.通过命令:gradlew assembleRelease,这种方式打包,直接读取build.grade配置进行打包,可同时打包不同名称的apk;
  例如:下面的Bate版本和Releases,这两种都是release版本的包

build.grade文件配置如下:
apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    useLibrary 'org.apache.http.legacy'
    dexOptions {
        javaMaxHeapSize "6g" //java虚拟机的堆内存大小。
    }

    //在编译apk的时默认配置
    defaultConfig {
        applicationId "com.demo" //应用包名
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1

        versionName "1.0.0"

        //dex突破65535的限制

        multiDexEnabled true
        manifestPlaceholders = [JPUSH_APP_KEY: TEST_JPUSH_APP_KEY, //打包时替换Androidmenifest.xml中的值
                                app_name     : "@string/app_name",
        ]
    //<meta-data
            android:name="JPUSH_APPKEY"
            android:value="${JPUSH_APP_KEY}"
    }
    signingConfigs {
        //debug版本的包
        debug {
            // No debug config
        }

    //打签名包时的配置,release版本的包
        release {
            storeFile file("C:\\Android\\workspace\\demo\\my.keystore")
            storePassword "123456"
            keyAlias "name"
            keyPassword "123456"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            pseudoLocalesEnabled false
            multiDexEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            debuggable false
        //打签名包时,需要添加此设置
            signingConfig signingConfigs.release
        }
    }

    //apk多渠道打包
    productFlavors {
        Bate{
            applicationId "com.demo.beta"
            manifestPlaceholders = [app_name: "测试Beta版"]
            //在java代码中具体的使用方式为:context.getResources().getString(R.string.strKey);
            resValue("string", "strKey", "beta版本")//打包后apk的安装名称
        }

        Releases {
            manifestPlaceholders = [JPUSH_APP_KEY: JPUSH_APP_KEY]
            resValue("string", "strKey", "release版本")//打包后apk的安装名称
        }

    }

    lintOptions {
        disable 'ResourceType'
        abortOnError false
        checkReleaseBuilds false
        // 防止在发布的时候出现因MissingTranslation导致Build Failed!
        disable 'MissingTranslation'
    }
}
repositories {
    // ...
    maven { url "https://jitpack.io" }
}

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值