3

I want to write an app using Android SDK and Eclipse. I installed Android 4 Platform using the SDK Manager, but I'm wondering, will this app work with Android 2 Devices? or only Android 4 Devices?

Thanks.

Hani
  • 105
  • 2
  • 2
  • 11
  • I think what you are to be concern about is the API. "In addition to everything above, Android 4.0 naturally supports all APIs from previous releases" <- taken from http://developer.android.com/about/versions/android-4.0.html – 0gravity Jul 04 '12 at 01:17
  • 1
    @0gravity: but the opposite is of course not true: Android 2 devices *do not* support all API from later releases. – Thilo Jul 04 '12 at 01:21
  • @Thilo yes, and I am glad that you mentioned. – 0gravity Jul 04 '12 at 01:28

3 Answers3

2

It depends on the system calls you make. Always test on devices running different versions, because certain calls only work for certain API levels.

On the sdk website you can see this info.

(See the "Since: API Level 9" on the right part of the grey bar of the getNumberOfCameras fn)

Daniel Smith
  • 8,561
  • 3
  • 35
  • 58
  • 1
    +1. In addition to just the API, there may be other things, like packaging options. The safest way would be to also install the older version of the Android SDK and see if your code works with that, too. – Thilo Jul 04 '12 at 01:23
2

In your App Manifest XML file you must specify the Minimum and Desired Target SDK version. I am developing a App that Target Android 4.0.3 (SDK v15) but must run on 2.3.3 (SDK v10).

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

Off course you have to use only the lower SDK available functions. You should also look the Google Support Library thats make available some new functions for older SDK. http://developer.android.com/tools/extras/support-library.html

// Marcello

mFontolan
  • 194
  • 2
  • 3
  • 1
    Thanks, that really helped. But when I make a new project in Eclipse, should I choose v15 or v10? – Hani Jul 04 '12 at 03:18
  • 1
    Usually you want the targetSdkVersion to be the latest sdk (v15 now), unless there is a specific reason to build with an earlier version. You will then use decorators like @TargetAPI, the support library, or ActionBarSherlock to support previous sdk versions on older systems back to your minSdkVersion. Lint will give you a warning if these two values differ, and this warning is to remind you to be careful about backwards compatibility as I understand it. – dar Jul 04 '12 at 04:04
2

Android Lint is a new tool introduced in ADT r16, which automatically scan and check your project for new API, and show you a nice error mark inside your Eclipse editor.

Rule for checking new API, see here:

NewApi
------
Summary: Finds API accesses to APIs that are not supported in all targeted API
versions

Priority: 6 / 10
Severity: Error
Category: Correctness

This check scans through all the Android API calls in the application and
warns about any calls that are not available on *all* versions targeted by
this application (according to its minimum SDK attribute in the manifest).

If your code is *deliberately* accessing newer APIs, and you have ensured
(e.g. with conditional execution) that this code will only ever be called on a
supported platform, then you can annotate your class or method with the
@TargetApi annotation specifying the local minimum SDK to apply, such
as@TargetApi(11), such that this check considers 11 rather than your manifest
file's minimum SDK as the required API level.

In Eclipse:

enter image description here

yorkw
  • 40,926
  • 10
  • 117
  • 130