Platform specific variable for AOT


Is there an AOT variable available for use to detect iOS / Android platform?

Using app.ios / from application module, or using isIOS / isAndroid from platform module fails during AOT compile due to:
'isAndroid is not initialized at tns-core-modules/platform/platform.ts(11,12).

The value is required to be initialized at compile time since it is being used to setup API environment in a static readonly field of a Config class. The iOS / Android use different domain names for local debug, i.e. vs https://localhost.


First, I’m using / .ios or isIOS / isAndroid in may places of my app and still AOT complies as expected. Not sure where / how exactly you are using it in your app, so unsure why it fails.

But if you want to detect the platform at compile time, checkout this line in webpack.config.js

You can use that variable and define any platform specific configurations with define plugin which can be later used in app at run time.


Issue with using env style variables is inability to pass them in dev builds (not using webpack).
I don’t think the flags are sent downstream by a tns run (non-bundle) version.


FWIW, here is a snippet of my Config class:

export class Config {

  public static readonly ENV_CONFIG: EnvConfig = {
    API: (!global.ENV_PROD) ? 
           (isAndroid ? '' : 'https://localhost:1234/') : 


Yes, indeed. But a work around is to have default values in your code. I do something like this, where ENV_NAME is set by WebPack. During dev build it should always take development configuration as there won’t be a value set. You may think of something similar.

   switch (global.ENV_NAME) {
        case "production":
            return ProdConfig;
        case "development":
            return AppConfig;


And webpack is setting global.ENV_PROD to prod


Still looking for an answer for a compile-time variable to determine platform…