| 1 2 3 4 5 | android{ defaultConfig{ manifestPlaceholders = [app_label:"@string/app_name"] } } |
| 1 2 3 4 5 6 7 8 9 | android{ buildTypes { debug { manifestPlaceholders = [app_label:"@string/app_name_debug"] } release { } } } |
| 1 2 3 4 5 6 7 8 | android{ productFlavors { // 把dev产品型号的apk的AndroidManifest中的channel替换dev "dev"{ manifestPlaceholders = [channel:"dev"] } } } |
| 1 2 3 4 | RELEASE_KEY_PASSWORD=xxxx RELEASE_KEY_ALIAS=xxx RELEASE_STORE_PASSWORD=xxx RELEASE_STORE_FILE=../.keystore/xxx.jks |
| 1 2 3 4 5 6 7 8 9 10 | android { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } } |
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | android { productFlavors { dev{ manifestPlaceholders = [channel:"dev"] } official{ manifestPlaceholders = [channel:"official"] } // ... ... wandoujia{ manifestPlaceholders = [channel:"wandoujia"] } xiaomi{ manifestPlaceholders = [channel:"xiaomi"] } "360"{ manifestPlaceholders = [channel:"360"] } } |
| 1 2 3 4 5 6 7 8 9 10 | devDebug devRelease officialDebug officialRelease wandoujiaDebug wandoujiaRelease xiaomiDebug xiaomiRelease 360Debug 360Release |
| 1 2 3 4 5 6 7 8 9 10 | // release版本生成的BuildConfig特性信息 public final class BuildConfig { public static final boolean DEBUG = false; public static final String BUILD_TYPE = "release"; } // debug版本生成的BuildConfig特性信息 public final class BuildConfig { public static final boolean DEBUG = true; public static final String BUILD_TYPE = "debug"; } |
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | android { signingConfigs { debug { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } preview { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASSWORD keyAlias RELEASE_KEY_ALIAS keyPassword RELEASE_KEY_PASSWORD } } buildTypes { debug { manifestPlaceholders = [app_label:"@string/app_name_debug"] } release { manifestPlaceholders = [app_label:"@string/app_name"] } preview{ manifestPlaceholders = [app_label:"@string/app_name_preview"] } } } |
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | android { debug { manifestPlaceholders = [app_label:"@string/app_name_debug"] applicationIdSuffix ".debug" minifyEnabled false signingConfig signingConfigs.debug proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } release { manifestPlaceholders = [app_label:"@string/app_name"] minifyEnabled true shrinkResources true signingConfig signingConfigs.release proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } preview{ manifestPlaceholders = [app_label:"@string/app_name_preview"] applicationIdSuffix ".preview" debuggable true // 保留debug信息 minifyEnabled true shrinkResources true signingConfig signingConfigs.preview proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } } } |
| 1 2 3 4 5 6 7 | // minifyEnabled 混淆处理 // shrinkResources 去除无用资源 // signingConfig 签名 // proguardFiles 混淆配置 // applicationIdSuffix 增加APP ID的后缀 // debuggable 是否保留调试信息 // ... ... |
| 1 2 3 4 5 6 7 8 9 10 11 | android { compileSdkVersion 22 buildToolsVersion "23.0.1" defaultConfig { minSdkVersion 10 targetSdkVersion 22 versionCode 34 versionName "v2.6.1" } } |
| 1 2 3 4 5 6 7 8 | ext { compileSdkVersion = 22 buildToolsVersion = "23.0.1" minSdkVersion = 10 targetSdkVersion = 22 versionCode = 34 versionName = "v2.6.1" } |
| 1 2 3 4 5 6 7 8 9 10 11 12 | android { compileSdkVersion rootProject.ext.compileSdkVersion buildToolsVersion rootProject.ext.buildToolsVersion defaultConfig { applicationId "com.xxx.xxx" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode rootProject.ext.versionCode versionName rootProject.ext.versionName } } |
| 1 2 3 4 5 6 7 8 9 10 | android { // rename the apk with the version name applicationVariants.all { variant -> variant.outputs.each { output -> output.outputFile = new File( output.outputFile.parent, "ganchai-${variant.buildType.name}-${variant.versionName}-${variant.productFlavors[0].name}.apk".toLowerCase()) } } } |
| 1 2 3 4 5 6 7 8 9 10 11 | android { // rename the apk with the version name // add output file sub folder by build type applicationVariants.all { variant -> variant.outputs.each { output -> output.outputFile = new File( output.outputFile.parent + "/${variant.buildType.name}", "ganchai-${variant.buildType.name}-${variant.versionName}-${variant.productFlavors[0].name}.apk".toLowerCase()) } } } |
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ## 位于module下的proguard-rules.pro ##################################### ######### 主程序不能混淆的代码 ######### ##################################### -dontwarn xxx.model.** -keep class xxx.model.** { *; } ## 等等,自己的代码自己清楚 ##################################### ########### 不优化泛型和反射 ########## ##################################### -keepattributes Signature |
| 1 2 | -dontwarn cn.jpush.** -keep class cn.jpush.** { *; } |
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | ##################################### ######### 第三方库或者jar包 ########### ##################################### -dontwarn cn.jpush.** -keep class cn.jpush.** { *; } -dontwarn com.squareup.** -keep class com.squareup.** { *; } -dontwarn com.octo.** -keep class com.octo.** { *; } -dontwarn de.** -keep class de.** { *; } -dontwarn javax.** -keep class javax.** { *; } -dontwarn org.** -keep class org.** { *; } -dontwarn u.aly.** -keep class u.aly.** { *; } -dontwarn uk.** -keep class uk.** { *; } -dontwarn com.baidu.** -keep class com.baidu.** { *; } -dontwarn com.facebook.** -keep class com.facebook.** { *; } -dontwarn com.google.** -keep class com.google.** { *; } ## ... ... |
| 1 2 | java.lang.NullPointerException: java.lang.NullPointerException at com.xxx.TabMessageFragment$7.run(Unknown Source) |
| 1 2 | project > module > build > outputs > {flavor name} > {build type} > mapping.txt |
| 1 | -keepattributes SourceFile,LineNumberTable |
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | android { defaultConfig { resValue "string", "build_time", buildTime() resValue "string", "build_host", hostName() resValue "string", "build_revision", revision() } } def buildTime() { return new Date().format("yyyy-MM-dd HH:mm:ss") } def hostName() { return System.getProperty("user.name") + "@" + InetAddress.localHost.hostName } def revision() { def code = new ByteArrayOutputStream() exec { commandLine "git", "rev-parse", "--short", "HEAD" standardOutput = code } return code.toString() } |
| 1 2 3 4 | // 在Activity里调用 getString(R.string.build_time)// 输出2015-11-07 17:01 getString(R.string.build_host)// 输出jay@deepin,这是我的电脑的用户名和PC名 getString(R.string.build_revision) // 输出3dd5823, 这是最后一次commit的sha值 |
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | private int clickCount = 0; private long clickTime = 0; sevenClickView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (clickTime == 0) { clickTime = System.currentTimeMillis(); } if (System.currentTimeMillis() - clickTime > 500) { clickCount = 0; } else { clickCount++; } clickTime = System.currentTimeMillis(); if (clickCount > 6) { // 点七下条件达到,跳到debug界面 } } }); |