使用library工程中自定义属性无法识别问题
解决:xmlns:ptr="http://schemas.android.com/apk/res/包名,
改成xmlns:ptr="http://schemas.android.com/apk/res-auto
参照google官方文档试出来的
 
看到这位兄弟解释,借用下给大家参考。
 
http://blog.sina.com.cn/s/blog_ac843e3301017p2t.html
 
 
1.================================================================

在前面我们使用了一个android项目作为一个library,供另外一个项目使用,但是也会出现一些问题,如下:

当project主动引用另外一个android project的时候,出现了一个问题,在当前的project中报了library中的一些错误 :
E:\developtools\workspace\Chejt\res\layout\setting_contents_fragment.xml:62: error: No resource identifier found for attribute 'mode' in package 'com.souchenow.cjt<这是作为library的项目>'
在我们的library项目中确实用到了attribute,即xml自定义属性,在attr.xml中定义了一些属性,但是它不作为一个library的时候就不会报错,而作为一个library的时候却报了错,这是什么原因呢?我通过以下方式解决了问题,在xml中引入这个属性的时候,我们不使用以前的
        xmlns:ptr="http://schemas.android.com/apk/com.shouchenow.main"
这样的形式,而换成了
        xmlns:ptr="http://schemas.android.com/apk/res-auto"
换成了res-auto ,这样问题解决,详细看下链接:
http://stackoverflow.com/questions/10398416/using-activities-from-library-projects
简述:

Issue 9656: Library projects don't support custom XML attributes for custom classes

Solution:

Upgrade to latest SDK & ADT version (fixed was released since r17) and usehttp://schemas.android.com/apk/res-auto as custom attributes' namespace URI, see Revisions for ADT 17.0.0:

Added support for custom views with custom attributes in libraries. Layouts using custom attributes must use the namespace URI http://schemas.android.com/apk/res-auto instead of the URI that includes the app package name. This URI is replaced with the app specific one at build time.

Related Topic:

Help with a custom View attributes inside a Android Library Project

2=======================================================================
我们来看资源打包问题:
自:http://developer.android.com/tools/projects/index.html#TestProjects
When you build an application that depends on a library project, the SDK tools compile the library into a temporary JAR file and uses it in the main project, then uses the result to generate the .apk. In cases where a resource ID is defined in both the application and the library, the tools ensure that the resource declared in the application gets priority and that the resource in the library project is not compiled into the application .apk. This gives your application the flexibility to either use or redefine any resource behaviors or values that are defined in any library.
当我们把一个android project 加上 is library属性的时候,再进行清理之后R文件会出现以下的情况:
拿R.id来举一个例子,在加上属性以前为:
public static final class id {
        public static final int action_settings=0x7f080000;
    }
但是加上属性之后会变成下面的形式:
public static final class id {
        public static int action_settings=0x7f080000;
    }
当加上is library属性之后,在R文件中的final属性就会消失,而不是libary的时候,是会有final属性的,如果变成了libary,我们在使用到R.id.button等的时候,我们就不能把它放在switch中,我们只能把它放在if()else()中,因为switch要求为常量,而if...else...没有这样的要求。
 
我们来看下当一个项目作为一个library引入之后如果资源冲突出现的情况来分析一下:
每个项目中都会有ic_lancher图片,我们就用它来进行一个小小的连接前后的对比:
在链接前:library表示作为库引入的项目,project表示我们将要引入包的那个项目。
library:public static final int ic_launcher=0x7f020000;
project:public static final int ic_launcher=0x7f020000;
链接后:
我们清理项目:
library:public static int ic_launcher=0x7f020000;//final 消失,但是id号没变
project:
library.get.R:public static final int ic_launcher= 0x7f020000;
project.get.R:public static final int ic_launcher=0x7f020000;

