如何解决Android的库自定义属性和生成过程中的包名重映射? [英] How to solve Android Libraries custom attributes and package name remapping during build?

查看:512
本文介绍了如何解决Android的库自定义属性和生成过程中的包名重映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着时间的推移我们的Andr​​oid项目已经扩大了很多,这几天我们正在创造来自同一个源代码树的多个品牌的APK。这已成为具有挑战性的,由于包命名Android系统的要求。

Over time our Android project has expanded a great deal, and these days we are creating multiple branded APKs from the same source tree. This has become challenging due to the package naming requirements of Android.

我们有我们所有的共享code在Android库项目,其中包括在主要应用项目。此外,我们有Android的库'覆盖'为获得适用于每个品牌的品牌资源。当我们想打造一个品牌,我们包括该品牌最终包括C的Andr​​oid库的主共享$ C $之前的'叠加'的Andr​​oid库的一些额外的属性。为了说明:

We have all of our shared code in an Android Library project, which is included in the main application project. Plus we have Android library 'overlays' for branded resources that get applied for each brand. When we want to build a brand, we include a few extra properties for that brand that end up including the 'overlay' Android libraries before the main shared code Android Library. To illustrate:

AppProject
  Include: BrandALibrary or BrandBLibrary
  Include: SharedLibrary

SharedLibrary
-> src/..
-> res/..
BrandALibrary
-> res/..
BrandBLibrary
-> res/..

在'BrandALibrary或BrandBLibrary切换在构建时,通过包括.properties文件在构建时使用命令行开关。没什么特别的存在。构建脚本还必须更改.apk文件的包名在构建时使两者的apk文件,可以在同一时间(多为QA目的的特定设备上共存,因为我们不希望客户在同时拥有同时...虽然他们可能)。

The 'BrandALibrary or BrandBLibrary' is switched at build time, by including .properties files at build time using command-line switches. Nothing too fancy there. The build script also must change the package name of the .APK at build time so that the two .APK files can coexist on a given device at the same time (mostly for QA purposes, since we don't expect customers to have both at the same time... though they could).

一切工作得非常好,直到我们的建设添加一个类来我们共同code库项目后的今天爆发。在四处寻找一个原因,这是ocurring我偶然发现了下面的网页,那里的老乡都遇到了同样的问题,并有固定他的版本AAPT的,使这项工作:

Everything was working very well until our build broke today after adding a class to our shared code library project. In looking around for a reason why this is ocurring I stumbled upon the following web page, where the fellow had encountered the same issue and had fixed his version of aapt to make this work:

<一个href="http://devmaze.word$p$pss.com/2011/05/22/the-case-of-android-libraries-and-custom-xml-attributes-part-2/">http://devmaze.word$p$pss.com/2011/05/22/the-case-of-android-libraries-and-custom-xml-attributes-part-2/

在我们的构建,下面的错误psented在日志中$ P $:

During our build, the following errors are presented in the logs:

    -pre-build:

-code-gen:
     [echo] ----------
     [echo] Handling aidl files...
     [aidl] No aidl files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
[renderscript] No renderscript files to compile.
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Found Deleted Target File
     [aapt] Generating resource IDs...
     [aapt] E:\CSI\Neal\trunk\Clients\Android\MyAppSharedLib\res\layout\fancy_layout.xml:22: error: No resource identifier found for attribute 'state_add' in package 'com.myapp'
     [aapt] E:\CSI\Neal\trunk\Clients\Android\MyAppSharedLib\res\layout\fancy_layout.xml:22: error: No resource identifier found for attribute 'state_list' in package 'com.myapp'
     [aapt] E:\CSI\Neal\trunk\Clients\Android\MyAppSharedLib\res\drawable\fancy_button_selector.xml:4: error: No resource identifier found for attribute 'state_add' in package 'com.myapp'
     [aapt] E:\CSI\Neal\trunk\Clients\Android\MyAppSharedLib\res\drawable\fancy_button_selector.xml:4: error: No resource
identifier found for attribute 'state_list' in package 'com.myapp'
     [aapt] E:\CSI\Neal\trunk\Clients\Android\MyAppSharedLib\res\drawable\fancy_button_selector.xml:5: error: No resource
identifier found for attribute 'state_add' in package 'com.myapp'
     [aapt] E:\CSI\Neal\trunk\Clients\Android\MyAppSharedLib\res\drawable\fancy_button_selector_button_selector.xml:5: error: No resource identifier found for attribute 'state_list' in package 'com.myapp'

BUILD FAILED
C:\android-sdk\tools\ant\build.xml:539: The following error occurred while executing this line:
C:\android-sdk\tools\ant\build.xml:568: null returned: 1

我的自定义属性都没什么壮观,我有一个state_add,并state_list定义的,我可以用它来设置默认状态的控制,显示一个按钮,一个图标指示哪个国家应该显示。这就像在一个方式切换按钮,我可能会最终有一个切换按钮而不是替换该控件。

My custom attributes are nothing spectacular, I've got a state_add, and state_list defined that I can use to set the default states for a control that shows a button with an icon that indicates which states should be shown. It's like a 'toggle' button in a way, and I might end up replacing this control with a toggle button instead.

我跟着本教程当我创造了这个按钮

I followed this tutorial when I created this button.

我的问题是,最终(这家伙是长篇大论是不是他?),是有办法,以确保AAPT将重映射在自定义属性中使用的包名。如果我甚至想多写自定义控件到我们的图书馆,我们需要聘任才能够做到以下几点:

My question is, finally (this guy is long winded isn't he?), is there a way to ensure that aapt will 'remap' the package names used in custom attributes. If I even want to write more custom controls into our library, we will need appt to be able to do the following:

  • 如果自定义命名空间是在库项目中定义,重新映射该命名空间为正在建造的Andr​​oid应用程序的命名空间。

我缺少的东西与自定义属性在一个Ant构建映射方式的根本?有什么简单的,我可以做些什么来解决我的构建问题?

Am I missing something fundamental with the way custom attributes are mapped during an Ant build? Is there something simple I can do to fix my build issues?

推荐答案

是解决

例如:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto" >
...

这篇关于如何解决Android的库自定义属性和生成过程中的包名重映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