How do I use the latest Cordova/Ionic2 and target a lower API-level (i.e. 19) on Android?

I am using cordova-android@6.1.2 (latest) and targeting Android. By default, Cordova selects the highest API level (i.e. 25) for compilation. That works. But the apk will not run on lower API-level on my Android emulator.

On the Cordava page ( is instruction on how to compile with lower API-level by setting the environment variable
$ export ORG_GRADLE_PROJECT_cdvCompileSdkVersion=19
I did that and the compile error is:

* What went wrong:
A problem occurred configuring root project ‘android’.
java.lang.NullPointerException (no error message)’

Knowing that the highest API-level is 25, I set
$ export ORG_GRADLE_PROJECT_cdvCompileSdkVersion=25
but I get the same error. The only way to successfully compile through the libraries is to not set any environment variables.

I know I can use an older version of cordova-android by removing the Android platform and
ionic platform add android@4
but this only allows me to go down to API-level 22.
ionic platform add android@3.7
gets me API-level 21.

It looks to me like there is a way to target lower API-level with the latest Cordova release. What did I do wrong?

Ionic2 version is 2.2.1.
Cordova CLI version is 6.5.0.
Android SDK Tools 25.2.5.
Android SDK Platform-tools 25.0.3
Android SDK Build-tools 25.0.2
Build machine - macOS Sierra

keywords: cdvCompileSdkVersion, API-level

I figured out that:

  1. using the latest version of cordova-android, as in
    ionic add platform android
    which is equivalent to
    ionic add platform android@6.1.2"
    does not limit me to running on any API level. The same binaries will run on API level 16-25.

  2. Due to (1) above, there is no need to
    export ORG_GRADLE_PROJECT_cdvCompileSdkVersion=19
    to “down-compile” the API level. Just compile against the latest and greatest API level and it will run on all API level.

  3. Due to (1) above, there is no need to
    ionic platform add android@4
    to use an older version of CLI.

  4. The reason my app does not run on API level 23 and older is because I need to have Crosswalk installed.

1 Like