Library工程No resource identifier found for attribute的更多相关文章

  1. 解决 Delphi XE5 写Android程序的No resource identifier found for attribute... 错误【转】

    原文:http://www.hxhlb.cn/article/32142aaeb67bbc05379369c3.html 那一天,我装上了RAD Studio XE5. 当天晚上,我就写了一个小小的A ...

  2. No resource identifier found for attribute 'showAsAction' in package 'android'

    运行一个项目时在一个menu.xml文件item属性android:showAsAction 报错 No resource identifier found for attribute 'showAs ...

  3. Android 官网提供的Custom-view 编译出错--error: No resource identifier found for attribute

    error: No resource identifier found for attribute in custom-views from http://developer.android.com ...

  4. res\menu\main.xml:6: error: No resource identifier found for attribute 'showAsAction' in package 'com.xxx.xxxx'

    res\menu\main.xml:6: error: No resource identifier found for attribute 'showAsAction' in package 'co ...

  5. Error:(108) No resource identifier found for attribute 'style' in package 'android'

    Error:(108) No resource identifier found for attribute 'style' in package 'android' 解决方案: 这是错误的写法: a ...

  6. Android调试错误-No resource identifier found for attribute 'showAsAction'

    转载自:http://www.bubuko.com/infodetail-498830.html 1.问题描述: 24\YoumiAndroidSdk\demo\offers\res\menu\mai ...

  7. apktool 回编译报错:No resource identifier found for attribute 'xxxxxx' in package 'android' W:

    C:\xxxx\app-release\res\layout-v26\xxxx.xml:5: error: No resource identifier found for attribute 'xx ...

  8. 自定义view中错误:No resource identifier found for attribute X in package X

  9. Error:(12) No resource identifier found for attribute 'titles' in package 'com.itheima52.mobilesafe5

    http://stackoverflow.com/questions/5819369/error-no-resource-identifier-found-for-attribute-adsize-i ...

随机推荐

  1. Mongdb操作嵌套文档

    1.一个文档如下 db.posts.find() { "_id" : ObjectId("5388162dfc164ee1f39be37f"), "t ...

  2. android小细节

    1.资源包图片尽量控制在50k以内,否则可能读取失败 2.资源图片建议使用png格式,此格式在android系统上支持最好.对于jpeg和gif格式的图片,在android4.0以后版本,通过系统自缩 ...

  3. gitlab和Django实现push自动更新

    1.设置webhook gitlab->setting->webhook:http://121.143.191.166:7000?token=23028-b396-12e5-9912-ba ...

  4. 文件的输出与载入之java操作

    一.前言 学习java没多久,关键是没怎么系统学过.都是看别人的代码来学习的.今天就把一直以来让我头痛的java  IO 的一些基本操作来记录下来,加深记忆. 二.java导入文件到内存中 首先放一个 ...

  5. 搭建基于Windows + Apache + PHP + MySQL的Moodle平台

    说起Moodle,我相信学习教育技术的同学应该都不陌生,在大学的网络与远程教育课中,我有幸与传说中的Moodle相遇,然后相知,但是我绝对不会跟你们说一直到我毕业,我都没有找到一个合适的时间与这位Ms ...

  6. 如何用ASPxTreeView建立三级树(显示及数据绑定)

    示例如图: //设置treeviw默认为第一个菜单打开if (ASPxTreeView1.SelectedNode == null)ASPxTreeView1.SelectedNode = ASPxT ...

  7. ASP.NET 数据库页面访问简单工具

    在工作中,有很多项目已上线后,很多项目的数据库服务器都不会对外开放的,外网想直接访问客户数据库服务器时,可能会出现困难. 这时就需要一个可以查询,更新数据库操作的页面了: 本来用sql语句直接操作数据 ...

  8. 【Framework】深入研究Asp.net页面的生命周期

    介绍 Asp.net是微软.Net战略的一个组成部分.它相对以前的Asp有了很大的发展,引入了许多的新机制.本文就Asp.net页面的生命周期向大家做一个初步的介绍,以期能起到指导大家更好.更灵活地操 ...

  9. javascript之delete操作符

    理解delete 理论 代码段的类型 执行上下文 活动对象 / 变量对象 属性的特性 内置属性与 DontDelete 未声明的赋值 Firebug的困惑 在eval中删除变量 浏览器兼容性 Geck ...

  10. 银行ATM机工作流程模拟编程(代码)

    #include<stdio.h>#include<stdlib.h>#include <conio.h>#include <string.h> voi ...