4

I've added the external library bsh-2.0b4.jar to an android project in android-studio by going into Project structure -> Modules -> myProject -> Tab-Dependencies -> + Sign and then add the .jar file. I also tried to copy the file into the /libs directory and then rightclick in studio and add as library... (both methods independently!!). I inserted the following code as a test

  import bsh.Interpreter;
  ...
  Interpreter interpreter = new Interpreter();
  interpreter.eval("result = (7+21*6)/(32-27)");
  return interpreter.get("result").toString();

I compile with the buildin button in android. The build.gradle looks like:

  buildscript {
    repositories {
      mavenCentral()
    }
    dependencies {
     classpath 'com.android.tools.build:gradle:0.5.+'
    }
  }
  apply plugin: 'android'

  repositories {
    mavenCentral()
  }

  android {
     compileSdkVersion 17
     buildToolsVersion "17.0.0"

     defaultConfig {
        minSdkVersion 9
        targetSdkVersion 17
     }
  }

  dependencies {
     compile 'com.android.support:support-v4:13.0.+'
  }

But when I compile everything I receive the error

  Gradle: error: package bsh does not exist
  Gradle: error: cannot find symbol class Interpreter

Can anyone help me pls?

2
  • how do you compile ? using command line or built-in command ? Can you post the dependencies section of build.gradle ? Commented Aug 29, 2013 at 21:38
  • Updated the gradle file, and I'm compiling with the build-in command Commented Aug 30, 2013 at 8:03

2 Answers 2

8

Try this...

  1. Create libs folder under your application folder.
  2. Add .jar files to libs folder.
  3. Then add .jar files to app's build.gradle dependency.
  4. Finally Sync project with Gradle files.

1.Create libs folder:

enter image description here

2.Add .jar to libs folder:

enter image description here

3.Edit app's build.gradle dependency:

  • Open app/build.gradle

enter image description here

4.Sync project with Gradle files:

  • Finally add .jar files to your application.

enter image description here

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

Comments

3

Change your dependencies like that

dependencies {
   compile 'com.android.support:support-v4:13.0.+'
   compile 'org.beanshell:bsh:2.0b4'
}

You can now remove manually downloaded dependencies in libs directory.

What you did was adding libraries to Android Studio project only. You should always add them to Gradle build files as only this is interpreted by Android Build Tools.

There is also new version of build tools 18.0.1, you can install them and change version in you build.gradle. As far as I know they can handle aar dependencies better.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.