您的位置:首页 > 移动开发 > Android开发

android引入外部项目点击不能查看源码问题

2014-12-11 13:52 543 查看
当我手动创建一个Android项目(暂且叫项目A),然后由另外一个项目(暂且叫项目B)引用这个项目的时候,在项目B中使用了项目A的类时,此时使用ctrl+鼠标左键是可以定位到项目A的源码的。

但是当我再复制一个项目A(复制的项目叫做项目C),由项目B引用项目C的时候,在项目B中使用了项目C的类时,此时使用ctrl+鼠标左键是不能找到源码的,这个问题很奇怪,纠结了好久,终于找到答案了,现在观察一下项目A的.classpath文件

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path=".apt_generated">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

再来看看复制出来的项目C的.classpath文件
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path=".apt_generated">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

发现除了位置之外,其他的好像没什么区别,于是将项目C也换成项目A这样的位置顺序,clean项目一下,然后再看,果然可以关联了。
查看被依赖工程的class path 文件,发现如果某个工程可以debug,那么<classpathentry kind="src" path="src"/> 一定在<classpathentry kind="src" path="src_gen"/> 的前面,因此修改这两个配置属性的位置,将<classpathentry
kind="src" path="src"/>放在class path 属性列表的最上边,保存并clean工程,重新debug。问题解决,可以正常查看源码。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ANDROID