android项目之间的相互引用出现的问题
2014-12-16 09:25
495 查看
1.================================================================
在前面我们使用了一个android项目作为一个library,供另外一个项目使用,但是也会出现一些问题,如下:
当project主动引用另外一个androidproject的时候,出现了一个问题,在当前的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 简述:
Issue9656: Library projects don't support custom XML attributes forcustom classes
Upgrade to latest SDK & ADT version (fixed wasreleased since r17) and use
attributes' namespace URI, see Revisions forADT 17.0.0:
Added support for custom views with custom attributes in libraries.Layouts using custom attributes must use the namespaceURI http://schemas.android.com/apk/res-auto insteadof the
URI that includes the app package name. This URI is replacedwith the app specific one at build time.
Help with a custom View attributes inside a Android LibraryProject
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 anduses
it in the main project, then uses the result to generatethe
is defined in both the application andthe library, the tools ensure that the resource declared in theapplication gets priority and that the resource in the libraryproject is not compiled into theapplication
gives your application the flexibility to either use orredefine any resource behaviors or values that are defined in anylibrary.
当我们把一个android project 加上 is library属性的时候,再进行清理之后R文件会出现以下的情况:
拿R.id来举一个例子,在加上属性以前为:
public static final class id{
public static
finalint action_settings=0x7f080000;
}
但是加上属性之后会变成下面的形式:
public static final class id{
public static intaction_settings=0x7f080000;
}
当加上islibrary属性之后,在R文件中的final属性就会消失,而不是libary的时候,是会有final属性的,如果变成了libary,我们在使用到R.id.button等的时候,我们就不能把它放在switch中,我们只能把它放在if()else()中,因为switch要求为常量,而if...else...没有这样的要求。
我们来看下当一个项目作为一个library引入之后如果资源冲突出现的情况来分析一下:
每个项目中都会有ic_lancher图片,我们就用它来进行一个小小的连接前后的对比:
在链接前:library表示作为库引入的项目,project表示我们将要引入包的那个项目。
library:public static final intic_launcher=0x7f020000;
project:public static final intic_launcher=0x7f020000;
链接后:
我们清理项目:
library:public static intic_launcher=0x7f020000;//final 消失,但是id号没变
project:
library.get.R:public static finalint ic_launcher=0x7f020000;
project.get.R:public static final intic_launcher=0x7f020000;
在前面我们使用了一个android项目作为一个library,供另外一个项目使用,但是也会出现一些问题,如下:
当project主动引用另外一个androidproject的时候,出现了一个问题,在当前的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 简述:
Issue9656: Library projects don't support custom XML attributes forcustom classes
Solution:
Upgrade to latest SDK & ADT version (fixed wasreleased since r17) and usehttp://schemas.android.com/apk/res-autoascustom
attributes' namespace URI, see Revisions forADT 17.0.0:
Added support for custom views with custom attributes in libraries.Layouts using custom attributes must use the namespaceURI http://schemas.android.com/apk/res-auto insteadof the
URI that includes the app package name. This URI is replacedwith the app specific one at build time.
Related Topic:
Help with a custom View attributes inside a Android LibraryProject2=======================================================================
我们来看资源打包问题:
自: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 anduses
it in the main project, then uses the result to generatethe
.apk.In cases where a resource ID
is defined in both the application andthe library, the tools ensure that the resource declared in theapplication gets priority and that the resource in the libraryproject is not compiled into theapplication
.apk.This
gives your application the flexibility to either use orredefine any resource behaviors or values that are defined in anylibrary.
当我们把一个android project 加上 is library属性的时候,再进行清理之后R文件会出现以下的情况:
拿R.id来举一个例子,在加上属性以前为:
public static final class id{
public static
finalint action_settings=0x7f080000;
}
但是加上属性之后会变成下面的形式:
public static final class id{
public static intaction_settings=0x7f080000;
}
当加上islibrary属性之后,在R文件中的final属性就会消失,而不是libary的时候,是会有final属性的,如果变成了libary,我们在使用到R.id.button等的时候,我们就不能把它放在switch中,我们只能把它放在if()else()中,因为switch要求为常量,而if...else...没有这样的要求。
我们来看下当一个项目作为一个library引入之后如果资源冲突出现的情况来分析一下:
每个项目中都会有ic_lancher图片,我们就用它来进行一个小小的连接前后的对比:
在链接前:library表示作为库引入的项目,project表示我们将要引入包的那个项目。
library:public static final intic_launcher=0x7f020000;
project:public static final intic_launcher=0x7f020000;
链接后:
我们清理项目:
library:public static intic_launcher=0x7f020000;//final 消失,但是id号没变
project:
library.get.R:public static finalint ic_launcher=0x7f020000;
project.get.R:public static final intic_launcher=0x7f020000;
相关文章推荐
- android项目之间的相互引用出现的问题
- android项目之间的相互引用出现的问题
- android项目之间的相互引用出现的问题
- android项目之间的相互引用出现的问题
- android library工程项目之间的相互引用出现的问题
- Android项目导入出现问题解决方案
- Eclipse打包Android项目时用到proguard.cfg后,出现的Warning:can't find referenced class问题的解决方案
- 添加文件【COCOS2DX-LUA 脚本开发之十三】解决lua项目编译Android出现get data from file failed、Cocos2dxActivity cannot be 路径等问题
- eclipse运行android项目时,出现“launching has encountered a problem...”的问题
- Eclipse打包Android项目时用到proguard.cfg后,出现的Warning:can't find referenced class问题的解决方案
- android项目出现红色大感叹号的问题解决方法
- 【COCOS2DX-LUA 脚本开发之十三】解决lua项目编译Android出现get data from file failed、Cocos2dxActivity cannot be 路径等问题 .
- Android中库项目出现java.util.zip.ZipException: error in opening zip file的问题
- 用gradle管理android项目出现的问题以及解决方法
- 关于VS.NET中多个项目的工程相互引用和多个dll引用的问题!
- 【android 反编译】Eclipse打包Android项目时用到proguard.cfg后,出现的Warning:can't find referenced class问题的解决方案
- C++ 基类与派生类之间的相互引用、赋值问题
- android开放平台接入后项目打包中出现的问题
- Android项目导入出现The type java.lang.Object cannot be resolved.问题解决办法!!
- 用gradle管理android项目出现的问题以及解决方法