I have finished my Ionic 2 App for Android.
For testing I generated my builds with:
cordova build android
These APKs work but the device ready event takes quite a while to fire. No problem.
No I build the productions APK:
cordova build --release android
And the device ready event still happens only after a few seconds. I hoped that this would not be the case in the production version.
ionic run android --prod
This creates a build for debugging and in this build the device ready events fire very fast. But the build is called app-debug.apk.
How can I build a production build that loads fast?
For production (the --prod uses aot which makes load time faster). Also make sure to use ionic middleware instead of cordova
ionic build --release --prod android
To debug in aot:
ionic run android --aot
Related
In ionic 4, how to do a release aka prod build?
The angular part can be build in prod mode by ionic build --prod
Now how to copy this build to android? If I do ionic capacitor run android it will do normal build first and then copy assets to android. But I want to build in prod mode and take assets to android.
(I know how to generate apk in Android studio)
After doing
ionic build --prod
Assuming you have already installed Capacitor, otherwise you can follow this and thereafter,
You can do the following
npx cap copy android
Which copies the built code to android folder.
Then you can do
npx cap open android
Which opens android studio if you havent opened it already, then you should go to Build -> Generate Signed Bundle / APK option and the rest is quite straightforward.
More info can be found here
You can use the simple way.
ionic capacitor build android --prod
after the command, the android studio will open automatic
Development:
android stdio: Build-> Build Bundle(s)/APK(s)->Build APk(s)
Production: android stdio: Build-> Generate Signed Bundle(s)/APK(s)-> Android App Bundle or APk-> release
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
I'm trying to install my ionic app on my android phone. I tried
install my ionic app on my android phone
The app ran on my phone, but when I ran the same command to run a different app, the app was replaced on my mobile. How can I keep both? I don't intend to modify any of these apps, they are ready. I tried these commands as well:
ionic cordova build android --prod --release
and
ionic cordova run android --prod --release
I got this error message:
[ERROR] An error occurred while running cordova run android --release
(exit code 1)
By default, it will overwrite the previous version. You can keep the both app using below way:
Check the config.xml file, and change the id of the app.
<widget id="new.app.id" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
Now, it will be considered as a different app and will not replace the previous one.
I am new to Ionic, recently I developed One app.But my app size was 8mb.
How should I reduce app size,and I am not using any Images and plugins also, but it took 8mb size. please help me.
For production builds you can use ionic cordova build [android/ios] --prod --release. This can reduced the size of your application.
The prod and release flags will minify code and remove debugging utilities.
Documentation: https://ionicframework.com/docs/intro/deploying/#production-builds
You can use one of $ ionic cordova build options
--no-build - Do not invoke an Ionic build
--prod - Build the application for production
--aot - Perform ahead-of-time compilation for this build
--minifyjs - Minify JS for this build
--minifycss - Minify CSS for this build
--optimizejs - Perform JS optimizations for this build
...
For example: ionic cordova build android --prod --aot
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