Android gradle create flavors with cordora 5.0.0
I faced the same problem and I think I have found a workable solution (although I rather see the solution in Cordova itself).
The problem is that the cordova build script (at runtime) assumes that if you have multiple APKs (as in the case of adding ProductFlavors) one of them must be architecture specific. The result is an empty list:
Built the following apk (s):
Cordova app / platform / android / cordova / node_modules / q / q.js: throw 126;
^ Error: Could not find apk architecture: x86 build-type: debug
I have now added the following to my build-extras.gradle :
android.variantFilter { variant ->
def flavor = variant.flavors.get(0).name
if (project.hasProperty("activeFlavor")) {
if (flavor != project.getProperty("activeFlavor")) {
variant.setIgnore(true)
}
}
else {
if (flavor != "mydefaultproductflavor") {
variant.setIgnore(true)
}
}
}
And when I don't want my default scent, I need to specify the scent using:
cordova run android -- --gradleArg="-PactiveFlavor=myotherflavor"
For those who don't know, the delimiter --
is a special character that, by convention, tells the program to stop parsing arguments afterwards. Cordova states that you should use double --
to indicate that these are platform-specific arguments. [1] Nice to know if you need to pass arguments to Cordova from Ionic. [2]
Unfortunately, cordova's build process doesn't like it when I switch versions without cleaning (since then I have multiple .apk files in my output directory again). So the first time you switch, do ./platforms/android/cordova/clean
to delete old .apk files.
[1] See the note on using flags when signing an application.
[2] See dwieeb's comment on ionic-cli 2254 for more details.
source to share