I would like to add the extern jar library commons-jexl-2.1.1.jar
. I copied the jar into the libs/
folder and performed the Add as library...
menu point. I don't receive any errors in the code and everything seems to work but when compiling and starting the application I receive the error java.lang.NoClassDefFoundError: org.apache.commons.jexl2.JexlEngine
on this line private JexlEngine jexl = new JexlEngine();
Does anyone know what I've missed?

- 5,943
- 12
- 72
- 119
2 Answers
Unfortunately, that menu command is doing the wrong thing for Gradle-based projects, which I assume yours is. (Gradle-based projects are what you get when you create new projects in Android Studio). I've filed bug https://code.google.com/p/android/issues/detail?id=62249 to request implementing this menu command properly for these projects, or at a minimum disabling it until it's implemented to prevent confusion.
In the meantime, you can add external JAR dependencies by going through the Project Structure dialog, which will add the appropriate entries to your build.gradle build file. Choose File menu > Project Structure, and click on the "Modules" entry on the left. Choose your module from the middle list, and click on the Dependencies tab on the right. Then click on the + button at the bottom to add a new dependency. Screen shot here:
The + menu has an option for "File dependency" (pictured). You will get a file chooser that will let you select the jar file.
If your dependency is one that can be found in Maven, you may find it more convenient to specify the Maven coordinates; that way, the build system will automatically download the dependency, and you won't have to download and store the JAR manually. To set that up, choose "Maven dependency" from the + menu. You'll get a dialog where you can search to find the proper Maven coordinates for your library. In your case, those coordinates will be "org.apache.commons:commons-jexl:2.1.1@jar"
If you prefer to edit build files by hand, check out your build.gradle file after completing the Project Structure dialog changes to see what it did.
The docs for using Gradle in Android are at http://tools.android.com/tech-docs/new-build-system

- 79,344
- 24
- 180
- 163
-
My project structure window looks a bit different, I don't have a Mudules selection on the left and the + for choosing `file dependencies` doesn't exist either!? – wasp256 Nov 14 '13 at 06:24
-
Did you create your project by hand or by using the New Project Wizard? If you created it by hand and it has a more flat directory structure than wizard-created projects, you could be running into https://code.google.com/p/android/issues/detail?id=62170 . In that case you can add the dependency to your build.gradle file by hand by putting a `compile 'org.apache.commons:commons-jexl:2.1.1@jar'` statement in your `dependencies` block – Scott Barta Nov 14 '13 at 17:08
-
I have already inserted `compile files('libs/commons-jexl-2.1.1.jar')` in my build.gradle file, added your line too but I still receive the same error...I created the Project with File->New Project – wasp256 Nov 14 '13 at 19:19
-
Based on your screenshot you're using a very old version of Android Studio (0.2.13). Try upgrading to 0.3.5. That version itself has some issues we're hoping to resolve in 0.3.6, which we're trying to get out the door. – Scott Barta Nov 14 '13 at 19:34
courtesy The App Chaps I've been struggling with the same thing for many hours, trying to get the Gson jar to work no less. I finally cracked it – here are the steps I took:
- Put the Gson jar (in my case,
gson-2.2.4.jar
) into thelibs
folder - Right click it and hit 'Add as library'
- Ensure that
compile files('libs/gson-2.2.4.jar')
is in yourbuild.gradle
file - Do a clean build (you can probably do this fine in Android Studio, but to make sure I navigated in a terminal to the root folder of my app and typed
gradlew clean
. I'm on Mac OS X, the command might be different on your system
After I did the above three, it started working fine. I think the 'Add as library' step was the one I'd previously missed, and it didn't work until I cleaned it either.
[Edit - added the build.gradle
step which is also necessary as others have pointed out]

- 1
- 1

- 6,200
- 6
- 45
- 64