AndroidManifest.xml 详解 (二) 之<application> ——译自《Beginning Android Games》 .

本文详细解析了Android开发中的&lt;application&gt;元素,包括其属性如icon、label和debuggable的作用,以及如何引用资源文件如图片和字符串。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

接上篇~

<application>元素

我们以以下这个例子来讨论<application>元素

<application android:icon="@drawable/icon" android:label="@string/app_name"
android:debuggable="true">
...
</application>

现在看起来可能有点奇怪,@drawable/icon 和 @string/app_name 是什么呢?当我们开发了一个基于android的应用,我们通常用许多XML去定义一些特殊的资源。

我们必须要有能区分这些定义在XML中的资源(比如说图片,国际化字符串)。这些资源储存在res/文件夹下。

我们用先前的标记去索引这些资源。 @指定了我们希望索引在别处的资源。接下来的字符串标记了我们希望索引到的资源类别,并直接映射到res/目录下

资源所在的文件夹或者文件中。最后的部分指定了资源的名字,比如在之前的例子中的图片名字叫icon,字符串的名字叫app_name。这里的图片名字是一个真实的文件名,我们

可以在res/drawable/文件夹下找到。字符串app_name定义在res/values/strings.xml文件里。这个文件里定义的所有字符串将被用在应用中。

NOTE:

在android中,资源处理是一个非常灵活的,同时也是非常复杂的东西。在这本书中,我出于2个原因去放弃使用这种方法。

1、在游戏开发中,这种处理方法对于需要完全控制资源的我们有过度(杀伤力)。

2、Android有一个修改在res/文件夹下资源的习惯,特别是图片(它称为drawables),而这些

修改又不是我们在游戏开发中所希望的。

在游戏开发中我唯一建议使用android的资源系统是——国际化字符串。

我们通常在游戏开发中使用assets/文件夹来储存资源,在此文件夹下我们的资源将不会被做任何修改。

<application>元素的意义想必现在已经非常清楚了。

icon属性指定了用与作为应用图标的图片,图片储存于res/drawable/文件夹下,这个图标将在android market中和

我们的设备上显示,它也所有在<application>元素中定义的activity的默认图标

debuggable属性指定了我们的应用是否能够调试,在开发中,我们通常把它设置为true。当你把应用发布到android market上的时候,就需要把它设置为false。

如果你不把他设置为true,你将不能在Eclipse上调试此应用。

我们仅仅讨论了一小部分你可以指定的<application>元素的子集及其属性,然而这些子集和属性以及足够我们开发游戏所用,如果你希望了解更多的内容,你可以在

Android开发官方文档上找到全部的内容。

<application>元素包涵了所有应用组件的精确定义(包涵activity,services)而且也包涵了任何我们添加的库。

下一个是<activity>~

另附上原文:

The <application> Element
As in the case of the <manifest> element, let’s discuss the <application> element in the
form of an example:


<application android:icon="@drawable/icon" android:label="@string/app_name"
android:debuggable="true">
...
</application>

Now this looks a little bit strange. What’s up with the @drawable/icon and
@string/app_name strings? When developing a standard Android application, we usually
write a lot of XML files, each defining a specific portion of our application. To be able to
fully define those portions, we must also be able to reference resources that are not
defined in the XML file, such as images or internationalized strings. These resources are
located in subfolders of the res/ folder, as discussed in Chapter 2 when we dissected
the Hello World project in Eclipse.


To reference resources, we use the preceding notation. The @ specifies that we want to
reference a resource defined elsewhere. The following string identifies the type of the
resource we want to reference, which directly maps to one of the folders or files in the
res/ directory. The final part specifies the name of the resource—in the preceding case
an image called icon and a string called app_name. In the case of the image, it’s the
actual filename we specify, as found in the res/drawable/ folder. Note that the image
name does not have a suffix like .png or .jpg. Android will infer that automatically based
on what’s in the res/drawable/ folder. The app_name string is defined in the
res/values/strings.xml file, a file where all the strings used by the application will be
stored. The name of the string was defined in the strings.xml file.


NOTE: Resource handling on Android is an extremely flexible but also complex thing. For this
book, I decided to skip most of it for two reasons: it’s utter overkill for game development and we
want to have full control over our resources. Android has the habit of modifying resources placed
in the res/ folder, especially images (called drawables). That’s something we do not want asgame developers. The only thing I‘d suggest using the Android resource system for in game


development is internationalizing strings. We won’t get into that in this book; instead we’ll use
the more game development–friendly assets/ folder, which leaves our resources untouched
and allows us to specify our own folder hierarchy.


The meaning of the attributes of the <application> element should become a bit clearer
now. The icon attribute specifies the image from the res/drawable/ folder to be used as
an icon for the application. This icon will be displayed in the Android Market as well as in
the application launcher on the device. It is also the default icon for all the activities we
define within the <application> element.


The label attribute specifies the string being displayed for our application in the
application launcher. In the preceding example, this references a string in the
res/values/string.xml file, which is what we specified when we created the Android
project in Eclipse. We could also set this to a raw string, such as My Super Awesome
Game. The label is also the default label for all the activities we define in the
<application> element. The label will be shown in their title bar of our application.
The debuggable attribute specifies whether our application can be debugged or not. For
development, we should usually set this to true. When you deploy your application to
the market, just switch it to false. If you don’t set this to true, you won’t be able to
debug the application in Eclipse.

We have only discussed a very small subset of the attributes you can specify for the
<application> element. However, these are sufficient for our game development needs.
If you want to know more, you can find the full documentation on the Android
Developers site.


The <application> element contains the definitions of all the application components,
including activities and services, as well as any additional libraries used.

<think>我们正在处理一个关于Android开发中配置mPaaS框架的QuinoxlessApplication的问题。根据用户查询,需要在AndroidManifest.xml中设置QuinoxlessApplication并添加特定的meta-data。根据引用[1]:AndroidManifest.xmlAndroid应用的核心配置文件,定义了应用的基本信息、组件、权限等。因此,我们在这个文件中配置Application和meta-data。用户提到了两个关键点:1.设置mPaaS提供的QuinoxlessApplication2.添加mpaas.quinoxless.extern.application的meta-data配置在AndroidManifest.xml中,通常我们在<application>标签中设置android:name属性来指定自定义的Application类。对于mPaaS的QuinoxlessApplication,我们应该将其全类名作为android:name的值。另外,meta-data配置通常放在<application>标签内,使用<meta-data>子标签,并指定android:name和android:value。但是,我们需要注意用户提到的meta-data名称为“mpaas.quinoxless.extern.application”,这个meta-data的作用可能是用来指定外部(即用户自定义)的Application类,以便mPaaS框架能够识别并代理。因此,我们可以推测配置步骤:1.在<application>标签的android:name属性中,设置为mPaaS提供的QuinoxlessApplication的全限定名(例如com.mpaas.quinoxless.QuinoxlessApplication)。2.在<application>标签内,添加一个<meta-data>标签,其中android:name属性设置为“mpaas.quinoxless.extern.application”,android:value属性设置为用户自己的Application类的全限定名(如果用户有自定义的Application类的话)。但是,请注意,用户的问题中没有提到他们自己的Application类,所以我们需要明确:如果用户没有自定义Application,可能不需要设置这个meta-data?但根据问题描述,用户明确要求添加这个meta-data配置,所以很可能他们有一个自己的Application类需要被mPaaS框架代理。因此,配置示例:```xml<applicationandroid:name="com.mpaas.quinoxless.QuinoxlessApplication"...其他属性><meta-dataandroid:name="mpaas.quinoxless.extern.application"android:value="com.example.MyCustomApplication"/>...其他组件(Activity等)</application>```这里,我们假设用户的自定义Application类为com.example.MyCustomApplication。注意:mPaaS框架可能会在QuinoxlessApplication中通过这个meta-data获取到用户自定义的Application类,并在适当的时机(如attachBaseContext和onCreate)调用用户Application的方法,以实现代理。引用[2]中展示了一个ProxyApplication(代理Application)的例子,其中通过JNI加载了native库,并重写了attachBaseContext和onCreate方法。这可能是mPaaS框架实现代理Application的一种方式,即通过一个框架提供的Application(QuinoxlessApplication)来代理用户自定义的Application。引用[3]提到了配置CMakeLists.txt或Android.mk来编C++代码,但用户的问题主要是在AndroidManifest.xml中配置,所以暂时不需要考虑。引用[4]与当前问题无关。因此,总结回答:在AndroidManifest.xml中,你需要做以下两步:1.在<application>标签的android:name属性中指定QuinoxlessApplication的全类名。2.在<application>标签内添加一个<meta-data>标签,其中android:name为"mpaas.quinoxless.extern.application",android:value为你自定义的Application类的全类名。这样,mPaaS框架就会使用QuinoxlessApplication来代理你的自定义Application。§§相关问题§§1.为什么mPaaS需要配置QuinoxlessApplication?2.在mPaaS中配置自定义Application时需要注意哪些问题?3.如何验证mPaaS的Application代理配置是否生效?</think>在 AndroidManifest.xml 中配置 mPaaS 的 QuinoxlessApplication 及相关 meta-data 的步骤如下: ### 1. **配置 QuinoxlessApplication** 在 `<application>` 标签的 `android:name` 属性中指定 mPaaS 提供的 `QuinoxlessApplication` 全类名: ```xml <application android:name="com.mpaas.quinoxless.QuinoxlessApplication" ... > <!-- 其他组件 --> </application> ``` ### 2. **添加 meta-data 配置** 在 `<application>` 标签内添加 `mpaas.quinoxless.extern.application` 的 meta-data,指定你的自定义 Application 类: ```xml <application ...> <meta-data android:name="mpaas.quinoxless.extern.application" android:value="com.yourpackage.YourCustomApplication" /> <!-- 其他组件 --> </application> ``` ### 关键配置说明: 1. **QuinoxlessApplication 作用** mPaaS 通过 `QuinoxlessApplication` 代理应用的生命周期,实现框架初始化、热修复等核心功能[^1]。 2. **meta-data 意义** `mpaas.quinoxless.extern.application` 用于声明**用户自定义的 Application 类**: - `android:value` 必须是你的自定义 Application 全类名(如 `com.example.MyApp`) - mPaaS 会代理该类的 `onCreate()` 和 `attachBaseContext()` 方法 - 确保自定义 Application **不继承系统 Application**(直接继承 `Object`) 3. **自定义 Application 示例** ```java public class YourCustomApplication { public void onCreate() { // 你的初始化代码 } public void attachBaseContext(Context base) { // 基础上下文处理 } } ``` ### 注意事项: 1. **代理机制** mPaaS 通过 `QuinoxlessApplication` 动态加载你的自定义 Application,因此**不需要**在代码中显式调用 `super.onCreate()`[^2]。 2. **多进程支持** 若应用使用多进程,需在每个进程的 AndroidManifest.xml 中重复上述配置。 3. **混淆配置** 在 ProGuard 规则中添加保留自定义 Application 类: ``` -keep class com.yourpackage.YourCustomApplication { *; } ``` ### 验证配置: 1. 启动应用时检查 Logcat,搜索 `QuinoxlessApplication` 相关日志 2. 确认自定义 Application 中的初始化代码被执行 3. 使用 APK 分析工具检查 manifest 合并结果 > ⚠️ 注意:若未正确声明 meta-data,会导致 mPaaS 框架无法初始化,引发启动崩溃[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值