简体   繁体   English

将JAR导入Android Studio 2.2

[英]Importing a JAR into Android Studio 2.2

I'm trying to import a JAR that I made in Groovy into an Android Studio 2.2 project and all the instructions I can find say to just add it under Project Structure -> app -> Dependencies. 我试图将我在Groovy中制作的JAR导入到Android Studio 2.2项目中,我可以找到的所有说明都只是将其添加到Project Structure-> app-> Dependencies下。 I did this and it's still not letting me use the imported JAR. 我这样做了,但仍然不允许我使用导入的JAR。 I've imported JAR files from Groovy into other Java projects in Eclipse. 我已经从Groovy将JAR文件导入到Eclipse中的其他Java项目中。 Did something change in Android Studio 2.2 that changes how you're supposed to do this? Android Studio 2.2中的某些更改是否改变了您的操作方式?

在此处输入图片说明

I thinnk this step help You 我这一步帮助你

1 ) Put the jar (in my case, yourJar-2.2.4.jar) into the libs folder. 1)将jar(在我的情况下为yourJar-2.2.4.jar)放入libs文件夹。

2) Right click it and hit 'Add as library'. 2)右键单击它,然后单击“添加为库”。

3) Ensure that compile files('libs/yourJar-2.2.4.jar') is in your build.gradle file (or compile fileTree(dir: 'libs', include: '*.jar') if you are using many jar files). 3)确保编译文件('libs / yourJar-2.2.4.jar')在build.gradle文件中(或者如果您正在使用许多文件,则编译fileTree(dir:'libs',include:'* .jar') jar文件)。

4) Do a clean build (you can probably do this fine in Android Studio, but to make sure I navigated in a terminal to the root folder of my app and typed gradlew clean. I'm on Mac OS X, the command might be different on your system. 4)做一个干净的构建(您可以在Android Studio中做得很好,但是要确保我在终端中导航到应用程序的根文件夹并键入gradlew clean。在Mac OS X上,命令可能是在您的系统上有所不同。

5) Clean Project. 5)清洁项目。

6) Run. 6)跑。

May be it,s Working 可能是它的工作

I figured it out but I'm still not sure why it works. 我知道了,但是我仍然不确定为什么会起作用。 I changed the package name of the JAR to match the Android project. 我更改了JAR的程序包名称以匹配Android项目。 My Android project is com.johnwstanford.simplegps and I originally just called the JAR package SimpleGpsOutputFormatter. 我的Android项目是com.johnwstanford.simplegps,我最初只是将JAR包称为SimpleGpsOutputFormatter。 I changed it to com.johnwstanford.simplegps.SimpleGpsOutputFormatter and for some reason, that made it work. 我将其更改为com.johnwstanford.simplegps.SimpleGpsOutputFormatter,由于某种原因,它可以正常工作。 Anyone know why that would make a difference? 有人知道为什么会有所作为吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM