问题
I have 2 libraries:
- chilkat-9.5.0-android-all
- 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:
https://www.chilkatsoft.com/chilkatAndroid.asp
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.
回答1:
I implemented a .jar library today in my project and did the following:
add the .jar file to the libs folder of your project
in the build.gradle file add:
compile fileTree(dir: 'libs', include: ['*.jar'])
to the dependencies.Build your project
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.
回答2:
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
来源:https://stackoverflow.com/questions/29991716/android-studio-how-to-add-and-use-project-as-library-not-as-module