Android compatibility? API Level? Cordova or Ionic

So I’m working on my first Ionic app for Android. I’ve got it all running via CLI on my Macbook.

I was able to download the Sociogram demo app and start with that. I was able to export the APK and run it on an emulator and my phone. SO far so good…

I sent it to a friend, and he gets “unsupported file”. His Android is 4.1.2, mine is 4.4.2

I assume the reason it’s not working on his is because my environment is using API 19, which his phone doesn’t support.

I know a lot of apps in the store say they work on 2.3.3+ (Gingerbread) which is API 10, so I started to try and get it to work with API 10 and test it.

I’ve read about editing the [uses-sdk] tag here (http://developer.android.com/guide/topics/manifest/uses-sdk-element.html) in the AndroidManifest.xml, and I tried that, but the debug from the “ionic build android” still seems to reference API 19.

I then modified some of the project.properties in both /platforms/android and /platforms/android/CordovaLib but then those throw other errors, some about the “hardware:true” settings in the manifest, and another deeper in the build.xml

Questions:
Am I right about the API being too high for the older phone?
What’s the correct way to change the target API? It seems to have it hard coded in when I run:

] ionic platform add android

I get the following which already has 19 built in… how do I change this? It looks to build the AndroidManifest.xml already around the fact that 19 will be the level, I’m guessing this can be changed before the BUILD command.


sh-3.2# ionic platform add android
Creating android project…
Creating Cordova project for the Android platform:
Path: platforms/android
Package: prg.coenraets.sociogram
Name: myApp
Android target: android-19
Copying template files…
Running: android update project --subprojects --path “platforms/android” --target android-19 --library "CordovaLib"
Resolved location of library project to: /Users/slikk66/Development/Applications/myApp/platforms/android/CordovaLib
Updated and renamed default.properties to project.properties
Updated local.properties

1 Like

So first off, love your avatar :smile:

Now for the serious stuff…

<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />

So this bit of xml does two things, sets the minimum api version for the android app, and sets the target, obviously because of their name.

So api 10 is android 2.3, which we’ve dropped support for. So we can bump that to 14, or android 4.0

Api 19 is 4.4 which is all good.

So these number are part of the default project structure that cordova makes. You could create a hook that after the project is add, it changes the default api level to 14 and 19 instead of manually doing it.

But to change it, go to platforms/android/android.xml, if you edit this, you should be good. Not too sure really why your friend’s device wouldn’t install the app, maybe his phone isn’t setup to allow for apk from unsigned developers?

4 Likes

Hey thanks!

I re-read my post and found the obvious answer staring at me:

] android update project --subprojects --path “platforms/android” --target android-19 --library “CordovaLib”

I changed this to:

] android update project --subprojects --path “platforms/android” --target android-14 --library “CordovaLib”

And then modified the AndroidManifest.xml file as you suggested, now all the debug states level 14 and it compiled. I just sent a copy over to my buddy again… we’ll see if it works!

Thanks for the info, so far loving Ionic <3

2 Likes

by the way, this is undocumented in the Cordova docs, but in your config.xml, if you add the following preference(s), cordova will update your Manifest after prepare (which is run after a platform add or build)

<preference name="android-minSdkVersion" value="14" />
<preference name="android-targetSdkVersion" value="19" /> 

(the target is 19 by default, but change it if you want)

9 Likes

Does this mean we don’t need to take additional steps outlined here:

http://developer.android.com/tools/support-library/index.html

I don’t understand how I can build an app with api level 21 and expect it to run on a 4.1 device.

NOTE: ionic is awesome. Thank you for all you’re doing!

1 Like

I think I get it - if I build an app at API level 21, it will work on a 4.0 device as long as I only use API level 16 functions. API level 21-specific functions will only work on a 5.0 device. So if I want the app to work on both, I would need to use the Support Library somehow.

You define a min-sdk for backward compatibility. So your app will run on a device that has the min-sdk, even though your target is for a specific sdk. You don’t have to do anything manually for this, just define min and target sdk in your config.xml and cordova and android will do the rest!

2 Likes

@slikk66, I am facing the same issue with my ionic application, that’s working fine on all android versions except Jelly Bean(4.1.x, 4.2.x and 4.3.x), even working on lower versions also.

I have no clue here, please help me if you remember how your issue has been resolved, my config file has only minimum sdk version preference, even I tried with target sdk version preference also but not working for me. At least anybody let me know how can I debug this issue.

<preference name="android-minSdkVersion" value="9"/>

This is the preference from my config.xml file.

1 Like

Why those directives are undocumented? should we use those?

1 Like

My previous app on production has target sdk version to 22, Is it possible to decrease 19 now?

I tried to change your settings … I didn’t worked in my case… I got sdk installed on my mac device.

Where you wrote this line in whole ionic project.
in config file it is like this??

<preference name="android-minSdkVersion" value="14"/>
and
<preference name="android-targetSdkVersion" value="23"/>

in ionic is there anything like manifest.xml in which i can define

  • maxSDKVersion

  • targetSdkVersion

minSdkVersion

that is defined in manifest.xml in android

I am trying as well to make my to be compitable with api 8, however, what I understood from different discussion is that Ionic only works for Api 16 and above; but cordova it can works with lower version.
Anyway, I am thinking now if I could only with cordova to make my finished project to be suitable for api 8.
Anyone knows better approch?

As you can see here in ionic docs link, there is also ionic v2 mentioned.

Ionic 1
Ionic V1 is focused on building native/hybrid mobile apps rather than mobile websites.

As such, our browser support tends to be whatever Web View API is available to native apps on a given platform. For Ionic 1x, that means UIWebView for iOS 7+, and Android 4.1 and up. We recommend using Crosswalk to improve performance on older devices.

Ionic 2
Ionic 2 is focused on building both native/hybrid apps through Cordova, as well as adding the ability for Progressive Web Apps and Electron .

The following OSs and browsers are supported:

iOS 8+
Windows 10 Universal App
Android 4.4+
Support can be pushed back to 4.1 if Crosswalk is used with Cordova

2 Likes

hai ,
paltforms/android/app/src/main/androidmanifest.xml

1 Like