Android 多渠道配置

Android 多包名,icon

本篇文章主要记录下android 下的同一工程,打包时配置不同的包名,icon,名称等信息.

1: 多包名

首先讲述下如何配置多包名.

在build.gralde的android 标签下添加:

复制代码
productFlavors{
        xiaomi{
            applicationId "com.test.usagetest"
        }
        huawei{
            applicationId "com.test.usagetest1"
        }
}

此时如果我们运行的话,会出现下面错误:

复制代码
A problem occurred configuring project ':app'.
> All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html

解决办法:

defaultConfig添加一行代码:

复制代码
flavorDimensions "versionCode"

此时编译重新运行即可.

2: 多icon

  1. 修改manifest.xml

    java 复制代码
    <application
        android:allowBackup="true"
        android:icon="${app_icon}"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.UsageTest">

    将icon属性由原来的"@mipmap/ic_launcher" 替换成${app_icon}

  2. 修改build.gradle

    shell 复制代码
    productFlavors{
        xiaomi{
            applicationId "com.test.usagetest"
            manifestPlaceholders = [app_icon : "@mipmap/ic_launcher"]
        }
        huawei{
            applicationId "com.test.usagetest1"
            manifestPlaceholders = [app_icon : "@mipmap/ic_launcher2"]
        }
    }

运行后可以看到icon已替换.

3:多名称

修改方法与icon一致.

复制代码
productFlavors{
    xiaomi{
        applicationId "com.test.usagetest"
        manifestPlaceholders = [app_icon : "@mipmap/ic_launcher",
                                app_name : "test1"]
    }
    huawei{
        applicationId "com.test.usagetest1"
        manifestPlaceholders = [app_icon : "@mipmap/ic_launcher2",
                                app_name : "test2"]
    }
}

4: 多资源

不同的包名对应不同的资源文件.

配置res的不同路径.

复制代码
 sourceSets{
        xiaomi{
            res.srcDir("src/main/res")
        }
        huawei{
            res.srcDir("src/hw/res")
        }
}

相同资源名称下设置不同的值即可.

相关推荐
Xzaveir12 小时前
不要用一个状态表示“号码已认证”:企业号码身份的四域模型
android·人工智能
(Charon)12 小时前
【C++】手写 MySQL 连接池(二):同步连接的获取、加锁与释放
android
zhangjin112014 小时前
AOSP下载
android
Mico1814 小时前
MySQL 8.0.35 GTID 主从复制搭建-基于GITD
android·mysql·adb
YXL1111YXL16 小时前
LeakCanary 源码解析检测泄露工作机制(一)
android·leakcanary
且随疾风前行.18 小时前
Android Binder 驱动 - 内核驱动层源码初探
android·网络·binder
额恩6618 小时前
AI 智能体从零搭建实战教程——扣子
android·rxjava·coze
hunterandroid19 小时前
前台服务适配与线上排查:通知权限、启动限制和任务保活
android·前端
帅次19 小时前
Android 高级工程师面试:Flutter 渲染与性能 近1年高频追问 20 题
android·flutter·面试·渲染·性能
糖果店的幽灵20 小时前
【langgraph 从入门到精通graphApi 篇】Command 与动态流程控制
android·java·数据库·人工智能·langgraph