Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a library project in android studio

I have been trying to add this library project to my existing project in Android Studio. It's the first time I am going to use a library project and I am having tough time. I have looked around for many ways to do this from tutorials and posts around but couldn't get it done.

like image 397
dmSherazi Avatar asked Dec 04 '13 14:12

dmSherazi


People also ask

How do I access library on Android?

You can find your History, Watch later, Playlists, and other channel details in your Library. To find your Library, go to the bottom menu bar and select Library .

How do you create a library project?

Create a new project to make your library in. Click File > New > New Module > Android Library > Next > (choose name) > Finish. Then add whatever classes and resourced you want to your library. When you build the module an AAR file will be created.

Can I use Java library in Android?

To use a Java library (JAR file) inside your Android project, you can simple copy the JAR file into the folder called libs in your application. *. jar files in this folder are included into the compile classpath via the default build.


2 Answers

I'm not sure if it's already possible to add a library project via the IDE (-> without any problems). I do this by configuring the gradle files of my project like this:

  • create a folder in your root project directory named libs
  • copy the folder datetimepicker-library to libs
  • add this library in your settings.gradle with the following command:

    include ':libs:datetimepicker-library' 
  • go to your build.gradle file of your AppProject and add the following line to your dependencies:

    implementation project(':libs:datetimepicker-library') 
  • at least you have to sync your gradle files: Tools -> Android -> Sync Project with Gradle Files

Please try this. If you get errors please post the log file.

like image 96
owe Avatar answered Sep 29 '22 15:09

owe


I did it this way ,

  1. go to project Structure from File menu
  2. Select modules from the left pane
  3. press on `+'
  4. complete the new module wizard steps Make sure to make the module package name same as the module you want to add
  5. again open Project structure as in step 1
  6. select your project from the module list and on the right select dependencies
  7. Click on the + icon from right
  8. select module dependency and then select the newly added module.
  9. copy files of the library project to the new directory created as module
  10. Done

Step 1:

step 1

Step 2:

Step 2!

Step 3:

Step 3

Step 4:

**Step 4:**

....

Step 6 & 7:

enter image description here

Step 8: enter image description here

like image 41
dmSherazi Avatar answered Sep 29 '22 15:09

dmSherazi