rfgamaral
rfgamaral

Reputation: 16842

What impact does the Android build target have on the final APK?

My question popped up a very similar question, this one. But the accepted answer (the single one) points to another question, this one, which doesn't really answer the original question.

The Android documentation states:

The Build Target specifies which Android platform you'd like your application built against.

But what does it mean really?

The way I see it, I can have the minSdkVersion=4 and targetSdkVersion=10 but set the build target to API Level 4. What will happen? Eclipse assumes I'm developing for API Level 4 and any method, constant or whatever defined on API Levels above 4 will not be available to me. If I try to use them, the application will not compile. I'm aware of this.

But let me put it differently...

Let's say I have only set minSdkVersion=4, targetSdkVersion is not defined. I am also not using any method or constant only available on API Levels above 4. In this situation, does it really matter the build target I pick? Will it have any impact in the final APK?

Upvotes: 6

Views: 4246

Answers (3)

rfgamaral
rfgamaral

Reputation: 16842

Build target

Build target is the API level Eclipse/IntelliJ/whatever IDE you’re using is building against. This is simply used by the IDE/build system to know which APIs to offer you. If you build against API level 14, the application will still be able to run on API level 7, providing you don’t call any APIs that are not available on API level 7.

I mostly set the build target to the same as android:targetSdkVersion, though this is not required.

Source: http://simonvt.net/2012/02/07/what-api-level-should-i-target/

Upvotes: 6

Zerhinne
Zerhinne

Reputation: 2057

The way I see it, I can have the minSdkVersion=4 and targetSdkVersion=10 but set the build target to API Level 4. What will happen? Eclipse assumes I'm developing for API Level 4 and any method, constant or whatever defined on API Levels above 4 will not be available to me. If I try to use them, the application will not compile.

When you set the build target to API level 4, Eclipse will not let you compile any methods you use higher than that, because it strictly uses API level 4. However, when you put the build target to a higher API level, in your case API level 10, your APK is available for use for phones from API level 4 to 10.

The 2nd question's answer answers your question, that is the Android build target, both minSdkVersion and targetSdkVersion affects the range of users that are able to use your application.

EDIT:

Since you're not going to define targetSdkVersion and you're not using any features which is above API level 4, the targetSdkVersion will be the same as minSdkVersion. Whatever build target your chose will automatically be specified. It doesn't really matter which build target you pick unless it is below API level 4

From Android documentation of targetSdkVersion:

An integer designating the API Level that the application targets. If not set, the default value equals that given to minSdkVersion. This attribute informs the system that you have tested against the target version and the system should not enable any compatibility behaviors to maintain your app's forward-compatibility with the target version. The application is still able to run on older versions (down to minSdkVersion).

Upvotes: 2

James Black
James Black

Reputation: 41858

If you use a higher build target then you can write code that will work on earlier versions by using reflection, for example. If you want to be restricted to just API 4 then don't worry about the build target.

For an example of targeting earlier api levels when compiling for a higher one you can look at this question:

Android: how to code depending on the version of the API?

Upvotes: 2

Related Questions