You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android动态功能按国家条件分发的非Play商店测试方法咨询

如何在不依赖Google Play的情况下测试动态功能模块的国家分发条件?

问题描述

我在Android应用中使用动态功能模块,为该模块配置了仅对德国(DE)开放的国家分发条件,配置代码如下:

<dist:module dist:title="@string/title_dynamicfeaturede">
    <dist:fusing dist:include="true" />
    <dist:delivery>
        <dist:install-time>
            <dist:conditions>
                <dist:user-countries dist:exclude="false">
                    <dist:country dist:code="DE"/>
                </dist:user-countries>
            </dist:conditions>
        </dist:install-time>
    </dist:delivery>
</dist:module>

但使用bundleTool测试时,这个条件被忽略了,想请教下不借助Google Play商店的话,该怎么测试这个分发条件?


解决方案

其实bundleTool本身就支持模拟这类分发条件,只是需要用对参数。下面是几种可行的测试方法:

1. 自定义设备配置文件来模拟国家/地区

  • 先导出你的测试设备的基础配置:
    bundletool get-device-spec --output=device-spec.json
    
  • 打开生成的device-spec.json,添加countryCode字段来指定目标国家。比如要模拟德国用户,就加:
    "countryCode": "DE"
    
    要是想验证非德国用户的情况,就改成US这类其他国家代码。
  • 之后用这个自定义配置生成APKS或者直接安装应用,命令里带上--device-spec参数:
    # 生成适配该配置的APKS文件
    bundletool build-apks --bundle=app.aab --output=app.apks --device-spec=device-spec.json
    # 或者直接安装到测试设备
    bundletool install-apks --apks=app.apks --device-spec=device-spec.json
    
    这样bundleTool就会根据你指定的国家代码,判断是否要包含目标动态模块。

2. 直接用命令行参数指定国家(bundleTool 0.10.0+支持)

从bundleTool 0.10.0版本开始,你可以不用修改配置文件,直接在build-apks或install-apks命令里用--country参数指定国家代码:

# 模拟德国用户安装,验证模块是否被包含
bundletool install-apks --apks=app.apks --country=DE
# 模拟美国用户安装,验证模块是否被排除
bundletool install-apks --apks=app.apks --country=US

3. 验证模块过滤结果

你可以用extract-apks命令把APKS里的内容提取出来,检查目标动态模块的APK是否存在:

bundletool extract-apks --apks=app.apks --output-dir=extracted_apks --device-spec=device-spec.json

然后查看extracted_apks目录,就能确认分发条件是否生效了。

注意事项

  • 确保你的bundleTool是最新版本,旧版本可能不支持--country这类参数。
  • 因为你用的是install-time交付类型,模块是否被包含是在安装阶段决定的,所以测试时要先卸载设备上的旧应用,再重新安装验证。

内容的提问来源于stack exchange,提问作者Tommy Giesbrecht

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:41:27