在 Android Studio 的 Gradle 项目中添加外部 JAR 文件
我在 Android Studio 中向我的 gradle 项目添加外部 JAR 时遇到了很糟糕的情况.我在这里问了一个类似的问题,但那些答案对我不起作用.
I'm having a terrible time adding an external JAR to my gradle project in Android Studio. I asked a similar question here but those answers haven't worked for me.
我创建了一个 libs
文件夹并在那里添加了我的 JAR:
I created a libs
folder and added my JAR in there:
~/android/MyProject/libs $ pwd
/Users/me/android/MyProject/libs
~/android/MyProject/libs $ ls
TestFlightLib.jar
我在 build.gradle
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
做完这一切后,我点击了Build ->重建
项目,但仍然不允许我添加 import com.testflightapp.lib.TestFlight
After doing all this I clicked Build -> Rebuild
project but that still doesn't let me add import com.testflightapp.lib.TestFlight
我还尝试了第二种解决方案,即右键单击 TestFlightLib.jar
并将其添加为模块.这让我可以成功添加 import com.testflightapp.lib.TestFlight
但是当我 Run
项目时,我仍然收到错误:Gradle: error: package com.testflightapp.lib 不存在
I also tried the second solution of right clicking TestFlightLib.jar
and adding it as a Module. This lets me add import com.testflightapp.lib.TestFlight
successfully but when I Run
the project I still get the error: Gradle: error: package com.testflightapp.lib does not exist
我做错了什么?
如何简单地将外部 JAR 添加到我的 gradle 项目中?
How can I simply add an external JAR to my gradle project?
试试这个:
- 右键单击您的项目
- 选择打开模块设置"
- 点击模块,然后点击依赖项"
- 检查您的文件是否存在于列表中
- 如果没有,请按 + 并将其添加为文件