AndroidManifest.xml 中的 Android 兼容性设置
我有一个应用程序要发布,它适用于所有 Android 屏幕尺寸(较小的除外)和高于 SDK 版本 2.0 的密度。
它还将在超大屏幕上运行。 目前我已经添加了这个:
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="false"
android:anyDensity="true"
/>
但我还需要添加 android:xlargeScreens="true"
,以允许它在超大屏幕设备上的 android 市场中可见,因为默认情况下它是 false。
但是要添加 android:xlargeScreens
我需要将 eclipse targetsettings 更改为 2.3,因为此属性是从 API 级别 9 添加的。
那么对于这种情况,我应该如何处理我的目标编译设置呢?编译时应该是2.3吗?如果是,那么该应用程序在 2.0 版本的设备上运行时不会出现任何问题吗?
I have an app to release which works on all android screen-sizes (except smaller) and densities above SDK version 2.0.
It will also run on extra large screens.
Currently I have added this:
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="false"
android:anyDensity="true"
/>
But I also need to add android:xlargeScreens="true"
, to allow it visible in android market on extra large screen devices, since by default it is false.
But to add android:xlargeScreens
I need to change my eclipse targetsettings to 2.3 as this attribute was added from API level 9.
So what should I do with my target compilation settings for this scenario ? Should it be 2.3 while compiling ? If yes, then will the app not give any problems while running on devices with 2.0 version ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
是的,您需要将使用的 sdk 更改为 2.3,但请确保您没有使用 2.0 以外的任何较新的 api,或者您支持的最低 sdk 版本是什么。或者如果你想使用它们,你必须使用反射。
但是更多关于如何使用sdk版本的信息在这里和有关uses-sdk的更多信息在这里。
我在我的应用程序中做了同样的事情,并确保在发布之前在两个[所有]版本中测试您的应用程序。
最好的,
阿奇。
Yes you need to change the uses sdk to 2.3 but make sure that you are not using any newer apis which are not in 2.0 or whatever your minimum supported sdk version is. Or in case you want to use them you have to use reflection.
But more about how to use the sdk versions is here and more about uses-sdk is here.
I do the same in my application and make sure you test your application in both[all] the versions before you release.
Best,
Achie.
我将其从评论中移走,以便其他人将来查看这个问题时更加清楚。
当同时支持新旧版本的 Android 时,尽管在每个新版本中框架中发生了许多变化,但应用程序如何管理运行可能会令人困惑,我将在这里尝试澄清这一点。
为 1.5 sdk 编写的应用程序只能调用该 API 级别存在的函数,因此,例如多点触控 api 在 1.5 中不存在,也永远不会存在。现在你说“好吧,但我不需要调用任何更新的 API,我只想让我的应用程序在 2.3 中工作并支持 a2sd”,我说“好吧,只需在清单中更改你的 targetApi,设置 minSDK 并编译反对 2.3,你就可以开始了。”
现在为什么会这样呢?如果
ListView
的 onMeasure() 方法在 2.2 中发生更改,现在在 onMeasure() 中调用 betterCalculateFunction() 会怎么样?为什么我的应用程序仍然可以运行?这就是Java中后期绑定的优点。您会看到,Java 在到达设备并运行之前永远不会被编译,您在 Eclipse 中所做的就是将其转换为字节代码,其中包含一堆字节代码指令,稍后由设备解释。不过,字节码永远不会包含对 betterCalculateFunction() 的引用(除非您直接调用它。调用 onMeasure() 是间接的)。发生这种情况的原因是,当您的代码在设备上运行时,它会链接到设备上的 Android 框架,并且您的代码直接调用 onMeasure(),因为它是公共的向外 API。然后执行路径将进入框架并调用它需要的任何内容,然后一旦完成就返回到您的代码。
现在,如果您需要调用根据 API 级别可能存在或可能不存在的函数,那么我建议您在这里查看我的相关答案 stackoverflow:优雅地降级您的应用
希望能清除一些事情向上。
I'm moving this from the comments to make it more clear for others looking at this question in the future.
When supporting both old and new versions of Android it can be confusing how applications manage to run despite many things change with in the frameworks during each new release, I'm going to try and clarify this here.
An application written for the 1.5 sdk can only call functions that exist for that API level, so for instance the multi touch api's didn't exist in 1.5 and never will. Now you say "Ok but I don't need to call any newer APIs, I just want my app to work in 2.3 and have a2sd support" And I say "Ok, just change your targetApi in the manifest, set the minSDK and compile against 2.3 and you're good to go."
Now why does that work? What if the onMeasure() method for
ListView
was changed in 2.2 and now calls betterCalculateFunction() within onMeasure()? Why does my app still work?This is the advantage of late binding in Java. You see, Java is never compiled until it reaches a device and is running, what you are doing in Eclipse is converting it to byte code which contains a bunch of byte code instructions that are later interpreted by the device. The byte code will NEVER contain a reference to betterCalculateFunction() though (unless you directly call it. Calling onMeasure() is indirect). This can happen because when your code is running on the device it gets linked against the Android framework on the device and your code calls onMeasure() directly because it is a public outward facing API. The path of execution will then enter the framework and call whatever it needs to, then once its done return to your code.
Now if you need to call functions that may or may not exist depending on API level then I suggest you look at a related answer of mine here stackoverflow: gracefully downgrade your app
Hope that clears some things up.
我没试过2.3,但我用2.2就是这么做的。
我针对 2.2 进行编译并在 1.6 上进行测试,以确保一切都按我的预期工作。我还没有遇到任何问题。
要仔细检查,请将目标设置为 2.3,然后为较低版本设置模拟器,以确保一切正常。
I haven't tried 2.3, but that's what I do with 2.2.
I compile for 2.2 and test on 1.6 to make sure everything works how I'm expecting. I haven't run in to any issues with it.
To double check, set your target for 2.3 and then setup an emulator for a lower rev version to make sure it all works.
android:xlargeScreens 的默认值为 true,因此您无需更改任何内容 - 只要您的 minSdkVersion 或 targetSdkVersion 高于 4,它就会默认启用。
http://developer.android.com/guide/topics/manifest /supports-screens-element.html
The default value for android:xlargeScreens is true, so you don't have to change anything - it's on by default, as long as your minSdkVersion or targetSdkVersion is higher than 4.
http://developer.android.com/guide/topics/manifest/supports-screens-element.html
以下是官方 Android 开发者博客对其工作原理的解释:
http:// /android-developers.blogspot.com/2010/07/how-to-have-your-cupcake-and-eat-it-too.html
总之:您可以使用最新的 XML,同时仍然支持旧版本以向后兼容方式的操作系统版本。
Here is an official Android developer blog explanation of how this works:
http://android-developers.blogspot.com/2010/07/how-to-have-your-cupcake-and-eat-it-too.html
In summary: you can use the newest XML whilst still supporting the older OS versions in a back compatible way.
在阅读这篇博客文章时,我想我有一个答案关于我的老问题。下面摘录(适用于 3.2 中引入的另一个清单属性“requiresSmallestWidthDp”):
“问题是您必须针对 Android 3.2 或更高版本编译应用程序才能使用 requireSmallestWidthDp 属性。旧版本不理解此属性,并且会引发编译时错误。最安全的做法是针对与您为 minSdkVersion 设置的 API 级别相匹配的平台来开发应用程序。当您为构建候选版本做最后准备时,请将构建目标更改为。 Android 3.2 并添加了 requireSmallestWidthDp 属性。早于 3.2 的 Android 版本会忽略该 XML 属性,因此不存在运行时失败的风险。”
While reading this blog post I guess I have an answer on my old question. An extract below (which is for another manifest attribute "requiresSmallestWidthDp" introduced from 3.2):
"The catch is that you must compile your application against Android 3.2 or higher in order to use the requiresSmallestWidthDp attribute. Older versions don’t understand this attribute and will raise a compile-time error. The safest thing to do is develop your app against the platform that matches the API level you’ve set for minSdkVersion. When you’re making final preparations to build your release candidate, change the build target to Android 3.2 and add the requiresSmallestWidthDp attribute. Android versions older than 3.2 simply ignore that XML attribute, so there’s no risk of a runtime failure."
对于不同的屏幕,您必须创建多个 apk,然后它会减少应用程序的大小。在每个应用程序的清单中,您必须根据以下链接进行定义。
http://developer.android.com/guide/practices/screens-distribution.html
For different screens you have to create multiple apk then it reduces size of your application.In each application's manifest you have to define according to following link.
http://developer.android.com/guide/practices/screens-distribution.html