Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.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 如何从产品口味控制多重指数和缩小?_Android_Android Studio_Gradle_Android Productflavors_Android Build Flavors - Fatal编程技术网

Android 如何从产品口味控制多重指数和缩小?

Android 如何从产品口味控制多重指数和缩小?,android,android-studio,gradle,android-productflavors,android-build-flavors,Android,Android Studio,Gradle,Android Productflavors,Android Build Flavors,我正在使用以下风格改进Android 5及以上版本设备的调试版本: productFlavors { // Define separate dev and prod product flavors. dev { // dev utilizes minSDKVersion = 21 to allow the Android gradle plugin // to pre-dex each module and produce an APK that can

我正在使用以下风格改进Android 5及以上版本设备的调试版本:

productFlavors {
    // Define separate dev and prod product flavors.
    dev {
      // dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
      // to pre-dex each module and produce an APK that can be tested on
      // Android Lollipop without time consuming dex merging processes.
      minSdkVersion 21
    }
    prod {
      // The actual minSdkVersion for the application.
      minSdkVersion 16
    }
  }
然而,并不是我所有的设备都在api 21+下运行,因此我想控制多索引和缩小。例如:

  productFlavors {
    dev {
      minSdkVersion 21
      multiDexEnabled false
      minifyEnabled false
    }
    prod {
      minSdkVersion 16
      multiDexEnabled true
      minifyEnabled true
    }
  }
但这给了我:

Error:(44, 0) Could not find method minifyEnabled() for arguments [false] on ProductFlavor_Decorated
如何将这些属性组合在一起?

minifyEnabled()
property仅在DSL对象中可用。而
multiDexEnabled
指的是对象。因此,如果要组合这些属性,必须在这两个对象中都指定它。例如:

productFlavors {
    dev {
        minSdkVersion 21
        multiDexEnabled false
    }
    prod {
        minSdkVersion 16
        multiDexEnabled true
    }
}

buildTypes {
    debug {
        minifyEnabled false
    }
    release {
        minifyEnabled true
    }
}

对于调试版本,请使用
devDebug
buildvariant,对于发布版本-
prodRelease

使用@maxst
就在下面,我提供了android开发者链接
请参阅此处[:

android {
            defaultConfig {
                ...
                multiDexEnabled true
            }
            productFlavors {
                dev {
                    // Enable pre-dexing to produce an APK that can be tested on
                    // Android 5.0+ without the time-consuming DEX build processes.
                    minSdkVersion 21
                }
                prod {
                    // The actual minSdkVersion for the production version.
                    minSdkVersion 14
                }
            }
            buildTypes {
                release {
                    minifyEnabled true
                    proguardFiles getDefaultProguardFile('proguard-android.txt'),
                                                         'proguard-rules.pro'
                }
            }
        }
        dependencies {
            compile 'com.android.support:multidex:1.0.1'
        }