Using JRuby in Android Studio - java

I'm trying to use JRuby in projects created in Android studio. I have built the latest (as of 9/10/2014) JRuby, and have completely updated Android Studio. I have a working app that I can use to test. I have a copy of jruby.jar in the MyApp/app/libs directory. Once there I right-clicked on jruby.jar and selected "Add as Library", which presumably did something (though what I am not certain), and have added the line "compile files('libs/jruby.jar')" to the build.gradle that is in MyApp/app/.
In one of the class files I have "import org.jruby.embed.ScriptingContainer;", which Android Studio says is fine (if I hadn't added jruby.jar as a library I couldn't include this without an error). Then in one of the working methods I say "ScriptingContainer container = new ScriptingContainer();". When I run this method the app will crash. I won't try to include the whole error message, but the important part seems to be:
Caused by: java.lang.ExceptionInInitializerError
at org.jruby.embed.internal.AbstractLocalContextProvider.<init>(AbstractLocalContextProvider.java:42)
at org.jruby.embed.internal.SingletonLocalContextProvider.<init>(SingletonLocalContextProvider.java:88)
at org.jruby.embed.ScriptingContainer.getProviderInstance(ScriptingContainer.java:248)
at org.jruby.embed.ScriptingContainer.<init>(ScriptingContainer.java:228)
at org.jruby.embed.ScriptingContainer.<init>(ScriptingContainer.java:185)
and
Caused by: java.lang.RuntimeException: unsupported Java version: 0.9
at org.jruby.RubyInstanceConfig.initGlobalJavaVersion(RubyInstanceConfig.java:1858)
at org.jruby.RubyInstanceConfig.<clinit>(RubyInstanceConfig.java:1608)
At least, those are the parts that make sense to me. I hav no idea why I would get the error "java.lang.RuntimeException: unsupported Java version: 0.9", since I am using 1.8.0_20. The rest of the errors I cannot follow. When I click on any of the files giving me an error (say AbstractLocalContextProvider.java:42) Android Studio will show the file but also say "Sources not found". That could be the problem, but I don't know why it can't find the sources.
Thanks for any help,
Brian

Uwe Kubosch (‏#donv70) was able to tell me the solution to this via Twitter, so credit to him, but I wanted to post the solution here in case anyone else needs it.
It was Java version that was causing the problem. In Ruboto the problem is solved here: https://github.com/ruboto/ruboto/blob/master/assets/src/org/ruboto/JRubyAdapter.java#L137
and for use in Android Studio it is necessary only to include the line: System.setProperty("jruby.bytecode.version", "1.6");
The number of course can be 1.6, 1.7, or 1.8, depending on your version of Java.

Looks like an interoperability problem between JRuby and the Dalvik VM (don't forget that you're running against Dalvik, not the Java VM).
There's a bug report at http://jira.codehaus.org/browse/JRUBY-5774 that may lead you in the right direction.
It's kind of old, and is marked 'fixed', but maybe it'll provide some clues?

Related

JavaFX font icons in FXML not working

I have gotten this result from running a javafx application using fontawesomefx
Caused by: java.lang.IllegalAccessError: tried to access method com.sun.javafx.css.parser.CSSParser.<init>()V from class de.jensd.fx.glyphs.GlyphIcon
at de.jensd.fx.glyphs.GlyphIcon.<clinit>(GlyphIcon.java:49)
I do not know how to fix a problem like this please help.
I would like to integrate resizable icons as font elements in java programs and this is one way I tried to do it but it does not work.
A couple of FontAwesomeFX library existing bug reports exist for this:
IllegalAccessError on FontAwesomeIcon construction. The bug report has been closed, but a comment by a user on the bug report states
the issue is still there in 8.9, try FontAwesomeFX 8.4
IllegalAccessError on FontAwesomeIcon construction. Same error, different report and further comments . . .
yes I was using JDK 1.8.0_31 that's why it doesn't work for me after updating to 1.8.0_92 version everything is working great.
AND
This is still an issue. com.sun.javafx.css.parser.CSSParser is not accessible in Java 9 resulting in java.lang.NoClassDefFoundError.
So, whether you get an error or not will depend on the Java version you are using (and, from your comments, the library is incompatible with all Java versions you have tried).
You will need to work with the developer of the library to get the error resolved.

Trouble running a Java.jar file with a Swing GUI on Android phone - Major.Minor Version 52.0 & Main Class Name Missing

Hello!
The goal I have is pretty simple: I want to create an executable .jar file which should be able to bring up a form (made using swing) and write the put-in information into a well structurized plain text file. Due to portability/mobility reasons I will have to run this on an Android phone.
Since Android unfortunately doesn't have native Java support and I am unable to code a real Android application myself, I tried to use a Java emulator. Unfortunately, it appears that a working Java Emulator is hard to find to begin with. JBED instantly crashes on my Medion X701. Netmite's Website, which also seems to offer a .jar to .apk converter, appears to be down. JBlend seems to have installed properly, but I do not know how to work with the program now that it presents me nothing but an empty screen with the caption "0 Java ME Application(s)". On the web, I could not find a proper manual. PhoneME's official website was Java.net, which is no longer active. But during my research, I could find an older Version of PhoneME which seems to be running well.
As a test, I created a simple jar file that shows a maximized JFrame. Unfortunately, it isn't able to run my simple executable Jar file on my phone. The main reason for that should be the aforementioned error, which implies that the interpreter there is probably Java version 1.7, since PhoneME's last release was in 2015. There are more error messages referring to an "unknown source", which I believe originate from the first error. I tried to recompile my jar file using Eclipse, by setting the Compiler compliance level to 1.7 and choosing the jre 1.7 before exporting my project. Unfortunately, this didn't change the error messages I got on PhoneME!
As my last attempt, I created a Startup.class file which does the very same thing as my jar file.
import javax.swing.*;
public class Startup {
public static void main(String[] args) {
JFrame fishForm = new JFrame("Questionnaire");
fishForm.setExtendedState(JFrame.MAXIMIZED_BOTH);
fishForm.setVisible(true);
}
}
I compiled it using the command prompt in order to make sure that it is indeed using java 1.7 as the target. This .class file, which ran fine on my computer, leads me into a different error: "Main class name missing.", followed by multiple lines of usage explaination. The command line PhoneME presents doesn't seem to allow me to post command operations myself, as pressing Enter on the virtual keyboard does nothing.
My Questions
Is it even possible to run a Java application on Android which relies on the GUI libraries of Swing, or am I wasting my time?
Is there a different, up-to-date Java emulator for Android which I could use? Or is there a working jar2apk converter somewhere out there?
If not, then there's probably a reason why Java emulators ceased to exist. Is there a much simpler solution for my initial problem which I am missing?
I'll await your ideas eagerly!

Business Objects 'bcm.jar' error when exporting Java app

I have been working on creating a simple Java desktop app using the RESTful API for Business Objects and have run into an issue. Whenever I run my app in Eclipse in works fine; whenever I export it as a 'Runnable Jar' and select the Library handling option 'Package required libraries into generated JAR' it works fine. However, whenever I try to export it using the Library handling option 'Extract required libraries into generated JAR' I get the following error after running the app:
java.lang.NoClassDefFoundError: Could not initialize class com.businessobjects.bcm.BCM
I have the 'bcm.jar' file added under a 'res' Source Folder and have it added to the Build Path. At one point I added all the JARs under the 'SAP BusinessObjects' java folder, and external folder, but it still throws the error. The problem stems from this line of code:
enterpriseSession = CrystalEnterprise.getSessionMgr().logon(userID, password, CMS, auth);
Would anyone know why I am getting said error? I really want to use the Extract option as it will improve performance as my app becomes larger. Any help resolving this issue would be greatly appreciated :)
EDIT: I would be happy to provide clarification or further detail upon request!
Seems this was introduced in SP04 and SAP has no intent of fixing it as the RESTful API wasn't designed to be used with Desktop apps.
Have you included the cryptojFIPS.jar? Leaving it out can cause the error.

