Running compiled Java code - Android Q&A, Help & Troubleshooting

Hi.
I want to know if it's possible to run compiled Java code (through the CLI) on my Android (4.0, HTC Sensation XE). I'll be writing and compiling the code on my laptop. The cli programs that I want to write are fairly simple (using java base classes, networking), no graphical interfaces or anything that requires elevated privileges.
My phone is not rooted.

There is no JVM on android, so you cannot directly run Java apps compiled for desktop. All android apps are compiled into dalvik bytecode.

knutson said:
There is no JVM on android, so you cannot directly run Java apps compiled for desktop. All android apps are compiled into dalvik bytecode.
Click to expand...
Click to collapse
So can I get the dalvik VM (with the compiler) on windows/linux ?
From wikipedia I've read that there's a tool called dx that can convert .class files to .dex (but not any .class files can be converted).

Mayhem00 said:
So can I get the dalvik VM (with the compiler) on windows/linux ?
From wikipedia I've read that there's a tool called dx that can convert .class files to .dex (but not any .class files can be converted).
Click to expand...
Click to collapse
It is possible to install Android to VirtualBox and use it to run Android apps (much faster than emulator from Android SDK).

knutson said:
It is possible to install Android to VirtualBox and use it to run Android apps (much faster than emulator from Android SDK).
Click to expand...
Click to collapse
But I want to be able to run short Java programs I make on my phone .

Related

Android SDK Setup - Java is not found in your PATH.

Hi,
I am new to Android. I have downloaded and installed every necessary component in order to start working with Android. The issue I am having is that in Command Prompt, anything I type in related to the Android SDK (for example: adb, or even just android) comes back with "Java was not found in your path". Now, I have changed all my PATH variables under "User" to the EXACT locations of where these folders are, but no dice. It keeps telling me to go and edit my PATH variables. Even running SDK Setup, gives me the same error, and tells me to add where Java was found (even though I have!).
I am starting to get really fed up with this, because Eclipse can't find the "jre" folder inside the Java JDK, either (that is, of course, until I copy the entire jre folder inside of the eclipse folder, or put eclipse inside of the JDK folder)...
I just know it shouldn't have to be this tedious to set everything up and I would really appreciate it if someone can help with this
I am running Java JDK 1.6.0_21 (x64), Eclipse Helios (3.6) IDE for Java EE Dev., Android SDK Revision 6, all on Windows 7 Ultimate x64.
Something to note: I have not encountered any problems with Eclipse Helios and the ADT plugin as stated on the Android Developers website. I can use Eclipse and the SDK to create and run the"Hello, Android!" application on the emulators without issues. I just want to be able to run everything from the command prompt, too. Now, if I can only get my phone to be recognized after I get this resolved.
I also need this for rooting and unlocking the phone.
Bazz44 said:
Hi,
I just know it shouldn't have to be this tedious to set everything up and I would really appreciate it if someone can help with this
I am running Java JDK 1.6.0_21 (x64), Eclipse Helios (3.6) IDE for Java EE Dev., Android SDK Revision 6, all on Windows 7 Ultimate x64.
Click to expand...
Click to collapse
In the SDK tools folder go to libs and edit find_java.bat.
Change all instances of %PROGRAMFILES% to %PROGRAMFILES(X86)% .
I had to do this for my SDK.
Your java will probably still resides in c:\program files (x86)\java or the likes.
To test if it works open DDMS.bat(May need to open twice).
I ran "ddms.bat" before changing the "find_java.bat", and it just came up that it could not find the path > checking if it is installed elsewhere. I did what you suggested (I found three instances of where I needed to add the (x86)), ran "ddms.bat", and got the same error. However, this time it also opened the Dalvik Debug Monitor. Eclipse still won't run without its own copy of the "jre" folder from the JDK at the same folder level as the "eclipse.exe"...
any luck with this? I'm also having same trouble in Win7x64
Gonna give in otherwise n reboot my ubuntu system see if thats any easier
i know i can't use OpenJDK or something so ill have to swap that but fingers crossed
=]
Solution
Install any JRE Java, Copy the java folder at program files/Java/jre6 Paste it inside MOTODEV´s folder program files/Motorola/MOTODEV Studio for Android 1.2/ and rename it to jre
Done
Edited the eclipse .ini works a treat now wi java x64...
time to whip out the olde java books from college an see if any of it comes back to me
Is it possible to install the android sdk platforms & extras offline manually, my only net atm is my desire tethered, unlimited data but I don't wanna push my luck
I'm not sure if it may be related or not but according to the android dev page, you should be using eclipse 3.5 because they have been having problems with 3.6
May or may not be related but worth a shot.
I'm not sure if it may be related or not but according to the android dev page, you should be using eclipse 3.5 because they have been having problems with 3.6
May or may not be related but worth a shot.
i need help http://forum.xda-developers.com/showthread.php?p=24028502#post24028502
Please use the Q&A Forum for questions &
Read the Forum Rules Ref Posting
Moving to Q&A
Make nu system path
Try making new system path named PATH (all caps). its an issue with Win7 64. Hope it helps. and yes Installing the Android sdk is a giant head****. I have it all put as fare as the link to abandroid put it doesn't make plug-in available in the plug-in list. I'm at a loss...
As i said, hope it works.
Having just had this issue myself on a new install of eclipse, the sdk and adt, here's what finally helped me: making sure the java\sdk1.6.x.x\bin directorywas in front of the windows\sys32 directory in the PATH statement of the environmental variables.
I did already add the JAVA_HOME and such, but the above was the step that finally allowed me to finish the setup.
Fix for Win7 64bit and Android SDK/Java install
MacDegger said:
Having just had this issue myself on a new install of eclipse, the sdk and adt, here's what finally helped me: making sure the java\sdk1.6.x.x\bin directorywas in front of the windows\sys32 directory in the PATH statement of the environmental variables.
I did already add the JAVA_HOME and such, but the above was the step that finally allowed me to finish the setup.
Click to expand...
Click to collapse
I had to finally use JAVA_HOME C:/PROGRAM FILES/JAVA/JDK1.7.0_05 That finally allowed me to instal the Android SDK
best answer
rowdyvc said:
I had to finally use JAVA_HOME C:/PROGRAM FILES/JAVA/JDK1.7.0_05 That finally allowed me to instal the Android SDK
Click to expand...
Click to collapse
Thank you you solve my prob man

