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")
        }
}

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

相关推荐
Mckay882 小时前
android studio导入项目
android·ide·android studio
是店小二呀4 小时前
【优选算法 | 字符串】字符串模拟题精选:思维+实现解析
android·c++·算法
奔跑吧 android5 小时前
【android bluetooth 协议分析 12】【A2DP详解 1】【车机侧蓝牙音乐免切源介绍】
android·bluetooth·bt·gd·a2dpsink·免切源·aosp14
飞猿_SIR6 小时前
Android Exoplayer多路不同时长音视频混合播放
android·音视频
前端懒猫6 小时前
android实现USB通讯
android
jiet_h7 小时前
Android锁
android
teacher伟大光荣且正确15 小时前
Qt Creator 配置 Android 编译环境
android·开发语言·qt
飞猿_SIR18 小时前
Android Exoplayer 实现多个音视频文件混合播放以及音轨切换
android·音视频
HumoChen9918 小时前
GZip+Base64压缩字符串在ios上解压报错问题解决(安卓、PC模拟器正常)
android·小程序·uniapp·base64·gzip
沙振宇1 天前
【HarmonyOS】ArkTS开发应用的横竖屏切换
android·华为·harmonyos