【问题标题】:Android Studio 3.0 Flavor Dimension IssueAndroid Studio 3.0 风格维度问题
【发布时间】:2017-10-21 15:42:36
【问题描述】:

升级到 Studio Canary 版本。我之前的 Telegram Messenger 项目出现以下错误。

错误:所有风味现在必须属于一个命名风味维度。风味“armv7”未分配给风味维度。在https://d.android.com/r/tools/flavorDimensions-missing-error-message.html了解更多信息

我该怎么办?我已经看过那个链接,但不明白该怎么做。我现在有 3 个构建变体,发布、调试和 foss。

【问题讨论】:

    标签: android android-studio gradle armv7


    【解决方案1】:

    如果您真的不需要该机制,只需在您的 build.gradle 中指定一个随机风味维度:

    android { 
        ...
        flavorDimensions "default"
        ...
    }
    

    更多信息,请查看migration guide

    【讨论】:

    • 谢谢。我已经有一个维度“versionCode”,我用过。
    • flavorDimensions "versionCode" productFlavors { debug { dimension "default" versionName "1.0" } release { dimension "default" versionName "1.0" } foss { dimension "default" versionName "1.0" } } 我得到了此错误 ..ProductFlavor 名称不能与 BuildType 名称冲突。你能请任何人帮助我吗?我收到了这个错误 AS 3.0 beta version Canary with Kotlin。
    • 如果你只有一个维度,你不需要在每个风味中都指定它。只需上面的第一行 flavorDimensions "default" 即可。
    • @GrahamBorland 感谢您的提示,我相应地更新了答案。
    • 也许补充一下,文件是app/build.gradle
    【解决方案2】:

    经过仔细尝试和阅读,我自己解决了。 解决方案是在 build.gradle 中添加以下行。

    flavorDimensions "versionCode"

    android { 
           compileSdkVersion 24
           .....
           flavorDimensions "versionCode"
    } 
    

    【讨论】:

    • 你在 gradle 的哪个位置添加了这一行?多一点上下文会有所帮助
    • 在 build.gradle 文件中,在 android { ... }
    • android { compileSdkVersion 24.... //在这里添加 }
    • 为什么是 "versionCode" 而不是别的?它会影响 versionCode 吗?
    • @MBH 我的 productFlavors 中有这个。您只需要任何唯一的密钥即可识别。
    【解决方案3】:

    这里你可以解决这个问题,你需要用 productFlavors 的名字添加 flavorDimension 并且还需要定义维度,见下面的例子,更多信息见这里 https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

    flavorDimensions 'yourAppName' //here defined dimensions
    productFlavors {
        production {
            dimension 'yourAppName' //you just need to add this line
            //here you no need to write applicationIdSuffix because by default it will point to your app package which is also available inside manifest.xml file.
    
        }
    
        staging {
            dimension 'yourAppName' //added here also
            applicationIdSuffix ".staging"//(.staging) will be added after your default package name.
            //or you can also use applicationId="your_package_name.staging" instead of applicationIdSuffix but remember if you are using applicationId then You have to mention full package name.
            //versionNameSuffix "-staging"
    
        }
    
        develop {
            dimension 'yourAppName' //add here too
            applicationIdSuffix ".develop"
            //versionNameSuffix "-develop"
    
        }
    

    【讨论】:

      【解决方案4】:

      如果你不想使用维度,你应该使用这条线

      android { 
      compileSdkVersion 24
      
      ...
      flavorDimensions "default"
      ...
      }
      

      但是如果你想使用维度,你应该先声明你的维度名称,然后再使用这个名称 此示例来自文档:

      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"
        ...
          }
        }
      }
      ...
      

      【讨论】:

        【解决方案5】:

        我在 build.gradle (Module: app) 中为我的应用程序使用了 flavorDimensions

        flavorDimensions "tier"
        
        productFlavors {
            production {
                flavorDimensions "tier"
                //manifestPlaceholders = [appName: APP_NAME]
                //signingConfig signingConfigs.config
            }
            staging {
                flavorDimensions "tier"
                //manifestPlaceholders = [appName: APP_NAME_STAGING]
                //applicationIdSuffix ".staging"
                //versionNameSuffix "-staging"
                //signingConfig signingConfigs.config
            }
        }
        

        Check this link for more info

        // Specifies two flavor dimensions.
        flavorDimensions "tier", "minApi"
        
        productFlavors {
             free {
                    // Assigns this product flavor to the "tier" flavor dimension. Specifying
                    // this property is optional if you are using only one dimension.
                    dimension "tier"
                    ...
             }
        
             paid {
                    dimension "tier"
                    ...
             }
        
             minApi23 {
                    dimension "minApi"
                    ...
             }
        
             minApi18 {
                    dimension "minApi"
                    ...
             }
        }
        

        【讨论】:

          【解决方案6】:

          在 KotlinDSL 中你可以这样使用:

          flavorDimensions ("PlaceApp")
          productFlavors {
              create("tapsi") {
                  setDimension("PlaceApp")
                  buildConfigField("String", "API_BASE_URL", "https://xxx/x/x/")
              }
          
          }
          

          【讨论】:

            【解决方案7】:

            如果您有简单的口味(免费/专业、演示/完整等),请添加到 build.gradle 文件:

            android {
            ...
            flavorDimensions "version"
            productFlavors {
                    free{
                        dimension "version"
                        ...
                        }
                    pro{
                        dimension "version"
                        ...
                        }
            }
            

            您可以按维度创建“风味中的风味”。 Read more.

            【讨论】:

              猜你喜欢
              • 2018-04-14
              • 1970-01-01
              • 2017-01-09
              • 1970-01-01
              • 2013-05-25
              • 2018-04-10
              • 2018-05-20
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多