Android打包之多版本、多环境、多渠道,2024大厂Android面试真题集锦

manifestPlaceholders = [
app_name: “开-WalleDemo”,
app_icon: “@drawable/icon_develop”
]
}
//测试环境
check {
buildConfigField “int”, “ENV_TYPE”, “2”
applicationId ‘om.soubu.walledemo.check’
manifestPlaceholders = [
app_name: “测-WalleDemo”,
app_icon: “@drawable/icon_check”
]
}
//生产环境
product {
buildConfigField “int”, “ENV_TYPE”, “3”
applicationId ‘com.soubu.walledemo.product’
manifestPlaceholders = [
app_name: “WalleDemo”,
app_icon: “@drawable/icon_product”
]
}
}
}

dependencies {
compile fileTree(dir: ‘libs’, include: [‘*.jar’])
androidTestCompile(‘com.android.support.test.espresso:espresso-core:2.2.2’, {
exclude group: ‘com.android.support’, module: ‘support-annotations’
})
compile ‘com.android.support:appcompat-v7:25.1.0’
testCompile ‘junit:junit:4.12’

compile ‘com.meituan.android.walle:library:1.0.3’
}

(3) 这里,我根据不同的环境生成了不同包名的apk,方便在手机上同时安装多个环境的应用。为了让gradle动态更改apk的名称和图标,我们需要在manifest文件中使用{app_name}等占位符

<?xml version="1.0" encoding="utf-8"?>




(4) 在代码中获取多渠道信息

String channel = WalleChannelReader.getChannel(getApplicationContext());

(5) 在代码中获取多环境信息

int envType = BuildConfig.ENV_TYPE;

这里的BuildConfig是由gradle动态生成的:

package com.soubu.walledemo;

public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean(“true”);
public static final String APPLICATION_ID = “om.soubu.walledemo.develop”;

  • 26
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值