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

当我手动创建一个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。问题解决,可以正常查看源码。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android Studio中引入第三方C++的步骤如下: 1. 将第三方的源代码放入项目的jni目录下,例如:`/app/src/main/jni/third_party_lib/`。 2. 在项目的`build.gradle`文件中添加以下代码: ```gradle android { // ... defaultConfig { // ... externalNativeBuild { cmake { cppFlags "-std=c++11 -frtti -fexceptions" abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' } } } // ... } // ... externalNativeBuild { cmake { path "CMakeLists.txt" } } ``` 其中,`path`指定了CMakeLists.txt文件的路径,`cppFlags`指定了编译选项,`abiFilters`指定了支持的CPU架构。 3. 在项目的`CMakeLists.txt`文件中添加以下代码: ```cmake add_library(third_party_lib SHARED IMPORTED) set_target_properties(third_party_lib PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/third_party_lib/libthird_party_lib.so) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party_lib/include) ``` 其中,`add_library`指定了的名称,`IMPORTED`表示这是一个外部,`IMPORTED_LOCATION`指定了文件的路径,`include_directories`指定了头文件的路径。 4. 在JNI代码中调用第三方的函数。 ```c++ #include "third_party_lib/include/third_party_lib.h" extern "C" JNIEXPORT jstring JNICALL Java_com_example_myapplication_MainActivity_callThirdPartyLib(JNIEnv* env, jobject /* this */) { ThirdPartyLib thirdPartyLib; std::string result = thirdPartyLib.doSomething(); return env->NewStringUTF(result.c_str()); } ``` 其中,`third_party_lib/include/third_party_lib.h`是第三方的头文件,`ThirdPartyLib`是第三方的类,`doSomething`是第三方的函数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值