2012-03-27 38 views
6

我的问题弹出了一个非常类似的问题,this one。但是接受的答案(单个问题)指向另一个问题,this one,它并不真正回答原始问题。Android构建目标对最终APK有什么影响?

Android的文档状态:

构建目标指定你想使用的Android平台的应用程序 建反对票。

但是这是什么意思呢?

我看到它的方式,我可以有minSdkVersion=4targetSdkVersion=10,但将构建目标设置为API Level 4。会发生什么情况? Eclipse假设我正在开发API Level 4,并且任何方法,常量或者API Levels上面定义的任何东西都不会提供给我。如果我尝试使用它们,应用程序将无法编译。我知道这一点。

但让我换种方式...

比方说,我只设置minSdkVersion=4targetSdkVersion是没有定义。我也不使用任何方法或常量只适用于4级以上的API级别。在这种情况下,真的很重要我选择的构建目标吗?它会对最终APK有什么影响吗?

回答

6

构建目标

构建目标API级别的Eclipse/IntelliJ /您正在使用的任何IDE都在构建。这个 被IDE/build系统简单地用来知道你要提供哪些API 你。如果您对构建API级别14,应用程序仍将 能够在API级别7上运行,提供你不叫那些 不提供API级别任何API 7.

我大多设置生成目标与android:targetSdkVersion相同, 虽然这不是必需的。

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

2

如果您使用更高版本的目标,那么您可以使用反射来编写可用于早期版本的代码。如果你想只限于API 4,那么不要担心构建目标。

对于编译为一个较高的,你可以看看这个问题,当针对早期API级别的例子:

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

+0

这仍然没有真正回答我的问题。 – 2012-03-27 23:58:23

+0

我提到过,如果你只想限制到API 4,那么没有目标是好的,但是如果你选择一个更高的构建目标,并且不使用任何新功能,它可能可以在更高的API上工作,使用这些函数,但因为你没有使用它们,所以没关系。我期望字节码有所不同,以便它可以使用不同的API。 – 2012-03-28 01:23:43

2

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.

当你设置生成目标API级别4,由于Eclipse严格使用API​​级别4,因此Eclipse不会让您编译任何使用高于此级别的方法。但是,如果将构建目标设置为更高的API级别,则在您的API级别10级别中,您的APK可用于手机从API级别4到10.

第二个问题的答案会回答您的问题,即Android构建目标,minSdkVersiontargetSdkVersion都会影响能够使用您的应用程序的用户范围。

编辑:

既然你不会去定义targetSdkVersion和你不使用它上面的API级别4的任何功能,该targetSdkVersion将是一样minSdkVersion。无论您选择何种构建目标,都会自动指定。它并不真正的问题,其建设目标由你挑,除非它低于API级别4

targetSdkVersion Android文档:

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).

+1

这些都不能回答我的问题,因为我的问题不是关于清单参数,而是每个人似乎都关注的问题。我知道他们做了什么以及他们如何工作。这不是我想知道的。 – 2012-03-28 00:01:39

+0

Steve Haley的回答充分说明了它的工作原理并给出了一个例子。社区认为这是第二个问题的正确答案,这正是我所指的。对不起,如果我误导你。 – androidnoob 2012-03-28 00:03:59

+1

Steve Haley的问题完全说明了minSdk/targetSdk属性是如何工作的。但是我的问题**不是**。 – 2012-03-28 00:07:41

相关问题