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

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

相关推荐
OkeyProxy44 分钟前
設置Android設備全局代理
android·代理模式·proxy模式·代理服务器·海外ip代理
刘志辉1 小时前
vue传参方法
android·vue.js·flutter
前期后期4 小时前
Android OkHttp源码分析(一):为什么OkHttp的请求速度很快?为什么可以高扩展?为什么可以高并发
android·okhttp
轻口味6 小时前
Android应用性能优化
android
全职计算机毕业设计6 小时前
基于 UniApp 平台的学生闲置物品售卖小程序设计与实现
android·uni-app
dgiij7 小时前
AutoX.js向后端传输二进制数据
android·javascript·websocket·node.js·自动化
SevenUUp8 小时前
Android Manifest权限清单
android
高林雨露8 小时前
Android 检测图片抓拍, 聚焦图片后自动完成拍照,未对准图片的提示请将摄像头对准要拍照的图片
android·拍照抓拍
wilanzai8 小时前
Android View 的绘制流程
android
INSBUG9 小时前
CVE-2024-21096:MySQLDump提权漏洞分析
android·adb