Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic android build error : "All flavors must now belong to a named flavor dimension"

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. 
like image 608
Hugo H Avatar asked Nov 21 '17 12:11

Hugo H


Video Answer


1 Answers

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.

like image 197
Gilson Avatar answered Sep 20 '22 07:09

Gilson