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

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

相关推荐
花花鱼1 小时前
android studio 设置让开发更加的方便,比如可以查看变量的类型,参数的名称等等
android·ide·android studio
alexhilton3 小时前
为什么你的App总是忘记所有事情
android·kotlin·android jetpack
AirDroid_cn6 小时前
OPPO手机怎样被其他手机远程控制?两台OPPO手机如何相互远程控制?
android·windows·ios·智能手机·iphone·远程工作·远程控制
尊治6 小时前
手机电工仿真软件更新了
android
xiangzhihong89 小时前
使用Universal Links与Android App Links实现网页无缝跳转至应用
android·ios
车载应用猿9 小时前
基于Android14的CarService 启动流程分析
android
没有了遇见10 小时前
Android 渐变色实现总结
android
雨白13 小时前
Jetpack系列(四):精通WorkManager,让后台任务不再失控
android·android jetpack
mmoyula15 小时前
【RK3568 驱动开发:实现一个最基础的网络设备】
android·linux·驱动开发
sam.li15 小时前
WebView安全实现(一)
android·安全·webview