Cannot resolve corresponding jni function

i read a lot of posts but cannot resolve this yet.
There is my error lines and structure of project:
Some libraries and configs I take from another project... And don't know where I went wrong.
I will give you source code of files if needed
Thank you for any help.
I've also been getting this error since upgrading from Android Studio 2 to 3. The code compiles, but the IDE isn't recognizing the native functions. (This may be due to a preprocessor macro I've created that simplifies JNI function names.)
I've suppressed this error in Java by adding #SuppressWarnings("JniMissingFunction") before my class declaration.
Ok, so this missing 'JNI function' isn't a big deal. I know it's highlighted red, but the function is being linked, just not in a way that the IDE can determine.
First, here's the relevant source code: https://github.com/koreader/crengine/blob/master/android/jni/cr3engine.cpp#L770
CrEngine is linking the functions at run time. The reason why your IDE isn't picking them up is because the CrEngine functions start with Java_org_ instead of Java_com_. If you were relying on the engine to automatically link, this would be an issue, but as stated before, they are being explicitly linked at runtime with jniRegisterNativeMethods.
Do a clean and update your build tools to 25.0.3 (or better) in your gradle.build file. Update your SDKs and NDK. Then rebuild. Some of the errors I saw could be caused by older build tools.

Eclipse Android Error with appcompat_v7 values-14 and values-11

Im trying to see if I can get my Android App running with API 8. I've changed the build target for the project to 2.2 and I've changed the java compiler to 1.6. In problems I'm getting an error where R cant be resolved (I've checked to make sure my files don't contain import android.R) and in the console I'm getting a lot of red text that says:
[2015-08-02 16:12:13 - my app] /home/myname/workspace/appcompat_v7/res/values-v14/styles_base.xml:24: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Holo.ActionBar'.
I wont paste the whole console but it goes on like that for almost everything in styles_base.xml and themes_base.xml for values-v14 and values-v11
The only suggestions I have found are to change to a higher build target but I want to see if I can make my program compatible with API 8
I dont know if it's relevant but, I've searched through my project and I'm not using Holo anything either as far as I can tell.
You can keep the minimum required SDK for a project to be API v8 and still set a higher build target. The error you quoted is related to the AppCompat library and not your project. You should have no problems setting a higher build target for the library.

Categories