调试时若想直接用正式的签名包可以在buildType里配置。
buildTypes { debug { signingConfig signingConfigs.release } release { minifyEnabled false proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘ } }
${Value} 是动态配置的。
<application android:name=".MyApplication"> <meta-data android:name="channelValue" android:value="${Value}"></meta-data>
build.gradle配置如下
productFlavors { huawei { minSdkVersion 14 targetSdkVersion 21 manifestPlaceholders =[Value: "huawei"] } xiaomi { minSdkVersion 14 targetSdkVersion 21 manifestPlaceholders =[Value: "xiaomi"] } }
代码中获取AndroidMainnifest Value的值
//获取meta字段 public static String getMetaString(Context con,String name){ ApplicationInfo ai = null; try { ai = con.getPackageManager().getApplicationInfo(con.getPackageName(), PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } Bundle bundle = ai.metaData; return bundle.getString(name); }
打包时直接使用
最后贴上build.gradle文件。
apply plugin: ‘com.android.application‘ android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "caisheng.com.search" minSdkVersion 16 targetSdkVersion 21 versionCode 1 versionName "1.0" } signingConfigs { //你自己的keystore信息 release { keyAlias ‘aolaigo‘ keyPassword ‘123456‘ storeFile file(‘E:/test.jks‘) storePassword ‘123456‘ } } lintOptions { checkReleaseBuilds false // Or, if you prefer, you can continue to check for errors in release builds, // but continue the build even when errors are found: abortOnError false } buildTypes { debug { signingConfig signingConfigs.release } release { minifyEnabled false proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘ } } productFlavors { huawei { minSdkVersion 14 targetSdkVersion 21 manifestPlaceholders =[Value: "huawei"] } xiaomi { minSdkVersion 14 targetSdkVersion 21 manifestPlaceholders =[Value: "xiaomi"] } } } dependencies { compile fileTree(dir: ‘libs‘, include: [‘*.jar‘]) // compile (name:‘cai‘,ext:‘aar‘) // compile project(‘:cai‘) /* compile ‘com.facebook.fresco:fresco:0.6.0‘ compile ‘com.android.support:appcompat-v7:22.2.0‘ compile ‘com.github.liuguangqiang.swipeback:library:1.0.2@aar‘ compile ‘com.sothree.slidinguppanel:library:3.1.1‘ compile ‘me.dm7.barcodescanner:zbar:1.5‘*/ }
版权声明:本文为博主原创文章,未经博主允许不得转载。
android studio 多渠道打包,调试正式包,build.gradle解析
原文地址:http://blog.csdn.net/chencaishengsic/article/details/48027339