[Q] Android general questions

I'm new to Android and have a few question that didn't get answered by Google it. I have bought my first Android phone (SGS2 of course, after years of being a Symbian fanboy), but have not received it yet.
1. Does everything run on top of Dalvik JVM? At the bottom is the Linux kernel. Then there is a Linux process which runs Dalvik VM. Could for instance Sun's JVM run on a Linux process of its own or another Linux application?
2. Can C/C++ Linux program run on Android? Though compiled for ARM. Android has NDK (Native Development Kit) which allows it to run C/C++ applications inside Android applications, but I'm wondering about running C/C++ applications directly on Android. BusyBox is coded in C, but runs on Android. Is it running directly on the kernel's linux process or within an Android application on Dalvik?
3. The latter(Q2) would indicate that not everything run on top of Dalvik. Otherwise C/C++ programs would not run.
4. Android uses ADB (Android Debug Bridge) for its CLI magic. BusyBox uses Ash. Can one install bash as the default shell, with full GNU Core Utilities commands? Some forum posts indicate that it is possible to install an ARM re-compiled bash version.
5. Android can be rooted by installing applications like Super User or BusyBox that would let the user execute applications as root. That would indicate that there exist a root user, in addition to the actual user. Is this similar to how it is on Linux? Can I define a password for the root user so that no applications can run root directly?
6. Are all user data stored in the database SQLite? User data is accessible through different applications, but how does Android determine access rights to it?
7. I have read that Android applications run on their own Linux process and are assigned a unique user ID. Does this mean that we can run ps to see all running processes or does it act like the Sun JVM just showing each VM process? However looks like different applications can run in the same process. Can these be distinguished or do we just the the once process.
8, Is the camera application (that some have made modifications of) a Google app or Samsung app? Just wondering since the former would allow such modified versions to run on other than Samsung phones, but given that different phones have different camera specs I don't see how this could go well.
9. Can the codes typed in the dialer be executed through a shell instead (adb)?
There are some apps that run direct c++ code. The stock gallery app for example is written in c++. So not everything uses that dalvik virtual machine. I don't know enough to answer all your questions though.
Not many replies. That is disappointing.
Perhaps I could move this thread to another forum here on XDA? Or perhaps another forum.
In the meantime I'll try some more Google search on the subjects...

