2

Assume that I have no idea what I'm doing. I'm trying to include a java library that I created in Eclipse with no relation to Android in my Android application so that I can use the classes in said library. I tried creating a folder called "libs" and including ":app:libs" as a dependency in my Project Structure screen under Modules->app->Dependencies. When I try to build, it gives me the message "Error:A problem occurred configuring project ':app'.

Cannot evaluate module libs : Configuration with name 'default' not found." I looked around and saw that the problem appears to be that I haven't set up a default build configuration for libs. What I can't figure out is how to do this. How do I set up a default build configuration for the module libs?

Avi K.
  • 1,734
  • 2
  • 18
  • 28
JDeveloper
  • 91
  • 2
  • 11

3 Answers3

4

You can do it in different ways. There are three standard approaches for importing a JAR file into Android studio. The first one is traditional way, the second one is standard way, and the last one is remote library. I explained these approaches step by step with screenshots in this link:

https://stackoverflow.com/a/35369267/5475941.

I hope it helps.

Community
  • 1
  • 1
Mohammad
  • 6,024
  • 3
  • 22
  • 30
0

One solution is to compile your library into a JAR file and then place it in the libs (Eclipse) or app/libs (Android Studio) folder in your Android project.

Alternatively, if you are using Eclipse to develop your Android app, you can add the library project as a dependency to your Android project. On the other hand, if you are using Android Studio, you can import the code for your library as a module and add it as a dependency to the module for your Android app.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
0

It sounds like you're trying to add a jar dependency to a Gradle build of an Android app. You can create a folder called libs in your app project, but to tell Gradle to include jars from that folder, you'll have to put a line like this in your dependencies block:

compile fileTree(dir: 'libs', include: ['*.jar'])

If you create a new Android project from scratch in Android studio, this line is actually present for you in the template it uses.

The syntax you were using for ':app:libs' is actually telling gradle you want to add a dependency on subproject of 'app' called 'libs'. Time to hit the gradle docs...

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441