Android-->build.gradle-->buildTypes

来源:互联网 发布:绿豆沙护眼软件 编辑:程序博客网 时间:2024/05/20 17:40

我们在用androidStudio开发安卓项目的时候经常要配置build.gradle,那么到底怎么配置呢

android {    compileSdkVersion 25    buildToolsVersion "25.0.3"    defaultConfig {        applicationId "com.pf.listener14"        minSdkVersion 15        targetSdkVersion 25        versionCode 1        versionName "1.0"        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"        externalNativeBuild {            cmake {                cppFlags "-frtti -fexceptions"            }        }    }    signingConfigs {        mySign {            storeFile file('debug.keystore')            storePassword 'android'            keyAlias 'androiddebugkey'            keyPassword 'android'            //支持V1签名            v1SigningEnabled true            //支持V2签名            v2SigningEnabled true        }    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }        debug {            //包名后缀            applicationIdSuffix '.debug'            //支持debug            debuggable true            //ndk支持debug            jniDebuggable true            //优化混淆            minifyEnabled true            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'            //分包            multiDexEnabled true            pseudoLocalesEnabled true            //压缩资源            shrinkResources true            //签名            signingConfig signingConfigs.mySign            //压缩apk            zipAlignEnabled true        }        hello{            initWith debug        }    }    externalNativeBuild {        cmake {            path "CMakeLists.txt"        }    }}

这里写图片描述

debug.keystore是在C:\Users\Administrator.android这个路径下,安卓默认的bebug签名

每次构建时 ProGuard 都会输出下列文件:

这里写图片描述

  • dump.txt–>说明 APK 中所有类文件的内部结构。
  • mapping.txt–>提供原始与混淆过的类、方法和字段名称之间的转换。
  • seeds.txt–>列出未进行混淆的类和成员。
  • usage.txt–>列出从 APK 移除的代码。


每次使用 ProGuard 创建发布构建时都会覆盖 mapping.txt 文件,因此每次发布新版本时都必须小心地保存一个副本。通过为每个发布构建保留一个 mapping.txt 文件副本,就可以在用户提交的已混淆堆叠追踪来自旧版本应用时对问题进行调试。


自定义要保留的代码

    要修正错误并强制 ProGuard 保留特定代码,请在 ProGuard 配置文件中添加一行 -keep 代码。例如:    -keep public class MyClass
原创粉丝点击