Compiling java file in android runtime java - java

I know this has been asked here and I have tried the suggested solutions but nothing yet to solve. I want to create an java compiler that could run in android in run time using button click but I can't find the right approach to solve the problem.
I've managed to create the lexical,parser and semantic analyzer but I have no Idea how I will convert the string into machine readable language and get the output of the code.
I've tried to download repositories from github but most of it uses Javax.tools api which is not supported in Android Studio.
I still don't understand much about dexing too..
what approach could I use to solve this problem ?

Related

Java in Visual Studio Code

I am attempting to set up JAVA in Visual Studio Code and I can not get it working. I am getting an error that states "Linkage Error occurred while loading main class Hello". I have researched numerous sites and have not found any solutions that I understand. For example, I have seen several sites that state you must "enable-preview" on some setting but there are no directions on how to actually do that. I have installed the jdk-11.0.4 jdk version. I have never programmed in java so I do not know what is required. I reviewed several you tube videos and of course their installation went off without any problems! Is there anyone here that can help?
As per their documentation link, there are two ways to setup and run java with VS code
They have created a special Installer of Visual Studio Code for Java developers. The package can be used as a clean install or an update for an existing development environment to add Java or Visual Studio Code.
Installer of Visual Studio Code for Java developers
Alternatively, you can also add Java language support to VS Code by installing the popular Java extensions by yourself.
Please see link below to setup and let me know if you face any issue in setting up and run java with VS Code.
Java in Visual Studio Code
There might be two reason to not identifying Java
Might be java is not installed correctly
Or there are multiple version installed so might be conflict
Could you try F1 -> Java: Clean the Java language server workspace?

I'm trying to install OpenCV with android studio and use C++ with it. I need to install JNI so how do I do this?

Most of them seem to be extremely difficult to follow or don't work on new distros. Or maybe I'm just stupid.
I want it to work with OpenCV and have been following a series where they install JNI here:
https://www.youtube.com/watch?v=mF9fYdXfSD8&t=44s
But apparently that doesn't work on newer versions and there's a better way of doing it but I'll be damned if I can figure it out.
So I tried this tutorial:
https://codelabs.developers.google.com/codelabs/android-studio-jni/index.html?index=..%2F..%2Findex#0
but it's giving me Plugin with id 'com.android.application' not found which means somethings fucked with gradle as I tried to change it...so I'm not really all that sure what to do now. Any links or solutions on Android Studio 2.2.3 with 3.3 gradle?
Not really sure what else to do other than ask people...
If I could have any help that would be great. I'd say what I specifically tried but I don't understand enough about JNI to say what I actually tried.
I just need a very basic step by step, like I've never used Android studio before, of how to do this...because all attempts at understand here is failing me entirely.
Thanks for any help you can give :)

Compiling this OCR Library Code

I came upon this simple Library that someone wrote in java GetImageText.java for OCR in images so i tried compiling it on my Ubuntu via terminal but i get several error as shown below in this paste :
Compilation Errors
Can Someone help me with it , it is absolute necessity that i test this code , its explanation can be found here
I think the problem is that i do not have com.sun.image.code.jpeg in my system, although java is definitely installed. Although I am not sure how to import this package without using an IDE.
The problem is that the library you are trying to recompile depends on INTERNAL classes1. Portable libraries are not supposed to do that!
What has happened is that the class has been removed or replaced. This happens from time to time, and that is the reason that people are not supposed to write code that depends on INTERNAL classes.
Solutions:
Bug the authors of the library to fix the problem.
Figure out which version(s) of Java that the library supports, and stick with those.
Find an alternative library that supports the version(s) of Java that you need.
Non-solution: Compiling the library on an older version of Java and running on a newer one is likely to fail. The class needs to be present at runtime, as well as at compile time.
1 - Anything in the "com.sun" tree counts as INTERNAL. Sometimes people have no choice but to have such a dependency. However, they still needs to deal with the potential consequences for portability.

OpenFeint with cocos2d-x (iOS and Android)

Apparently OpenFeint supports both iOS and Android. Great.
But how do I integrate it with cocos2d-x Android? The SDK is, apparently a .jar and such. Cocos2d-x uses c++.
I don't get this tutorial: http://blog.molioapp.com/2011/11/openfeint-and-admob-integrated-with.html
I copy & paste the code and immediately I get errors (JavaVM *gJavaVM;? There is no identifier called that way!)
Are there any other steps not mentioned in that tutorial I missed?
Yes. In order to build a C++ library for Android you need to use the NDK. Getting that set up is pretty involved so I am just going to link you to a separate tutorial that has already covered it.
http://developer.android.com/sdk/ndk/index.html#installing
That is the Google documentation on getting up and running. There are other resources for this as well if you have trouble.

Embed Groovy in an Android Java App

Basically, I need to run Groovy Scripts to manipulate Java objects, and GroovyShell / GroovyScriptEngine seems to be the best way to do so. Is it possible to embed Groovy inside a Java App? I tried placing the groovy-all-1.8.2.jar into my Android Java App's libs folder, referenced it then hit compile but I got a bunch of errors.
How do I do this?
I don't believe this will work. Groovy converts scripts to bytecode, and as the Dalvik bytecode is different to the Java bytecode that Groovy expects, I believe it will have problems...
The Discobot from a few years ago has been resurrected though, and great progress is being made so there is hope on the horizon.
But that doesn't help you today...
In near future it will be possible: http://skillsmatter.com/podcast/home/groovy-android/
I have found it recelty.
You can find the solution from http://melix.github.io/blog/2014/06/grooid.html.
Check it http://glaforge.appspot.com/article/groovy-2-3-3-and-groovy-2-4-beta-1-with-android-support too!
Since 09/2011, Discobot seems to be stuck. The last results seem to be : most of it works, but this is very slow.
Groovy 2.0 is out now, and Guillaume Laforge (insider) says it could helps - especially because of the #CompileStatic new feature of Groovy 2.0. Since then, Groovy 2.0.1...2.0.4, it looks that static compilation got a lot of bugfixes.
But for now, on the official website of Groovy, Android is not discussed, nobody seems to really be in charge (see wiki and wiki).
Here is an example of what you are trying to accomplish. https://github.com/melix/grooidshell-example
It is pretty slow since it has to first compile to class files on the android device and then convert them to dex, but it will accomplish what you are looking for.
A better choice for running scripts on Android is SnapScript. It does not rely on Bytecode and is fully supported on Android.

Categories