idea导入library_如何在IntelliJ IDEA中添加外部库?

在Android项目中尝试将AdMob.jar库添加到/lib目录后,遇到方法显示为红色且无法跳转到声明的问题。已尝试通过复制库文件到lib目录,然后在Project Structure中附加类,但仍然未被识别。解决方案是:将JAR文件复制到app的libs目录,刷新项目,然后右键点击JAR文件选择'Add as Library'。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

bd96500e110b49cbb3cd949968f18be7.png

I am trying to add external library (places it in the /libs directory) to my project. When I try to use the methods from that library, I see that they are in red color which means that the library is not recognized. When I click Ctrl+B, I get a message "Cannot find declaration to go to".

I use these steps to add a library (JAR file):

1. copy the library file into /libs dir

2. open Project Structure -> Global Libraries -> Attach clases

3. find the library and click ok

Is this proper way to do it?

PS. I am trying to add AdMob .jar file this way.

解决方案

Easier procedure on latest versions:

Copy jar to libs directory in the app (you can create the directory it if not there)

Refresh project so libs show up in the structure (right click on project top level, refresh/synchronize)

Expand libs and right click on the jar

Select "Add as Library"

Done

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值