Ionic build with capacitor uses without the --prod option

When building my app with the option: ionic cap build android (not for production) and running it from Android Studio, it still replaces the environment.ts with values.

These is my code:


export const environment = {
  production: false,
  login: false,

export const environment = {
  production: true,
  login: true,
  agrotiUser: 'semaren'

The service imports it as:
import { environment } from 'src/environments/environment';

Instead of, it works well when I run the app with: ionic cap run android -l --external

Why can it be possible?

1 Like

ionic cap build android defaults to prod from my experience whereas using livereload defaults to dev. When I need a dev build when it defaults to prod, I build in dev using whatever JS tooling you are using (Vite, Webpack, etc.) and then use the --no-build option.

ionic cap build android --no-build
ionic cap sync android --no-build

Yes, as you said, i’m trying to do a dev build but without a livereload. I’ve tried that two commands you suggested but I still get a prod build.

By the way, that first sentence with build and --no-build it’s really confusing.

Did I explain myself right?

1 Like

First, ionic cap build android and ionic cap sync android are pretty much the same commands from what I can see. The only difference is that ionic cap build android opens Android Studio.

When you run either of those commands, there are two things going on. First, it builds your JS assets and second it copies those assets over to the Android project and configures/updates any Capacitor/Cordova plugins. To skip the first step of building your JS assets, you use the --no-build option.

With that, you want to build your JS assets with a dev build yourself. Once you do that, then you want to sync those assets with your Android project without re-building your JS assets using the --no-build option so the dev build is synced and not a prod build.

What framework/tooling are you using with Ionic?

1 Like

Well, finally I understood it! I’m using Angular framework. So I executed:

ng build --configuration development
ionic cap sync  android --no-build

I believe something has changed from previous versions of Ionic, because that wasn’t needed before.

Thanks again for your help!

1 Like

I went in the same situations as op and the solution for me was simply change in angular.json file the build section defaultConfiguration parameter from production to development


This is helpful, the command now build the files using staging environments. To build in production mode, just add --prod to the command

1 Like