从AAR在XML中找不到资源标识符 [英] Can't find resource identifiers from AAR in XML

查看:4512
本文介绍了从AAR在XML中找不到资源标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个应用程序自定义preference。它有两个自定义属性。我试图在preference移动到库项目在其他项目中重复使用。我与相应的布局和ATTR XML文件一起移动Java文件。下面是该库项目的ATTR文件:

I developed a custom Preference for an application. It has two custom attributes. I'm trying to move the Preference to a library project to reuse in other projects. I moved the Java file along with the corresponding layout and attr XML files. Here's the attr file in the library project:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="NumberPickerPreference" >
        <attr name="minValue" format="integer" />
        <attr name="maxValue" format="integer" />
    </declare-styleable>
</resources>

下面是清单:

<manifest package="com.mydomain.androiduilibrary">
</manifest>

这是古怪的清单是肯定的。当我生成库项目把唯一的Andr​​oid工作室清单是SDK的信息,然后生成一个关于它已经在的build.gradle文件中所指定的警告,所以我删除清单中的项目。

An odd-looking manifest for sure. When I generated the library project the only thing Android Studio put in the manifest was the SDK info, which then generated a warning about it already being specified in the build.gradle file, so I deleted the entry in the manifest.

我生成使用bundleRelease任务AAR文件,获取androiduilibrary-release.aar文件命名。然后我去需要使用此preference,选择新建模块|导入.jar或.AAR包项目,导航到AAR,它现在在我的项目作为题为androiduilibrary释放模块。我做一个模块依赖于项目结构对话框中,现在还引用Java code中的preference。到目前为止,一切都很好。

I generate the AAR file using the bundleRelease task and get a file named androiduilibrary-release.aar. I then go to the project that needs to use this Preference and select "New Module | Import .JAR or .AAR Package", navigate to the AAR, and it's now in my project as a module entitled androiduilibrary-release. I make a module dependency in the Project Structure dialog, and can now reference the Preference in Java code. So far, so good.

然而,当我试图引用preference在XML中,我得到我的自定义下列错误属性:错误:(9)未找到属性minValue(最小值)封装com.mydomain资源标识符。 androiduilibrary'。这里的XML:

However, when I attempt to reference the Preference in XML, I get the following error on my custom attributes: "Error:(9) No resource identifier found for attribute 'minValue' in package 'com.mydomain.androiduilibrary'". Here's the XML:

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:title="@string/location_service_settings_preference_header_title"
    xmlns:custom="http://schemas.android.com/apk/res/com.mydomain.androiduilibrary">

<com.mydomain.androiduilibrary.NumberPickerPreference
    android:title="@string/update_interval_preference_title"
    android:key="@string/update_interval_preference_key"
    android:defaultValue="@integer/update_interval_preference_default"
    android:summary="@string/update_interval_preference_summary"
    custom:minValue="@integer/update_interval_preference_min"
    custom:maxValue="@integer/update_interval_preference_max"
    android:dialogMessage="@string/update_interval_preference_dialog_message"
    android:dialogTitle="@string/update_interval_preference_title" />

我可以看看AAR里面看到值在R.txt填充:

I can look inside the AAR and see that the values are populating in R.txt:

int attr maxValue 0x7f010001
int attr minValue 0x7f010000

和正在被正确地创建其清单:

And that its manifest is being created correctly:

<?xml version="1.0" encoding="UTF-8"?>

<manifest android:versionName="1.0" android:versionCode="1"
    xmlns:android="http://schemas.android.com/apk/res/android" package="com.mydomain.androiduilibrary">

    <uses-sdk android:targetSdkVersion="21" android:minSdkVersion="11"/>

</manifest>

我召唤出定制preference时也得到了警告:元素com.mydomain.androiduilibrary.NumberPicker preference在这里不允许所以我猜测,这将是一个问题太

I also get a warning when calling out the custom preference: "Element com.mydomain.androiduilibrary.NumberPickerPreference is not allowed here" so I'm guessing that will be a problem too.

有没有一步我失踪,让我引用来自AAR的元素在我的XML?我使用的Andr​​oid 1.0.2工作室。先谢谢了。

Is there a step I'm missing that will allow me to reference elements from the AAR in my XML? I'm using Android Studio 1.0.2. Thanks in advance.

推荐答案

从的这个后,倒在它谈到外部库底。从本质上讲,在$ C $引用AAR元素。当C则可利用在AAR的清单中指定的包,但在XML中引用AAR元素时,你举的项目(不是AAR)的命名空间。

Solved it from this post, down at the bottom where it talks about external libraries. Essentially, when referencing AAR elements in code you do so using the package specified in the AAR's manifest, but when referencing AAR elements in XML you cite the namespace of the project (not the AAR).

这篇关于从AAR在XML中找不到资源标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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