[Q] Build java files for android platform

Hi,
I'm new to android developement. To make it short. Our project needs to be ported for android. It has some java and C code. We run this java as applet using Oracle JRE in linux systems and using firefox browser.
Now it needs to be done on android and browser. Android doesnot support JRE. Hence i downloaded eclipse, ADT plugin. Added my java files, external JRE library and compiled it. Got the apk and classes.dex.
Now my question here is i'm not able to proceed further. How to execute the same as in JRE before. I'm totally confused. Running the apk in emulator/android mobile only runs the activity.java code. Say i'm printing hello world in that(i dont need that but still i have wrote it as my first program).
I dont know how to execute my other java files(which will run as java applet before in linux systems). I'm stuck here since i have not worked on android.
This would be the first step in to my porting.
Also the easy solution would be to run the applet.jar i have directly on android similar to linux jre. Is it possible.?
Any sort of help would be great. Thanks.

[Q] How to install Java or plugins in Firefox of ICS?

Dear all,
Some websites require to use Firefox and install JAVA or plugins to play movies. But when I use Chrome to open these webs and click on the guided link to download JAVA, it told me that there is no suitable version yet.
When I use Firefox to open these webs, it said there are no plugins, and didn't tell me what plugins.
But I can open these movies on webs using android 3.1 or lower.
So, is it because ICS 4.0.3 hasn't supported to open webs which require JAVA or there are other ways to open these movies?
thank you very much for your reply.
Oracle doesn't make plug-in for Android but you may use Adobe Flash Player. But it's strange
I've already installed Adobe flash player 11 before but it's no use.
Actually they require JAVA runtime or plugins or something like that.
Android has no Java support. In order to use a Java plugin, the installation of Java se runtime for arm CPU would be required (it worked like a charm on my old Nokia n900 debian based) but there would be no way to use the Java vm into the dalvik vm.
The only way (if your phone is a dual core, though it'd too slow) is running Java applet into an Ubuntu chrooted environment. In that case, it would be strongly suggestable to download the latest version of Java se from oracle site, which has jit and is very fast in comparison to the version you can find on current Ubuntu img.
Then, you'll just have to unpack it and put it somewhere in Ubuntu chrooted fs and make a symbolic link in order to jar to be launched via that Java se version. Besides, check inside Firefox configuration (always the chrooted one) and manually set the plugin path, though it could use the old version.
So you'll get a fully functional Java vm in android
wow, it's complicated. So it means that I have to install 'ubuntu installer' (the same as 'linux installer' in Play Market, is it right? ) and then install firefox with plugins to use, does it?
If do it this way, my phone will run 2 environments (Android and linux) at the same time and it'll become too slow then. I think my galaxy s2 with CPU 1.2ghz, ram 1g is not enough to do this . Should wait till Android supports JAVA then
thank you for your help, lucaoldb!
You are welcome
It is easier than it looks. Anyway, the Ubuntu chrooted img has already Java support, though it is a slower version. You can test it and see if fits to your needs. If you want an improved performance, you can follow the way I suggested above.
---------- Post added at 02:09 PM ---------- Previous post was at 02:03 PM ----------
By the way, your hardware is ok and Java se support in android will not very likely be avalaible in next years, because Oracle sued Google people for copyright violation and the whole thing is not yet over...
lucaoldb said:
Android has no Java support. In order to use a Java plugin, the installation of Java se runtime for arm CPU would be required (it worked like a charm on my old Nokia n900 debian based) but there would be no way to use the Java vm into the dalvik vm.
The only way (if your phone is a dual core, though it'd too slow) is running Java applet into an Ubuntu chrooted environment. In that case, it would be strongly suggestable to download the latest version of Java se from oracle site, which has jit and is very fast in comparison to the version you can find on current Ubuntu img.
Then, you'll just have to unpack it and put it somewhere in Ubuntu chrooted fs and make a symbolic link in order to jar to be launched via that Java se version. Besides, check inside Firefox configuration (always the chrooted one) and manually set the plugin path, though it could use the old version.
So you'll get a fully functional Java vm in android
Click to expand...
Click to collapse
I downloaded Java for ARM from Oracle site; these are the libs provided:
Code:
[email protected]:~/Downloads/ejre1.6.0_32/lib/arm# ls
client libhprof.so libjawt.so libnio.so
headless libinstrument.so libJdbcOdbc.so libnpt.so
jli libioser12.so libjdwp.so librmi.so
jvm.cfg libj2gss.so libjpeg.so libunpack.so
libawt.so libj2pcsc.so libjsig.so libverify.so
libcmm.so libj2pkcs11.so libjsound.so libzip.so
libdcpr.so libjaas_unix.so libmanagement.so native_threads
libdt_socket.so libjava_crw_demo.so libmlib_image.so
libfontmanager.so libjava.so libnet.so
I cannot find libjavaplugin_oji.so or libnpjp2.so to create the symbolic link for Firefox.
How can I do?
Regards
EDIT:
Solved, I downloaded headless version of JAVA SE instead of headful version:
ejre-1_6_0_32-fcs-b05-linux-arm-vfp-eabi-headful-05_apr_2012.tar.gz
ejre-1_6_0_32-fcs-b05-linux-arm-vfp-eabi-headless-05_apr_2012.tar.gz
in headful version the file libnpjp2.so is present.

Run APKTOOL in ANDROID!!!

Tried it, i put aapt,apktool and apktool.jar in /system/bin...
But when typing apktool it says "no such file or directory"
How can i make it work??
bamsbamx said:
Tried it, i put aapt,apktool and apktool.jar in /system/bin...
But when typing apktool it says "no such file or directory"
How can i make it work??
Click to expand...
Click to collapse
I think you can't run it since Android is not using Java API, but Dalvik instead.
Source: http://en.wikipedia.org/wiki/Comparison_of_Java_and_Android_API
EDIT:
Also, try to find out more about this one: https://code.google.com/p/java-ide-droid/
Ramazor said:
I think you can't run it since Android is not using Java API, but Dalvik instead.
Source: http://en.wikipedia.org/wiki/Comparison_of_Java_and_Android_API
EDIT:
Also, try to find out more about this one: https://code.google.com/p/java-ide-droid/
Click to expand...
Click to collapse
Well, but if android is based in linux, we still be able to download and install the java JDK/JRE for arm devices, right?
If i am wrong, suppose that we run ubuntu inside android with ubuntu installer.... in that case it should work, because it could run java properly... i am right???
Else, could be apktool source modified to run in android???
Please, anyone reply, i am very interested in this
You can install OpenJDK on Ubuntu 13.04 small (download from http://sourceforge.net/projects/linuxonandroid/files/Ubuntu/)
I could launch Minecraft Launcher (only the launcher...). All the binaries must be compiled for ARM.
Here's an easy script pack for installing JDK to ARM Linux that I wrote
https://github.com/S0AndS0/Debian-Kit-Mods
Check the readme for how to use and enjoy
Sent from my SPH-D700 using xda app-developers app

Categories

Resources