.JAR + Android? - android

I just purchased an Archos 5 and I'm wondering if it is possible to put a .JAR file on it and use it as an application. I read somewhere that it is possible but saw somewhere else that it wasn't. If it is possible, is there anything I have to do differently? Or do I just run it like I would on my computer?

Android devices run Android applications, not ordinary Java applications, and the ARCHOS 5 is no exception. While Android applications are written in Java, an ordinary Java desktop application uses a different GUI framework than Android offers.

As said by CommonsWare, although Android apps are written in Java you can't actually run Java code(s) on Android devices sinces Android actually has the Dalvick Virtual Machine as compared to the Java Virtual Machine (which runs the Java Bytecode)
If you still plan to use the logic of your jar file and run it on your device, you may reference it in an android app and use the feature(s) from it.
But be awared, that this mostly depends on what your jar file actually does and how it is packed. You may need to, otherwise, repack it to suit if for using in it Android apps.
Bottom line is, however, you can't run the jar files directly on the device!

Related

Where is java command located in Android?

I got my android phone rooted and I'm aware that the / doesn't contain the familiar linux /.
Is there a java command? Where is it located? I don't find one in /system/bin.
Is there a java command?
No. Such a command isn't shipped with stock Android images.
Where is it located?
It shouldn't exist on filesystem. What makes you think it should be there?
I don't find one in /system/bin.
You might consider installing any Java programming app for Android to have JDK/JRE installed. In this case the command will be located in the app's sandbox, not /system/bin.
Android does not use Java at all, at runtime.
Android runs programs that have been written in the Java language. Those programs are not compiled to Java bytecodes and will not run on a JVM.
Android executes Dalvik bytecodes. Until somewhere around Android 4, it used a virtual machine called Dalvik, to execute these bytecodes. Now it uses fantastically more complex virtual machine called ART.
Sorry. No Java.

Is it possible to run java application on android through openjdk

Disambiguation first: question is not about developing or compiling with openjdk code that would be run on dalvik in production. It is about using oracle runtime on android environment.
I'm using java for running small desktop utility application. I have no experience in Android and iOS development and I'm curious to which extent my classic java skills may be transferred to the mobile field.
I've googled couple of methods for running java application on iOS embedding runtime inside the application package. Android has its own partially incompatible and slow java virtual machine. It still is better than nothing, but I'm curious if it is possible to run application on genuine hotspot(openjdk) virtual machine. Android as well as iOS have the ability to run native code. May this ability be exploited to use third-party (non dalvik) jre on android?
I'm not interested on google play market so restrictions from it, if there are any, may not be taken into account.
Rooting is also possible since I'm going to write tools for myself. I would prefer methods that would be easy for installing. Like putting some package files and editing couple of options. And not build my own android distribution like CyanogenMod.
Without rooting the device, I don't think there is a way to do it.
Apparently, see http://openjdk.java.net/projects/mobile/android.html
The instructions are slightly out of date, I managed to do some hacking and get it to build though. Not sure if it runs yet

accessing android os root files

i have the following doubt:
i have read that android os is based on linux, and i imagine it may have the same structure that ubuntu (in terms of file configurations: /root, /dev, etc).
so, is it possible to run an application written in C in android? just as it is possible to do in ubuntu? if so, how can i do that?
also, how can i get access to the root files through an android application (written in java)? and how to get access to the behavior of the os (in terms of interruptions for example)?
thanks in advance for your answers.
gus
Basic answer: Running a C app on Android isn't supported, except through the Native Development Kit (NDK).
You can't get access to the root files except by rooting a phone.
You can get access to some OS behavior through the API. Basically, if it's not part of the API, you can't access it.
The Android OS is based on Linux, but it's an OS, not a windowing server like X or a desktop environment like Gnome or KDE.
You may run C and C++ code on android using NDK. You may use also QT framework. But code is runing in virtual machine named Davlik. Android have root acount , but it is default not available for user. Therefore, access to directory is dependend for chmod.
If you would like read about access to low level in android:
http://www.phrack.org/issues.html?issue=68&id=6
And about architecture this system:
https://developer.android.com/guide/basics/what-is-android.html
You can run programs using Runtime.exec. As an example, you can see Terminal IDE which runs many different programs including ssh, vim and bash. It's also open source so you can learn from the code. You will probably have to include the executable as a resource or asset and then copy to a local directory, grant execute permissions, then run with Runtime.exec. You still have limited user permissions as your app runs under a restricted account unless the device is rooted and you request root access.
an android smartphone/tablet works with an Arm cpu, not a x85. the architecture is different.
but you CAN run a C application in android if you cross compile it for arm linux. or you can use a c compiler inside android device. people ported c compiler to android. you can try C4DROID and in android market. but you can only run compiled program in system memory because of android permissions about sd card.

Use Android framework from console apps

I have a feeling I know the answer to this question, but I figure I would see what SO had to say.
I'm hoping to create a console app that can take an .apk file and extract metadata (such as version name/version number). I'm able to use PackageManager.getPackageArchiveInfo() from my Android app just fine, but I'd need to be able to call it from the command line. However, the classes in the android.jar appear to just be stubs, so it doesn't end up working.
Does anyone know of a way to do that?
For apks for which you do not have the signing certificate, you cannot access the contents of the apk beyond seeing that the contents exist.
As you noted, the android.jar is stubs. This is because the android system relies on native code which is designed to run on ARM processors and (probably) wouldn't run on your system. So, they package stub versions of all the java code and the only way to 'run' the actual library is to be executing in a vm with a full version of the android.jar, which would be an ARM environment ( a real handset or a emulator).
There could be ways to setup a 'console' app to do this, but it would have to be communicating with an Android VM to get a working version of the android.jar. I'm guessing that might be more effort than you'd want to sink into this.
I was able to open the .apk file and view it's contents (including AndroidManifest.xml) with WinZip...
'Hope that helps...

Can Android use standard built JAR files?

Im pretty sure the answer is no, but im using the new IntelliJ EAP version and have a project i worked on a while back which was just written against JDK 1.6 for an applet based application.
However now i could see how it could be useful in an android app that im interested in creating.
Do i now have to re-write all the code/tests again targeting the android sdk or can i just drop in my existing JAR file and only use android for the UI layer.
Its just android seems to make testing WAY harder than it needs to be, and i have alot of existing tests written and working, if it wasnt so hard to just write a quick unit test (standard Junit #Test style) i wouldnt mind porting, however i just dont get the whole instrumentation thing, as i dont need a UI at the moment...
Anyway so back to the point, can i use my existing JDK built code in an android app?
No!
Android uses the "Dalvik" VM from project harmony which uses a different set of bytecodes which are incompatable with the standard Java JVM bytecodes.
This was done both to optimise the VM for opreration on mobile platforms, and, probably more importantly to try and avoid Copyright and patent disputes with Sun and now Oracle.
More info here
However there is a tool called "dx" which can perform the conversion in the dev environment.
Okay, let me clear up your confusion.
Jars are converted to dex Dalvik bytecode during the compiling process thus you can use 3rd party jar libs.
However, in your case because its applet which has a different application lifecycle yes you might have to re-do it to get it to work in android.
As far as testing instrumentation is used on all java mobile development even JavaMe. It basically means that the Junit tests are run in the emulator or device but in android's case you are using android mock objects to test android specific things.

Categories

Resources