android - 不同构建变体中的不同代码

标签 android android-productflavors android-build-flavors

我的应用程序中有两个构建变体,一个是标准应用程序版本,第二个是自定义应用程序。

productFlavors {
        customConfig {
            minSdkVersion 14
            applicationId 'es.com.custom'
            targetSdkVersion 22
            versionCode 3
            versionName '3.0.0'
        }
        standard {
            minSdkVersion 14
            applicationId 'es.com.standard'
            targetSdkVersion 22
            versionCode 3
            versionName '3.0.0'
        }

对于自定义,我必须实现新功能,但只是为了自定义,所以这些新功能在标准版本上不可用。我不确定我必须做什么。

1.- 两类,一类是标准要求,一类是定制要求
2.- 在标准类中做类似的事情:

  if (getPackageName()==customConfig )
    // do the custom things
    else
    //do the standard things

最佳答案

Build variants are the result of Gradle using a specific set of rules to combine settings, code, and resources configured in your build types and product flavors. Although you do not configure build variants directly, you do configure the build types and product flavors that form them.

 if(BuildConfig.Flavor.equals("customConfig")) 
    {

    }
  else
   {

   }

阅读 Building multiple flavors of an Android

关于android - 不同构建变体中的不同代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43777949/

相关文章:

android - Flutter - 根据 Android 产品风格设置目标文件

android - 在 android 中为不同的风格创建单独的 apk 以在同一设备上运行

android - 如何从普通java类中为不同的产品风格调用不同的方法

java - 某些 Android 设备中的背景颜色错误

java - Android 编程中 fragment 、 Activity 和布局/菜单 XML 文件之间的关系是什么?

android - SmsManager 空指针异常

android - Gradle:为库的特定风格添加依赖项

android - 在忽略特殊字符的同时在 RegEx 中查找 Word

android - 强制关闭应用程序后,工作经理定期工作无法在中文 ROM 上工作

android - 如何从产品口味上控制 multiDex 和 minifying?