Facing error in building android in Ionic Framework - ionic-framework

I am having an error when running the command:
$ ionic build android

Did you install Android SDK and configure your Android_Home correctly ?
See Here for a detailed, step by step documentation.

Related

Ionic build android doesn't find Android AVD

I have an issue when I want to run the following command sudo ionic cordova run android --device but I have the error below.
Do Someone knows how I can fix it please? I have the avd folder in ~/.android.
Ok Found it, it's because I'm using sudo. Just ionic cordova build android --device is working

Ionic 4: Issue building for device

Error when building for the device
I am getting an error when I try to build for the device(ionic cordova run android --device). For some reason it is not creating platforms/android/app/build/outputs/apk/debug/app-debug/apk. I have tried removing and adding android different versions. Also, I have tried ionic cordova run android --no-native-run and it loads but with a blank screen.
I found 2 solutions, so if you have a problem with running the device feature:
Update CLI!
Remove Android
ionic cordova platform rm android
Add android#6 and run ionic cordova run android --no-native-run
OR
3.add the latest android#latest and run ionic cordova run android.
Those two worked for me, depending on the version of your projects!

Ionic plugins not installed

I have an issue only with android build, when I running on emulator or device android I get the error that ALL plugins are not installed, on ios emulator or device I dont have this issue
Any idea?
Thanks
Evripides
Maybe your plugins are not prepared.
Try cordova prepare then npm install and finally ionic cordova platform add <your_platform>
Your problem is specific with android so your platform should be android
remove node module and package.json.lock file manually
remove android platform using command ionic cordova platform rm android
npm i
ionic cordova platform add android
and install all plugins like below
ionic cordova plugin add cordova-plugin-file
npm install #ionic-native/file --save
Finaly I found the error on 1 plugin in-app-purchase, I removed it and reinstall it and now all are fine
Thank you all
sometimes android build fails dependencies mismatch so and re run fresh.
delete node_module
npm i
ionic cordova rm android
ionic cordova add platform android

Ionic v4: "Ionic cordova run -l" won't start my app

Additional notes for upcoming viewers
This seems to be a common problem on macOS: https://github.com/ios-control/ios-sim/issues/253
Temporary solution below this question.
I've worked on a fresh ionic project a few days ago and I had no problems back then whatsoever.
Today I tried to start the development server: ionic cordova run -l but then I got this error message:
No target specified for emulator. Deploying to undefined simulator
Device type "com.apple.CoreSimulator.SimDeviceType.undefined" could not be found.
An error occurred while running subprocess cordova.
Logging currently available devices(ionic cordova run --list) gives me this output:
Available ios devices:
Available ios virtual devices:
It is empty. None devices are available. Not for ios and neither for android.
Ionic version: 4.12.0
Cordova version: 9.0.0
Nodejs version: 11.5.0
I would appreciate any help to make this work again.
Seems like you have upgraded the Mac OS, faced similar problem in past and updating and re-installing iOS-sim was not of much help.
For me following command worked without installing anything further
ionic cordova emulate ios --livereload --consolelogs --target="iPhone-6,com.apple.CoreSimulator.SimRuntime.iOS-12-2"
Also, you can try this one if above don't work
ionic cordova emulate ios --livereload --consolelogs --target="iPhone-6,com.apple.CoreSimulator.SimRuntime.iOS-12-2" --buildFlag="-UseModernBuildSystem=0"
Do the following:
cd platforms/ios/cordova && npm install ios-sim#latest
cd ../../../
cordova platform rm ios
cordova platform add ios#4.5.0
ionic cordova emulate ios --target --list
ionic cordova plugin rm cordova-plugin-console
That should do it.

Fail to build android Ionic version 1

I have an Ionic version 1 project and install Ionic version 4 on my linux machine.
When trying to build an Android using ionic build android e get this error message:
Unable to load PlatformApi from platform. Error: Cannot find module '/home/myuser/ionic/myapp/platforms/android/cordova/Api.js'
How can i solve this problem?
this issue in latest ionic and cordova versions. try to Run following steps
ionic cordova platform rm browser/android/ios
ionic cordova run --emulator