Ionic 4: Issue building for device - ionic-framework

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!

Related

White screen while opening my ionic app in some devices

In few mobiles,my ionic app shows white screen only, when apk build with --prod mode. But the same apk works on other mobiles. If i build without --prod , it is working in all mobiles. i don't have any idea. Please help me out. Thanks in advance.
If you are using android platform version 10.0.0 or higher. Then you have to remove whitelist plugin, if it is installed in your project.
It doesn't work with android 10 or later. This is the reason it shows white screen after opening installed application.
cordova plugin rm cordova-plugin-whitelist
cordova prepare OR ionic cordova prepare
if prepare doesn't work try to remove platform and add again.
ionic cordova platform rm android
ionic cordova platform add android
Thanks, Hope it helps you.

Issue when I use ionic cordova run android

I am getting an issue when I try to run with command line
ionic cordova run android
The error that it diplays is this one:
ERR_NO_TARGET: No targets devices/emulators available. Cannot create AVD because there is no suitable API installation. Use --sdk-info to reveal missing packages and other issues.
But the thing is that I created a device in the Android Studio:
so I wonder what could the problem be? Thanks
You need to launch the emulator and keep it running before executing the command ionic cordova run android
Click on the Play icon in the Virtual Devices list to launch the emulator.
Might not be the answer you're looking for but generally, I use:ionic cordova build android
Then open the platform/android directory in Android Studio.
Maybe you should try this :
for see avaliables devices this:
ionic cordova run android --list
for run android app on device this:
ionic cordova run android --device --verbose
i hope help you.
Make sure you have the following variables set in your environment.
export ANDROID_HOME=$HOME/Library/Android/sdk
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export ANDROID_AVD_HOME=$HOME/.android/avd

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.

How to update my apk every time I make changes on my template or code changes?

How to update my apk every time I make changes on my template or code changes.
You can use the livereload feature of ionic cordova emulate or ionic cordova run to run the code on an emulator or device and see the changes live as as you code.
Here's how with the emulator:
ionic cordova emulate android --list to get a list of available emulator targets to copy into the next command.
ionic cordova emulate --livereload android -- --target="[TARGET]"
See the CLI docs for more info.
You can do livereload from a ionic cordova run <platform>, if it's an apk i assume that is for android so you can do this:
ionic cordova run android --livereload
For more options like specific port you can take a look on the docs

Ionic3 splash screen and icon - No platfrom detected

Let me first say. Each time i run
ionic cordova build android --dev
It first run this command
cordova platform add android
At the start of the project I already added the android platform successfully. So I dont know why on every build it has to add android platform again. But each build works perfectly well on my phone. Then yesterday when I tried to run
ionic cordova resources
and it says
no platform detected. Please run ionic cordova platfrom add
Please help