简体   繁体   English

一个项目有多个 AndroidManifest.xml 文件?

[英]Multiple AndroidManifest.xml files for one project?

For the past few months, I've been developing an Android app against Cupcake (Android 1.5, API Lvl 3), and everything is working quite well (overall it is a fairly simple app).在过去的几个月里,我一直在开发一个针对 Cupcake 的 Android 应用程序(Android 1.5,API Lvl 3),一切都运行良好(总体而言,它是一个相当简单的应用程序)。

However, recently I noticed there are two things that I would like to do:但是,最近我注意到有两件事我想做:

  1. Restrict permissions to only use Internet (with API Lvl 3, it uses 2 other permissions despite only defining the Internet permission in the manifest xml)限制仅使用 Internet 的权限(API Lvl 3,尽管仅在清单 xml 中定义了 Internet 权限,但它使用了 2 个其他权限)
  2. Let users move the app to SD card/external storage让用户将应用程序移动到 SD 卡/外部存储

Both these changes are really simple - couple of lines in AndroidManifest.xml这两项更改都非常简单 - AndroidManifest.xml中的几行

The solutions I found are:我找到的解决方案是:

  1. To restrict permissions, add: <uses-sdk android:minSdkVersion="4"/> http://developer.android.com/guide/topics/manifest/uses-sdk-element.html To restrict permissions, add: <uses-sdk android:minSdkVersion="4"/> http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
  2. To allow users to move app to SD card, add (to the manifest tag): android:installLocation="auto" http://developer.android.com/guide/topics/manifest/manifest-element.html To allow users to move app to SD card, add (to the manifest tag): android:installLocation="auto" http://developer.android.com/guide/topics/manifest/manifest-element.html

However, solution for #1 requires API Lvl 4 (Android 1.6) and solution for #2 requires API Lvl 8 (Android 2.2)!但是,#1 的解决方案需要 API Lvl 4 (Android 1.6),#2 的解决方案需要 API Lvl 8 (Android 2.2)!

So does it mean that if I want both #1 and #2 as listed above, my app will only be compatible with Android 2.2+?那么这是否意味着如果我想要上面列出的#1 和#2,我的应用程序将只与 Android 2.2+ 兼容?

Or, is there a way to have multiple AndroidManifest.xml files for the one project?或者,有没有办法为一个项目拥有多个 AndroidManifest.xml 文件? (I know the actual code for the app works for Android 1.5 and seems a waste to exclude them simply for a couple of extra lines in the manifest file) (我知道该应用程序的实际代码适用于 Android 1.5,仅在清单文件中添加几行就将它们排除在外似乎是一种浪费)

Thanks!谢谢!

Regarding Move your app to SD card.关于将您的应用程序移至 SD 卡。 It was not before.以前不是这样。 When android 1.5 was introduced there was no such type of concept.在引入 android 1.5 时,还没有这种类型的概念。 It is newer concept for android 1.5 android 1.5 是较新的概念

I donot think you can provide this functionality to android 1.5我认为您无法为 android 1.5 提供此功能

Thanks Deepak谢谢迪帕克

Use Android package renaming in order to have two different packages, ie the same application with different AndroidManifest.xml files in one project.使用 Android package 重命名,以便在一个项目中有两个不同的包,即同一个应用程序具有不同的 AndroidManifest.xml 文件。 See https://stackoverflow.com/a/4426654/1173350请参阅https://stackoverflow.com/a/4426654/1173350

Adding android:installLocation="auto" will not adversely effect backward compatibility -- it will just be ignored by older versions of Android.添加android:installLocation="auto"不会对向后兼容性产生不利影响——它只会被旧版本的 Android 忽略。

Setting <uses-sdk android:minSdkVersion="4"/> will prevent the app from being installed or displayed on the Market on Android 1.5 devices, however.但是,设置<uses-sdk android:minSdkVersion="4"/>将阻止应用程序在 Android 1.5 设备上安装或显示在市场上。 That is its whole purpose.这就是它的全部目的。

If you need to have a different set of permissions for different SDK versions, you would unfortunately need two separate projects and two separate Market listings.如果您需要对不同的 SDK 版本拥有不同的权限集,那么您将需要两个单独的项目和两个单独的市场列表。 You could prevent the Cupcake version of your app from displaying for newer devices by adding android:maxSdkVersion="3" to the <uses-sdk> tag.您可以通过将android:maxSdkVersion="3"添加到<uses-sdk>标记来阻止应用的 Cupcake 版本显示在较新的设备上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM