Use of Gradle multi-channel packaging and error analysis, gradle packaging Error
I just got started with android development, and I am familiar with everything. This article is a summary of the technical points I used in my project. When I met a big hacker, I could just jump over .....
1. Package Gradle (directly run the script without nonsense) and put the following script into the build. gradle file android;
1 defaultConfig {2 // applicationId "" // application package name 3 minSdkVersion 9 // sdk minimum supported version 4 targetSdkVersion 17 // sdk target version 5 versionCode 1 6 versionName "1.0" 7 8 // dex exceeded 65535 limit 9 multiDexEnabled true10 11 // AndroidManifest. the UMENG_CHANNEL value in xml is $ {UMENG_CHANNEL_VALUE} 12 // manifestPlaceholders = [UMENG_CHANNEL_VALUE: ""] 13} 14 15 // executes the lint check. any error or warning message is displayed, will terminate the build, we can turn it off. 16 lintOptions {17 abortOnError false18} 19 20 // signature 21 signingConfigs {22 myConfig {23 storeFile file ("123456 ") // signature file path 24 storePassword "123456" 25 keyAlias "123456" 26 keyPassword "123456" 27} 28} 29 30 31 buildTypes {32 release {33 // Log34 buildConfigField is not displayed" boolean ", "LOG_DEBUG", "false" 35 // obfuscation 36 minifyEnabled true37 // Zipalign optimized 38 zipAlignEnabled true39 // Remove useless resource file 40 shrinkResources true41 // Load the default obfuscation profile progudard-android.txt In the sdk directory, don't worry, proguard. cfg is the obfuscation file 42 proguardFiles getDefaultProguardFile('proguard-android.txt ') 43 proguardFile 'proguard. cfg '44 // signature 45 signingConfig signingConfigs. myConfig46} 47} 48 49 // flavorDimensions "abi" 50 51 // channel Flavors, I have written some commonly used 52 productFlavors {53 _ 360 {54} 55 xiaomi {56} 57} 58 59 60 productFlavors. all {flavor-> 61 flavor. manifestPla Ceholders = [UMENG_CHANNEL_VALUE: name] 62} 63 64 65 applicationVariants. all {variant-> 66 variant. outputs. each {output-> 67 def outputFile = output. outputFile68 if (outputFile! = Null & outputFile.name.endsWith('.apk ') {69 70 // The output apkname is appname_v1.0.apk 71 def fileName = "folder" 72 output. outputFile = new File (outputFile. parent, fileName) 73} 74} 75}
Then, when gradle clean assumerelease-d (output debug information) is used, the channel packages of 360 and Xiaomi will be successfully output.
Notes:
1. File Obfuscation
Proguard. ParseException: Unknown option 'Role? --Dump.txt
First, check the encoding of the obfuscation configuration file and then change the file to proguard. cfg. Then, open the command line in the file to be identified;
2. Third-Party jar references
Execution failed for task java. io. IOException: Can't write ''can't read
Check whether the third-party jar package has been referenced multiple times (delete the jar package that has been referenced multiple times) and reference the maven-dependent method.
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
And the jar followed by Can't read is deleted in libs.
(Use Gradle2.2.1 eclipse to switch to android studio)