美文网首页
使用applicationIdSuffix打多个包

使用applicationIdSuffix打多个包

作者: 因为我的心 | 来源:发表于2024-05-15 13:28 被阅读0次

1、Android配置打多个包

将下面的配置放在app的gradle的android节点下,与defaultConfig节点同等级。里面配置了多个版本.

android {
  flavorDimensions "default"
    productFlavors {
        dev {
            //这里是在 applicationId 中添加了一个后缀。所以『.』要加上
            applicationIdSuffix ".dev"
            buildConfigField "String", "AppEnvironment", "\"dev\""  //dev
            buildConfigField "String", "AppUrl", "\"http://dev.xxxx-tms.xxxx.com/\""
            buildConfigField "String", "AppBugly", "\"1234567\""  //腾讯Bugly
            manifestPlaceholders = [
                    application_label: "TMS_Dev"]
        }
        qa {
             //这里是在 applicationId 中添加了一个后缀。所以『.』要加上
            applicationIdSuffix ".test"
            buildConfigField "String", "AppEnvironment", "\"test\"" //test
            buildConfigField "String", "AppUrl", "\"http://test.xxxx-tms.xxxx.com/\""
            buildConfigField "String", "AppBugly", "\"1234567\""  //腾讯Bugly
            manifestPlaceholders = [
                    application_label: "TMS_Test"
            ]
        }

        prod {
            buildConfigField "String", "AppEnvironment", "\"release\""  //生产
            buildConfigField "String", "AppUrl", "\"http://test.xxxx-tms.xxxx.com/\""
            buildConfigField "String", "AppBugly", "\"1234567\""  //腾讯Bugly
            manifestPlaceholders = [
                    application_label: "TMS"
            ]
        }
    }
  }

将改变后的代码添加进去,并且将其中的包名改成自己的包名,就可以打多个包了。

2、Android使用配置的APP名称

 //必须都写,否则报错
  android:label="${application_label}"
  tools:replace="android:label"
   <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/app_logo"
        android:name=".AsuraApplication"
        android:label="${application_label}"
        android:roundIcon="@mipmap/app_logo"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:requestLegacyExternalStorage="true"
        android:usesCleartextTraffic="true"
        android:networkSecurityConfig="@xml/network_security_config"
        tools:replace="android:label"
        >
      //省略...
       </application>

3、Android使用配置AppUrl

import com.asura.android.tmspda.BuildConfig
var url = BuildConfig.AppUrl

参考:https://blog.51cto.com/u_14523369/6123812

相关文章

网友评论

      本文标题:使用applicationIdSuffix打多个包

      本文链接:https://www.haomeiwen.com/subject/bjivfjtx.html