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

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

相关推荐
牛蛙点点申请出战5 分钟前
仿微信语音 WaveView 实现
android·前端·ios
用户099 分钟前
Android View 事件分发机制详解及应用
android·kotlin
ForteScarlet17 分钟前
Kotlin 2.2.20 现已发布!下个版本的特性抢先看!
android·开发语言·kotlin·jetbrains
诺诺Okami26 分钟前
Android Framework-Input-8 ANR相关
android
法欧特斯卡雷特29 分钟前
Kotlin 2.2.20 现已发布!下个版本的特性抢先看!
android·前端·后端
人生游戏牛马NPC1号30 分钟前
学习 Android (二十一) 学习 OpenCV (六)
android·opencv·学习
用户20187928316730 分钟前
Native 层 Handler 机制与 Java 层共用 MessageQueue 的设计逻辑
android
lichong95140 分钟前
【混合开发】vue+Android、iPhone、鸿蒙、win、macOS、Linux之android 把assert里的dist.zip 包解压到sd卡里
android·vue.js·iphone
·云扬·2 小时前
MySQL 日志全解析:Binlog/Redo/Undo 等 5 类关键日志的配置、作用与最佳实践
android·mysql·adb
Kapaseker2 小时前
如果你的 View 不支持 Compose 怎么办
android·kotlin