-2

I have added a jar file to libs folder. My code is:

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   compile 'com.android.support:appcompat-v7:23.0.1'
 }

But, the editor still errors that the package isn't on right there. I believe, this should be one of the easiest things to do!

Update:

  Error:error reading C:\Users\Downloads\locker\app\libs\my.jar;   error in opening zip file network connection timeout.) <a href="syncProject">Re-download dependencies and sync project (requires network)</a> <a href="syncProject">Re-download dependencies and sync project (requires network)</a> –

I was able to open jar file with winRAR no problem. Why is gradle reporting this as a zip anyway? It appears it cannot open it. What else can I do?

MuayThai
  • 441
  • 1
  • 5
  • 19
  • Did you resync the project? – Thomas R. Oct 15 '15 at 11:43
  • add more information – Abhinav singh Oct 15 '15 at 11:43
  • I did not resync the project. Let me see if there is an obvious resync button ... Resynced. Still shows error. I mean I dont really know for sure what it found or did not find. I just cannot tell via studio. Or I don't know where to look. This was so easy with eclipse. You see what is there and what is not found. – MuayThai Oct 15 '15 at 11:46
  • "What the heck is the answer!" -- generally speaking, don't use JARs. Use artifacts in a repository. Beyond that, though, we would need to know where this `build.gradle` file is (e.g., in `app/` module?), where the `libs/` directory is, what the JAR is, what and where the source is that is generating the build error, etc. "obvious resync button" -- Tools > Android > Sync Project with Gradle Files from the main menu. – CommonsWare Oct 15 '15 at 11:47
  • I don't see a gradle tab ... @Trinimon – MuayThai Oct 15 '15 at 11:48
  • its just standard appName/app/libs is where the jar is located. And I am using in in src/mainjava/com/mycompany/myfile.java – MuayThai Oct 15 '15 at 11:50
  • I mean I don't know what Studio sees and what it does not see. This is very big waste of my time. Yeah I could use artifactory, but this is small project, and I was just tossed a jar file. I mean why make this hard. It should should be simple, easy, and clear! – MuayThai Oct 15 '15 at 11:53
  • In some cases I had to give gradle the exact path to make it work - should be `compile files('libs/library.jar')`. – natario Oct 15 '15 at 11:57
  • No programmer in 2015 should be dealing with this. Absolutely not. What are these people thinking who built studio! This is a joke! – MuayThai Oct 15 '15 at 11:57
  • Error:error reading C:\Users\mypc\Downloads\locker\app\libs\my.jar; error in opening zip file network connection timeout.) Re-download dependencies and sync project (requires network) Re-download dependencies and sync project (requires network) – MuayThai Oct 15 '15 at 12:09
  • 1
    Ok, now it says error in opening zip file? Did not know jar was a zip file. that's good to know. I see its an executable jar? Is perhaps that the reason? Still cannot see its classes but can open using zip opener. – MuayThai Oct 15 '15 at 12:09
  • Unzip your rar file then drag and drop all files into Arduino Studio's suitable area. This will help to you. – Bay Oct 15 '15 at 12:19

1 Answers1

1

You can add Jar files to the "Libs" folder in you project. Create Libs folder if not present. Then, Right - Click the jar file and Click "Add to Library". Will help you.

Surya
  • 628
  • 3
  • 9
  • 26
  • wish I was in eclipse. I'm on Studio, so I cannot Add to Library. Again this is no improvement over eclipse – MuayThai Oct 15 '15 at 11:57
  • Hey, you can do it in Studio also. Create a folder if not present under YourProject > app > Libs. Like that. And it will work. Worked for me. – Surya Oct 15 '15 at 12:03
  • What do you mean click the jar file? Do you mean put it in the libs folder and then click on jar file? or click on it somewhere else? – MuayThai Oct 15 '15 at 12:12
  • Ok, I did that. looks like its finding it but it says cannot open jar file. I notice its an executable jar file. I had no problem opening it with winzip ... – MuayThai Oct 15 '15 at 12:17
  • http://stackoverflow.com/questions/18735923/importing-jar-libraries-into-android-studio.. see here. They have explained where to add dependencies to your build - gradle. – Surya Oct 15 '15 at 13:16