《Gradle权威指南》--Android Gradle多渠道构建
No1:
Build Variant = Build Type + Product Flavor
Build Variant:构建的产物
Build Type:构建的类型
Product Flavor:构建的渠道
android{ compileSdkVersion 23 buildToolsVersion "23.0.1" productFlavors{ google{} baidu{} } }
No2:
Flurry多渠道和友盟多渠道构建
Flurry本身没有渠道的概念,它有Application,所以可以把一个Application当成一个渠道,每个Application都有一个Key,称为Flurry Key;友盟本身有渠道的概念,只要我们在AndroidManifest.xml配置标注即可。
android{ compileSdkVersion 23 buildToolsVersion "23.0.1" defaultConfig{ applicationId "org.flysnow.app.example112" minSdkVersion 14 targetSdkVersion 23 versionCode 1 versionName '1.0.0' resConfig 'zh' } buildTypes{ release{ minifyEnabled true projuardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro' zipAlignEnabled true } } productFlavors{ google{ buildConfigField 'String','FLURRY_KEY','"BHJKOUASDASFKLZL"' } baidu{ buildConfigField 'String','FLURRY_KEY','"HJSDKHFJDSF23478"' } } }
这样每个渠道的BuildConfig类中都会有名字为FLURRY_KEY常量定义
友盟渠道是在AndroidManifest.xml中配置的
<meta-data android :value="Channel ID" android:name="UMENG_CHANNEL"/>
其中Channel ID就是渠道值
No3:
多渠道构建定制--其实就是对Android Gradle插件的ProductFlavor的配置,通过配置ProductFlavor达到灵活地控制每个渠道的目的
applicationId就是该渠道的包名
android{ ... productFlavors{ google{ applicationId "org.flysnow.app.example112.google" } } }
consumerProguardFiles--只对Android库项目有用
android{ productFlavors{ google{ consumerProguardFiles 'proguard-rules.pro','proguard-android.txt' } } }
testApplicationId--测试包名
android{ ... productFlavors{ google{ testApplicationId "org.flysnow.app.example112.test" } } }
testFunctionalTest--是否为功能测试,testHandleProfiling--是否启用分析功能
android{ productFlavors{ google{ testFunctionalTest true testHandleProfiling true } } }
testInstrumentationRunner--用来配置运行测试使用的Instrumentation Runner的类名
android{ productFlavors{ google{ testInstrumentationRunner 'android.test.InstrumentationTestRunner' } } }
testInstrumentationRunnerArguments--用来配置Instrumentation Runner使用的参数
android{ productFlavors{ google{ testInstrumentationRunnerArguments.put("coverage",'true') } } }
useJack--用于标记是否启用Jack和Jill这个全新的、高性能的编译器
android{ productFlavors{ google{ useJact true } } }
dimension --多维度,理解为对ProdcutFlavor进行分组。用flavorDimensions声明维度,才能在ProductFlavor中使用
android{ flavorDimensions "abi","version"//优先级:abi>version>defaultConfig productFlavors{ free{ dimension 'version' } paid{ dimension 'version' } x86{ dimension 'abi' } arm{ dimension 'abi' } } }
会生成
ArmFreeDebug
ArmFreeRelease
ArmPaidDebug
ArmPaidRelease
x86FreeDebug
x86FreeRelease
x86PaidDebug
x86PaidRelease
No4:
提高多渠道构建的效率-美团方案
1)利用Android Gradle打一个基本包
2)基于该包复制一个,文件名要能区分出产品、打包时间、版本、渠道等
3)对复制出来的apk文件进行修改,在其META-INF目录下新增空文件,但是空文件的文件名要有意义,必须包含能区分渠道的名字,如:mtchannel_google
4)重复步骤2)步骤3生成我们所需的所有渠道包apk,这个可以使用Python这类脚本来做
5)生成了我们所有发布渠道的apk包
使用:
在apk启动(Application onCreate)时候,读取我们写apk中META-INF目录下的前缀mtchannel_文件,如果找到的话,把文件名取出来,然后就可以得到渠道标识(Google)了
相关文章
- android 常用加密,分享一下Android各种类型的加密
- strictmode android,Android 应用性能优化-StrictMode(严格模式)
- Android—Gradle教程(一)「建议收藏」
- android toast 自定义时间,Android 自定义 Toast 显示时间「建议收藏」
- android activitymanager 系统api_Android view
- Android SDK Tools_android.intent.category.DEFAULT
- 【Android Gradle 插件】Android Studio 工程 Gradle 构建流程 ② ( settings.gradle 构建脚本分析 | 根目录下 build.gradle 分析 )
- 【错误记录】Android Studio 编译报错 ( Could not find com.android.tools.build:gradle:4.2.1. )
- 【Android 逆向】Android 权限 ( Android 逆向中使用的 android.permission 权限 | Android 系统中的 Linux 用户权限 )
- 【Android 逆向】ART 脱壳 ( InMemoryDexClassLoader 脱壳 | DexFile 构造函数及相关调用函数 | Android 源码中查找 native 函数 )
- 【Android 逆向】ART 脱壳 ( InMemoryDexClassLoader 脱壳 | dex_file.cc 中创建 DexFile 实例对象的相关函数分析 )
- 【错误记录】Android Studio 编译报错 ( Could not install Gradle distribution from ‘https://services.gradle.or )
- 【Android Gradle 插件】工程根目录下 build.gradle 配置文件 ( 远程仓库配置 | 依赖配置 | 所有子模块配置 | task clean 任务 )
- 【错误记录】Android Studio 中查看 Gradle 配置的方法源码 ( 配置 gradle-wrapper.properties 中版本为 gradle-x.x.x-all.zip )
- 【Android Gradle 插件】Gradle 映射文件 ( settings.gradle 映射为 Settings 类 | build.gradle 映射为 Project 类 )
- 【错误记录】Android Gradle 配置报错 ( gradle.properties 配置到 BuildConfig 中需要注意类型转换 | 位置: 类 BuildConfig )
- 【Android Gradle 插件】ProductFlavor 配置 ( AppExtension#variantFilter 过滤变体属性 )
- 【Android Gradle 插件】BuildType 编译类型配置 ⑧ ( versionNameSuffix 配置 | zipAlignEnabled 配置 | initWith 方法 )
- 【Android Gradle 插件】LintOptions 配置 ② ( abortOnError 配置 | 手动执行 lint 检查并生成 lint-result.html 检查报告 )
- 【Android Gradle 插件】Gradle 依赖管理 ① ( org.gradle.api.Project 配置 | Android Gradle 插件配置与 Gradle 配置关联 ) ★
- 【Android Gradle 插件】自定义 Gradle 任务 ② ( 在 Terminal 面板中执行 gradlew task 命令显示所有任务 | 命令行输出所有任务 | 单独执行指定任务 )
- 【Android Gradle 插件】Gradle 基础配置 ⑤ ( gradle-wrapper.properties 配置分析 | GRADLE_USER_HOME 目录 )
- 【Android Gradle 插件】Gradle 构建机制 ② ( Groovy 语言 DSL 特性 | settings.gradle 配置文件解析 | 配置子模块工程目录 | 顶层配置 )
- 【Android Gradle 插件】组件化中的 Gradle 构建脚本实现 ⑤ ( 优化 Gradle 构建脚本 | 构建脚本结构 | 闭包定义及用法 | 依赖配置 | android 块配置 )
- 解析Android开发优化之:对界面UI的优化详解(一)
- android获取当前接入点信息判断是ctwap还是ctnet实例代码