Android 不同构建变量中的不同代码

Android 不同构建变量中的不同代码,android,android-productflavors,android-build-flavors,Android,Android Productflavors,Android Build Flavors,我的应用程序中有两个版本,一个是标准应用程序版本,另一个是定制应用程序 productFlavors { customConfig { minSdkVersion 14 applicationId 'es.com.custom' targetSdkVersion 22 versionCode 3 versionName '3.0.0' }

我的应用程序中有两个版本,一个是标准应用程序版本,另一个是定制应用程序

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
构建变体是Gradle使用一组特定规则的结果 组合生成中配置的设置、代码和资源 类型和产品口味。尽管您没有配置生成 您可以直接配置构建类型和产品 形成它们的味道


阅读

您必须为每种口味创建源目录。 因此,您将能够为特定的口味维护一个单独的文件


请浏览将对您有所帮助的

您可以用一种简单的方法完成此操作。您的项目中现在应该有一个名为“standard”的文件夹。只需在“standard”文件夹所在的同一文件夹中创建另一个名为“customConfig”的文件夹(也可能在gradle同步后创建)

在“customConfig”中创建另一个名为“res”的文件夹(同样,您可能已经拥有了它)。然后创建另一个文件夹“值”。在“值”文件夹中,您可以创建值文件。将文件命名为“values.xml”并返回到项目。您的“values.xml”文件应该如下所示:

<?xml version="1.0" encoding="utf-8"?>
<resources>
     <string name="custom_app_id">es.com.custom</string>s
</resources>
希望这有帮助

<?xml version="1.0" encoding="utf-8"?>
<resources>
     <string name="custom_app_id">es.com.custom</string>s
</resources>
 if (getPackageName().equals(getString(R.string.custom_app_id)))// for custom
// do the custom things
else
//do the standard things