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?

2
  • You say you created the java library in Eclipse. Are you also writing your Android app with Eclipse? Or are you using Android Studio? Commented Feb 7, 2016 at 21:49
  • Buddy, did you read my post? Did you get your answer? Commented Feb 12, 2016 at 14:24

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Why is add as library step necessary? Shouldn't Gradle just pick up the jars automatically?
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.

Comments

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...

1 Comment

No, this doesn't compile the jar file for me.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.