前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【Android Gradle 插件】BuildType 编译类型配置 ② ( consumerProguardFiles 配置 | debuggable 配置 | embedMicroApp配置 )

【Android Gradle 插件】BuildType 编译类型配置 ② ( consumerProguardFiles 配置 | debuggable 配置 | embedMicroApp配置 )

作者头像
韩曙亮
发布2023-03-30 15:10:40
1.5K0
发布2023-03-30 15:10:40
举报
文章被收录于专栏:韩曙亮的移动开发专栏

文章目录

Android Plugin DSL Reference 参考文档 :

一、BuildType#consumerProguardFiles 配置


BuildType ( build.gradle#android#buildTypes 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.BuildType.html

BuildType#consumerProguardFiles 配置是 Library 中的混淆文件配置 ;

代码语言:javascript
复制
发布的AAR中包含的ProGuard规则文件。
然后,使用AAR的任何应用程序项目都将使用这些proguard规则文件(如果启用了proguard)。
这允许AAR指定收缩或模糊排除规则。
这仅对库项目有效。这在应用程序项目中被忽略。

BuildType#consumerProguardFiles 配置原型 :

代码语言:javascript
复制
List<File> consumerProguardFiles

ProGuard rule files to be included in the published AAR.
These proguard rule files will then be used by any application project that consumes the AAR (if ProGuard is enabled).
This allows AAR to specify shrinking or obfuscation exclude rules.
This is only valid for Library project. This is ignored in Application project.

参考文档 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.BuildType.html#com.android.build.gradle.internal.dsl.BuildType:consumerProguardFiles

二、BuildType#debuggable 配置


BuildType ( build.gradle#android#buildTypes 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.BuildType.html

BuildType#debuggable 配置 是 BuildType 中特有的配置 , 该值默认为 true ;

BuildType#debuggable 配置设置为 true , 则默认生成的是可调式的 apk 安装文件 ;

BuildType#debuggable 配置设置为 false, 则生成的 apk 文件安装运行后 , 无法对 debug 版本的代码进行调试 ;

代码语言:javascript
复制
boolean debuggable
Whether this build type should generate a debuggable apk.

使用示例 :

代码语言:javascript
复制
android {

    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "kim.hsl.svg"
        minSdkVersion 18
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        
        applicationIdSuffix ".tom"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            applicationIdSuffix ".jerry"
            // 默认为 true , 生成的 debug apk 可调试 
            // 设置为 false , 生成的 debug apk 不可调试 
            debuggable false
        }
    }
}

三、BuildType#embedMicroApp 配置


BuildType ( build.gradle#android#buildTypes 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.BuildType.html

BuildType#embedMicroApp 配置是 可穿戴设备应用使用的配置 , 普通的手机应用不用处理该配置 ;

代码语言:javascript
复制
是否应使用此构建类型将链接的Android Wear应用嵌入变体中。
Wear应用程序可以与以下代码链接:

dependencies {
  freeWearApp project(:wear:free') // applies to variant using the free flavor
  wearApp project(':wear:base') // applies to all other variants
}

BuildType#embedMicroApp 配置原型 :

代码语言:javascript
复制
boolean embedMicroApp

Whether a linked Android Wear app should be embedded in variant using this build type.

Wear apps can be linked with the following code:

dependencies {
  freeWearApp project(:wear:free') // applies to variant using the free flavor
  wearApp project(':wear:base') // applies to all other variants
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-05-02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文章目录
  • 一、BuildType#consumerProguardFiles 配置
  • 二、BuildType#debuggable 配置
  • 三、BuildType#embedMicroApp 配置
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档