3

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+ で動作するわけではないため、multiDex と縮小を制御したいと考えています。例えば:

  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

これらのプロパティを組み合わせるにはどうすればよいですか?

4

2 に答える 2

2

minifyEnabled()プロパティはBuildType DSL オブジェクトでのみ使用できます。ProductFlavorオブジェクトmultiDexEnabledを指します。したがって、これらのプロパティを組み合わせたい場合は、これらの両方のオブジェクトで指定する必要があります。例えば:

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

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

デバッグ ビルドにはdevDebugビルド バリアントを使用し、リリースには -を使用しprodReleaseます。

于 2016-12-27T00:10:06.277 に答える
0

すぐ下の@maxostが示唆するように、
Android開発者のリンクを提供しました。
ここを参照してください[ https://developer.android.com/studio/build/multidex.html#dev-build]

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'
        }
于 2016-12-27T11:26:36.700 に答える