Android studio multi-channel packaging, formal debugging package, build. gradle Parsing
1. describes the build. gradle file. 1.1 root directory Android
1.1.1
DefaultConfig is the root directory of Android. You can configure the package name and other information. If AndroidMainfest. xml is also configured, use defaconfig config as the standard.
1.1.2
SigningConfigs is the root directory of Android. You can configure the signature, for example:
If you want to useFormal signature packageIt can be configured in buildType.
buildTypes { debug { signingConfig signingConfigs.release } release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' }}
1.1.3
Package Multiple channels to modify the meta-data value of AndroidMainFest.
Configure AndroidMainFest as follows:
$ {Value} is dynamically configured.
The configuration of build. gradle is as follows:
productFlavors { huawei { minSdkVersion 14 targetSdkVersion 21 manifestPlaceholders =[Value: huawei] } xiaomi { minSdkVersion 14 targetSdkVersion 21 manifestPlaceholders =[Value: xiaomi] }}
Get AndroidMainnifest Value in the code
// Obtain the meta field 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 );}
Use directly during packaging
Finally, paste the build. gradle file.
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 {// your own keystore Information release {keyAlias 'aolaigo 'keypassword' 123456 'storefile file ('e:/test. jks ') storePassword '000000'} 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 getdefadefaproguardfile('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: 0.6.0 'compile 'com. android. support: appcompat-v7: 22.2.0 'compile 'com. github. liuguangqiang. swipeback: library: 1.0.2 @ aar 'compute' com. sothree. slidinguppanel: library: 3.1.1 'compile 'me. dm7.barcode=: zbar: 1.5 '*/}