1

I have 2 libraries:

  1. chilkat-9.5.0-android-all
  2. simple-file-chooser-master

I have copied both into libs folder and used it as libs. When I try to import these libs into my java class I got red markup on their names. It means that android studio can't find thees libs. Anyway i had add file chooser as project to my main application. But when I 'Run' my app firstly I've got compiled file chooser not my main app.

So my main question is how to add .zip or .jar files as LIBRARIES not as project or module.

I will share these libraries download links:

  1. https://www.chilkatsoft.com/chilkatAndroid.asp

  2. https://github.com/ingyesid/simple-file-chooser

I know that this is not programming question but still useful for many people who started to use android studio after eclipse.

Rokas Devolskis
  • 61
  • 1
  • 10
  • Native libraries (`*.so`, here the ones from Chilkat) belong in `jniLibs` instead of `libs` and need no extra specification. Do it like [this](http://stackoverflow.com/questions/28940743/ndk-support-in-androidstudio-and-choosing-between-android-studio-and-eclipse/28943840#28943840). – Eugen Pechanec May 01 '15 at 17:37
  • @EugenPechanec thank you. Chilkat library problem solved. But what i need to do for file chooser library? This library is created as android project.. maybe i need to implement all .java files, .xml drawable and etc to my project, and use it as my own created? – Rokas Devolskis May 01 '15 at 18:01
  • @EugenPechanec ooops sorry dude. This doesn't helped me. Few seconds i thought that it helped bud now again `import com.chilkatsoft.CkZip;` chilkatsoft goes red, and other text grey.. :( – Rokas Devolskis May 01 '15 at 18:06
  • **Chilkat** Also copy whatever is in the archive in `src` to your `java/src`. **File Chooser** Either import it as a library module or look for an alternative that's available via maven central (or jcenter). – Eugen Pechanec May 01 '15 at 18:21
  • @EugenPechanec I look at my src/com and there were all java files from chilkat library. Still doesn't work :) – Rokas Devolskis May 01 '15 at 18:29
  • Maintain the file hierarchy that was in the chilkat archive. They're supposed to be in `./com/chilkat/*.java` – Eugen Pechanec May 01 '15 at 18:31

2 Answers2

0

I implemented a .jar library today in my project and did the following:

  1. add the .jar file to the libs folder of your project

  2. in the build.gradle file add: compile fileTree(dir: 'libs', include: ['*.jar']) to the dependencies.

  3. Build your project

  4. now try to import the objects in your class :)

like this: dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) }

other thing you can try is: right mouse click on your .jar in Android Studio and select "make module". - and build again.

Dennis Anderson
  • 1,348
  • 2
  • 14
  • 33
  • i have code like this in my build.gradle .. so i did it already :) `dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.0.0' compile project(':fileChooserActivity') compile files('libs/sshj-master.jar') compile files('libs/simple-file-chooser-master.jar') compile files('libs/chilkat-9.5.0-android-all.jar') }` – Rokas Devolskis May 01 '15 at 17:50
  • compile fileTree(dir: 'libs', include: ['*.jar']) is enough, you dont need to insert the libs seperatly that are in your folder like compile files('libs/chilkat-9.5.0-android-all.jar'). With that line i gave you EVERY .jar file will be compiled in the libs folder – Dennis Anderson May 01 '15 at 17:59
  • so try to clear your dependency and see if it works :) – Dennis Anderson May 01 '15 at 18:00
  • id doesnt work. i had that code month ago.. :) i clean and rebuild project every day ;) – Rokas Devolskis May 01 '15 at 18:05
  • there is no "libs" folder inside my project. Where should it go? maybe PROJECT/src/main/libs ? or PROJECT/src/libs ? or PROJECT/src/main/java/libs ? – Someone Somewhere May 27 '15 at 22:02
0

Here is i did it and it worked for most libraries. Since the libraries have their own manifest files they have got to be used. Extract the master-zip elsewhere and copy only the library folder into your project direct folder where there is the app folder. When done then open the application settings.gradle file and edit it like below:

include ':app', ':mylibrary'

Sync the project then open the build.gradle of your application then go to dependencies and add your library to it as below:

compile project(':mylibrary')

Sync the gradle with project then if any errors occur within the library gradle then open it and match it with your project data. Usually you would want to change compileBuildTools, sdk and other stuff. Happy coding

Flash
  • 1,105
  • 14
  • 16