简体   繁体   English

Android Studio 3.0 Flavor Dimension 问题

[英]Android Studio 3.0 Flavor Dimension Issue

Upgraded to Studio Canary build.升级到 Studio Canary 版本。 My previous project of Telegram Messenger is giving following error.我之前的 Telegram Messenger 项目出现以下错误。

Error:All flavors must now belong to a named flavor dimension.错误:所有风味现在必须属于命名风味维度。 The flavor 'armv7' is not assigned to a flavor dimension.风味“armv7”未分配给风味维度。 Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.htmlhttps://d.android.com/r/tools/flavorDimensions-missing-error-message.html了解更多信息

What should I do?我该怎么办? I have already seen that link but couldn't understand what to do.我已经看过那个链接,但不明白该怎么做。 I have 3 build variants now, release,debug and foss.我现在有 3 个构建变体,release、debug 和 foss。

If you don't really need the mechanism, just specify a random flavor dimension in your build.gradle :如果您真的不需要该机制,只需在build.gradle指定一个随机的风味维度:

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

For more information, check the migration guide有关更多信息,请查看迁移指南

After trying and reading carefully, I solved it myself.经过尝试和仔细阅读,我自己解决了。 Solution is to add the following line in build.gradle.解决方法是在 build.gradle 中添加以下行。

flavorDimensions "versionCode"风味维度“版本代码”

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

Here you can resolve this issue, you need to add flavorDimension with productFlavors's name and need to define dimension as well, see below example and for more information see here https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html在这里您可以解决此问题,您需要添加带有 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"

    }

If you want not to use dimensions you should use this line如果您不想使用尺寸,则应使用此行

android { 
compileSdkVersion 24

...
flavorDimensions "default"
...
}

but if you want ti use dimensions you should declare your dimension name first and then use this name after THIS example is from the documentations:但是如果你想使用维度,你应该先声明你的维度名称,然后在这个例子来自文档之后使用这个名称:

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

I have used flavorDimensions for my application in build.gradle (Module: app)我在 build.gradle(模块: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"
            ...
     }
}

in KotlinDSL you can use like this :在 KotlinDSL 中,您可以这样使用:

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

}

If you have simple flavors (free/pro, demo/full etc.) then add to build.gradle file:如果您有简单的口味(免费/专业版、演示版/完整版等),则添加到 build.gradle 文件中:

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

By dimensions you can create "flavors in flavors".通过维度,您可以创建“口味中的口味”。 Read more . 阅读更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM