Android Studio 3.0 多渠道打包 解决All flavors must now belong to a named flavor dimension

首先官方文档地址:这个需要梯子
https://developer.android.com/studio/build/build-variants?utm_source=android-studio#product-flavors

此处的多渠道包跟友盟没关系,需要配置的话自己去额外配置。
1.配置app下的gradle,在android{}里加入

android {

flavorDimensions "default"
 productFlavors {
    xiaomi {
        dimension "default"
      }
    qh360 {
        dimension "default"
      }
  }
   buildTypes {
    release {
      //这里需要加入这行,这里是为了给打包的apk命名,可以不加,看自己需要
        android.applicationVariants.all { variant ->
            variant.outputs.all {
                outputFileName = "dragview_${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk"
              }
          }
      }
  }
}

写到这里配置基本上就算完成了,接下来需要签名然后打包,签名的方法自己去查找即可。创建签名时 Signature Version 选择 V1 V2的问题可以参考
https://blog.csdn.net/lvshuchangyin/article/details/62227286。(v1 v2 同时勾选即可)

下面贴上官方的文档配置那块代码

android {
 ...
buildTypes {
debug {...}
release {...}
}

// Specifies the flavor dimensions you want to use. The order in which you
// list each dimension determines its priority, from highest to lowest,
// when Gradle merges variant sources and configurations. You must assign
// each product flavor you configure to one of the flavor dimensions.
flavorDimensions "api", "mode"

productFlavors {
demo {
  // Assigns this product flavor to the "mode" flavor dimension.
  dimension "mode"
  ...
}

full {
  dimension "mode"
  ...
}

// Configurations in the "api" product flavors override those in "mode"
// flavors and the defaultConfig {} block. Gradle determines the priority
// between flavor dimensions based on the order in which they appear next
// to the flavorDimensions property above--the first dimension has a higher
// priority than the second, and so on.
minApi24 {
  dimension "api"
  minSdkVersion '24'
  // To ensure the target device receives the version of the app with
  // the highest compatible API level, assign version codes in increasing
  // value with API level. To learn more about assigning version codes to
  // support app updates and uploading to Google Play, read Multiple APK Support
  versionCode 30000 + android.defaultConfig.versionCode
  versionNameSuffix "-minApi24"
  ...
}

minApi23 {
  dimension "api"
  minSdkVersion '23'
  versionCode 20000  + android.defaultConfig.versionCode
  versionNameSuffix "-minApi23"
  ...
}

minApi21 {
  dimension "api"
  minSdkVersion '21'
  versionCode 10000  + android.defaultConfig.versionCode
  versionNameSuffix "-minApi21"
   ...
     }
   }
 }
 ...

猜你喜欢

转载自blog.csdn.net/sinat_35541927/article/details/86521145