Search code examples
androidcordovaionic2phonegap

Add specific android version


I'm trying to add a specific android platform.

Now all answers to these same questions look approximately the same:

Add <preference name="android-targetSdkVersion" value="XX" /> to your config.xml

So, I tried:

  • Adding that line to my config.xml where XX = 23
  • cordova platform remove android --save
  • ionic cordova platform add android --save

My output shows me:

Using cordova-fetch for cordova-android@~6.2.2
Adding android project...
Creating Cordova project for the Android platform:
        Path: platforms\android
        Package: com.ionicframework.someapp
        Name: MyApp
        Activity: MainActivity
        Android target: android-25

This looks like it's using android-25.

My myapp/platforms/android/AppManifest.xml looks like this:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.ionicframework.someapp" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
        </provider>
    </application>

    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

But my platforms/android/project.properties just shows target=android-25

So. How can I configure my android version to use android-23, eventually manually if there's no straight answer.

(I had this issue before and I believe I resolved it back then by reverting to a 5.X.X build of cordova. New requirements make that kind of impossible this time)


Solution

  • I'm not sure if this is exactly what you're looking for, but this might help. If you are trying to only use a certain API level / android version, you can use the command on cli:

    cordova platform add android@[cordova android version]
    
    ie: cordova platform add [email protected]
    

    You can check out the documentation on which versions of cordova android support which API level.

    Note:

    Please note that the versions listed here are for Cordova's Android package, cordova-android, and not for the Cordova CLI. To determine what version of Cordova's Android package is installed in your Cordova project, run the command cordova platform ls in the directory that holds your project.