Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 209
rfgamaral Avatar asked Mar 27 '12 23:03

rfgamaral


2 Answers

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/

like image 121
rfgamaral Avatar answered Sep 19 '22 00:09

rfgamaral


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?

like image 42
James Black Avatar answered Sep 21 '22 00:09

James Black