14

I've started a new project on my computer but I'm not able anymore to build for android

When I run

ionic cordova platform run android

I get this error :

All flavors must now belong to a named flavor dimension. 
Hugo H
  • 6,029
  • 5
  • 37
  • 57

4 Answers4

28

The "flavours" error will occur if you have the cordova-plugin-crosswalk-webview plugin installed in your project and you try to build with Gradle v4.

However, if you want to upgrade to cordova-android@6.4.0 (e.g. to open your Cordova Android platform project in Android Studio 3 to debug native plugin code), you'll need to upgrade to Gradle v4. Hence cordova-plugin-crosswalk-webview is currently incompatible with cordova-android@6.4.0.

As a manual workaround for the "flavours" error, you can insert a default flavour in the platforms/android/build.gradle (see here):

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

Update

If you want to build with Gradle v4/cordova-android@6.4+ and cordova-plugin-crosswalk-webview, update to Gradle v4 then install cordova-android off the master branch, since this PR to resolve the "flavours" error with multiple APK builds has now been merged:

cordova platform rm android 
  && cordova platform add https://github.com/apache/cordova-android
DaveAlden
  • 30,083
  • 11
  • 93
  • 155
  • > Hence cordova-plugin-crosswalk-webview is currently incompatible with cordova-android@6.4.0 This is only true if you are building separate apks for the two versions. If you set `xwalkMultipleApk` to `false` - e.g. ` ` in `config.xml`, you can use gradle 4 + cordova-android@6.4. $ gradle -v --------------------- Gradle 4.4.1 --------------------- $ cordova platform ls Installed platforms: android 6.4.0 ios 4.5.4 – Shankari Jan 21 '18 at 01:50
  • I have checked that PR you told, but this code are not on release 6.4.0 nor 7.0.0 – Gilson Feb 17 '18 at 00:05
  • 1
    Now i am getting this error after adding the flavorDimention: default `A problem occurred configuring root project 'android'. > Flavor 'armv7' has no flavor dimension.` – Sri Krishna Mar 20 '18 at 06:21
  • @SriKrishna anything you found for `Flavor 'armv7' has no flavor dimension.` ? – Sanket Patel Oct 27 '18 at 12:31
2

I get the same error and i have created a script to solve it.

As there was said in the answer, the problem is: gradle 4 wants flavorDimensions on gradle.build.

If you check here: https://cordova.apache.org/docs/en/latest/guide/platforms/android/#extending-buildgradle

We can create a file named gradle-extra.build with will be included on gradle.build, we just need to create a script to paste this file on /platform/android/.

So i created this file build-extras.gradle in my project root

android { 
    flavorDimensions "default"
} 

and the script on ./hooks/after_platform_add/copy_build-extras.gradle.js

#!/usr/bin/env node

var fs = require('fs');
var path = require('path');

if(fs.existsSync(path.resolve(__dirname, '../../platforms/android'))) {
  fs.createReadStream(path.resolve(__dirname, '../../build-extras.gradle')).pipe(fs.createWriteStream(path.resolve(__dirname, '../../platforms/android/build-extras.gradle')));
}

You can check about hooks here: https://cordova.apache.org/docs/en/latest/guide/appdev/hooks/index.html

every script under /hooks/after_platform_add will be executed after ionic platform add ***

With this, we don't need to downgrade gradle nor change cordova-android version.

Gilson
  • 478
  • 7
  • 14
1

Found the solution. :)

Gradle version was the problem. I had to downgrade from 4.X to 3.5.1, which workds great!

Check you gradle version by doing

gradle -v

If if's > 4.x, downgrade it!

Hugo H
  • 6,029
  • 5
  • 37
  • 57
0

This issue should be solved in this PR: https://github.com/crosswalk-project/cordova-plugin-crosswalk-webview/pull/255

Ruben Stolk
  • 12,386
  • 2
  • 18
  • 12