Can't get exp4j to install - java

I'm currently writing an android application in android studio. As part of my application I would like to use the exp4j library:
import net.objecthunter.exp4j.Expression;
import net.objecthunter.exp4j.ExpressionBuilder;
These are the two lines of code I'm using to try and import it. I've downloaded the .jar files from the exp4j website however when I try and run these nothing happens. Is this library still in use and the downloadable version working?
Also is there anyway to install it without using the .jar files from the website? Can it be installed from Git?
Any tips greatly appreciated.
Kind Regards,
Ben
edit:
I have added the following to my dependencies but the exp4j variables are still not recognised.

You can try the following steps to add exp4j in your android studio project.
Download exp4j binary jar from the official site. Download
Import exp4j into android studio by copying the jar files in app/libs folder.
Add the following line in your module build.gradle file dependencies.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
...
}

Got this working...
Adding the dependencies in and removing the imports from my main sorted it out after reloading my project.

Related

Importing non-Android Java Library into Android Studio Project

I would like to import a non-Android Java library to an Android project.
Based on my research, there seem to be two main options:
Add the source code of the Java library as a separate module. However, the source code cannot simply be imported (e.g. added as a subrepo) since the Android package names would need to be added to each file.
Add a JAR file of the Java library. I have been following the instructions available here, and the project builds successfully, though I am still unable to import classes from the library. I suspect this may be because the project is a standalone Java library rather than an Android library.
Any advice on how to add the library (either as a JAR or as a copy of the existing library) would be greatly appreciated. Thanks.
Add the jar file for the library under app/libs and make sure your app/build.gradle file has the following:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
After you've included the jar file, click on the "Sync Project with Gradle Files" button. After the sync is complete you should be able to use the classes in the library.

How do I use a class from an imported jar file in Android Studio

I imported a jar file that I created with Eclipse to my Android Studio library but I don't know how to use the classes from it. Imported it here and I'm now trying to use the logarithm class
I tried to somehow get it with the import word on the beginning of a class but I don't get it to work. Sorry I'm a beginner. :p
Ok follow this:
Put the .jar into the libs folder
Put compile files('libs/your.jar') is in your build.gradle file (or compile fileTree(dir: 'libs', include: '*.jar') if you are using many jar files)
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. If this does not work then use the terminal tab and do this: gradlew clean.
Hope it helps!!!

Importing a JAR into Android Studio 2.2

I'm trying to import a JAR that I made in Groovy into an Android Studio 2.2 project and all the instructions I can find say to just add it under Project Structure -> app -> Dependencies. I did this and it's still not letting me use the imported JAR. I've imported JAR files from Groovy into other Java projects in Eclipse. Did something change in Android Studio 2.2 that changes how you're supposed to do this?
I thinnk this step help You
1 ) Put the jar (in my case, yourJar-2.2.4.jar) into the libs folder.
2) Right click it and hit 'Add as library'.
3) Ensure that compile files('libs/yourJar-2.2.4.jar') is in your build.gradle file (or compile fileTree(dir: 'libs', include: '*.jar') if you are using many jar files).
4) 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.
5) Clean Project.
6) Run.
May be it,s Working
I figured it out but I'm still not sure why it works. I changed the package name of the JAR to match the Android project. My Android project is com.johnwstanford.simplegps and I originally just called the JAR package SimpleGpsOutputFormatter. I changed it to com.johnwstanford.simplegps.SimpleGpsOutputFormatter and for some reason, that made it work. Anyone know why that would make a difference?

Androidstudio - gradle - cordova: import.org.apache.cordova.* fails

because of a high priority security fix in cordova for android we need to update our cordova version (from 2.7.0 to 3.6.3) in our app. So we thought it would be better to create a new project.
I installed cordova and create a project with cordova cli api. Also I added the android platform added many cordova plugins. Then I copied our sencha touch stuff into the www folder.
Then I called "cordova build android" (before I also called "cordova prepare android").
After that I imported this android project in Android Studio (0.8.11).
I needed to configure the gradle files a bit (buildToolsVersion, etc.)
For our app I needed to copy the following things from our old project
AndroidManifest.xml
All the stuff out of the res/ directory
in the src/ directory I added some stuff we need in our app
Then I recognized that the android-support android-support-v13.jar library was missing in the lib/ folder. So I copied it out of the sdk\extras\android\support\v13 directory. After that nearly all red stuff in the code disappeared, so I tried to run it.
The app starts but I'm getting many errors like: "Cordova exec fail: Class not found".
So I looked into our src/ directory and there in our java files. There is everything red because the impor of
import org.apache.cordova.*; or
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
fails.
The needed java files I found in /CordovaLib/ant-build/classes/com/org/apacke/cordova/
Is there anything which I still need to configure?
My gradle file dependencies:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
for (subproject in getProjectList()) {
compile project(subproject)
}
}
Please help me/ Thanks ahead!! :-)

How to import project - intellij

I am experiencing difficulties to install some project based on a build.gradle file. I was told in a precedent post, that I should use Android Studio but it seems even more difficult (reported conflict for gradle 1.10 and Android Studio). So I am asking if it is possible to import the project directly in my ide, https://github.com/chrisbanes/ActionBar-PullToRefresh. If yes, should I put the library folder below in my libs folder ? Here's a screen of the file hierarchy
Since you are using Android Studio and Gradle, you could import it as suggested by the QuickStart page :
The easiest way to add ActionBar-PullToRefresh to your project is via
Gradle, you just need to add the following dependency to your
build.gradle:
dependencies {
mavenCentral()
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}
I believe this is by far the easiest way to include that great library in your project.
If you are using Eclipse, you can still use the library, just download the project and create a create a new library project with the code from "library".
Check the guide http://www.jetbrains.com/idea/webhelp/cloning-a-repository-from-github.html
and other github integration http://www.jetbrains.com/idea/webhelp/using-github-integration.html

Categories