Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Studio:如何删除/过滤默认调试和发布构建类型的构建变体,并仅保留使用自定义构建类型的构建变体?_Android_Android Studio_Gradle_Android Build Type - Fatal编程技术网

Android Studio:如何删除/过滤默认调试和发布构建类型的构建变体,并仅保留使用自定义构建类型的构建变体?

Android Studio:如何删除/过滤默认调试和发布构建类型的构建变体,并仅保留使用自定义构建类型的构建变体?,android,android-studio,gradle,android-build-type,Android,Android Studio,Gradle,Android Build Type,我创建了自定义构建类型,如下所示: buildTypes { releasefree.initWith(buildTypes.release) releasefree { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard

我创建了自定义构建类型,如下所示:

 buildTypes {
        releasefree.initWith(buildTypes.release)
        releasefree {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        releasepro.initWith(buildTypes.release)
        releasepro {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationIdSuffix ".pro"
        }
        debugfree.initWith(buildTypes.debug)
        debugfree {
            shrinkResources true
            applicationIdSuffix ".debug"
            debuggable true
        }
        debugpro.initWith(buildTypes.debug)
        debugpro {
            shrinkResources true
            applicationIdSuffix ".pro.debug"
            debuggable true
        }
    }
我不打算使用默认的调试和发布构建类型,我想从构建变体列表中删除它们。我有不止几种口味,而且种类太多了。删除带有默认调试和发布类型的变体将有所帮助,因为我永远不会使用它们

我试着使用变体过滤器,如下所示,但不起作用

android.variantFilter { variant ->
    if(variant.buildType.name.endsWith('Release') || variant.buildType.name.endsWith('Debug')) {
        variant.setIgnore(true);
    }
}

我过滤变体的方式是否有问题,或者只是无法删除默认调试和发布版本类型的变体。

解决了这个问题。对我来说,这真是一个愚蠢的错误。 上面的变量过滤器不起作用。这些名字都是小写的,而我所比较的字符串中的大写就是罪魁祸首

更改为以下内容(使比较字符串小写)使其按预期工作:

android.variantFilter { variant ->
    if(variant.buildType.name.endsWith('release') || variant.buildType.name.endsWith('debug')) {
        variant.setIgnore(true);
    }
}
还是这个

android.variantFilter { variant ->
    if(variant.buildType.name.equals('release') || variant.buildType.name.equals('debug')) {
        variant.setIgnore(true);
    }
}

如果您想按名称排除,请使用以下内容

android.variantFilter { variant ->
    if(variant.name.equals("qaRelease")|| variant.name.equals('something')) {
        variant.setIgnore(true);
    }
}

如果您想忽略特定的构建变量,请参阅以下详细信息

flavorDimensions "client", "server"
productFlavors {
    client1 {
        manifestPlaceholders variant : 'Client 1'
        dimension "client"
        applicationId "com.edupointbd.bb"
    }
    client2 {
        manifestPlaceholders variant : 'Client 2'
        dimension "client"
        applicationId "com.edupointbd.bb"
    }
    dev {
        dimension "server"
    }
    staging {
        dimension "server"
    }
    production {
        dimension "server"
    }
}

variantFilter { variant ->
    def names = variant.flavors*.name
    // To check for a certain build type, use variant.buildType.name == "<buildType>"
    if (names.contains("client1") && names.contains("production")) {
        // Gradle ignores any variants that satisfy the conditions above.
        setIgnore(true)
    }
}
“客户端”、“服务器” 产品风味{ 客户1{ 清单占位符变量:“客户端1” 维度“客户端” applicationId“com.edupointbd.bb” } 客户2{ 清单占位符变量:“客户端2” 维度“客户端” applicationId“com.edupointbd.bb” } 发展{ 维度“服务器” } 登台{ 维度“服务器” } 生产{ 维度“服务器” } } variantFilter{variant-> def名称=variant.flavors*.name //要检查特定生成类型,请使用variant.buildType.name=“” if(names.contains(“client1”)&&names.contains(“production”)){ //Gradle忽略满足上述条件的任何变体。 setIgnore(true) } }