Closed ghost closed 3 years ago
Yeah it would be much appreciated
Ya, Terminal IDE is really hard to use. I've tried importing their binaries to a custom folder to run, but it doesn't work
I can get the JRE 8 Runtime working on Android but it requires mounting the libraries whoch requires root
@TheDiamondYT1 please, elaborate. I've been trying to get openjdk to build for Android but it fails for shm support.
@vishalbiswas Im not entirely sure if this is correct, because this is a new phone and i had it working on the old one, but here is my script.
NOTE!!!!! Please compile and use my app to download and run the script if you are on lollipop or below. Or just go to my app repo's "download" branch and get java.zip and copy to /sdcard/.JRE4Droid then run the script in the system somewhere
#!/system/bin/sh
# Java Installer by TheDiamondYT
#
# Set DIR variable
dir=$(dirname $0)
busybox=$dir/busybox
#
# Mount / read write
$busybox mount -o rw,remount /
#
# Create java directory
$busybox mkdir $dir/java
#
# Extract java.zip here
$busybox unzip /sdcard/.JRE4Droid/java.zip -d $dir/java
#
# Create directory for java libs
$busybox mkdir /lib
#
# Umount
$busybox umount /lib
#
# Bind folders
$busybox mount -o bind $dir/java/lib /lib
#
# Mount / read only
$busybox mount -o ro,remount /
#
#
#
# (The Android Shell doesn't like empty lines)
I originally got those commands from (this app)(github repo)
@TheDiamondYT1 I'm more interested in how you compiled the files in java.zip. It will allow us to create a package for termux.
@vishalbiswas I didnt. I got the compressed archive from the repo in my previous comment. For some reason this time around i cant get the correct permissions on the java binary.
Is this happening? - referring to javac in termux? If it is ace, but if not is there some other solution to compiling java files and allowing them to run within the termux environment? Sorry if this question has been asked and answered elsewhere I found a few things but nothing really covered it fully... thanks!
If we can get a JRE working maven will easily run
Done.
However, there are some interesting things to note:
java
returns "No such file or directory" unless you do (from the top level directory)
$ mount -o remount,rw /
$ mkdir /lib
$ mount -o bind lib /lib
Compiling openjdk fails at shm support. That's the roadblock I'm stumped at.
@vishalbiswas Try https://github.com/pelya/android-shmem
@TheDiamondYT1 already tried. That implementation isn't complete. Semaphore functions are missing which are required for ipc
http://openjdk.java.net/projects/mobile/android.html This documents how to cross compile OpenJDK 9 for Android. But I just can't get the build to succeed.
If this works that would open a new world of possibilities.. @vishalbiswas Do you still remember what the error is from the build?
@lynnard undefined reference to SHMLBA and semop ------------------------------EDIT------------------------------- Exact errors:
hotspot/src/os/linux/vm/os_linux.cpp: In function 'char* shmat_with_alignment(int, size_t, size_t)':
hotspot/src/os/linux/vm/os_linux.cpp:3391:35: error: 'SHMLBA' was not declared in this scope
if (!is_size_aligned(alignment, SHMLBA)) {
^
hotspot/src/os/linux/vm/os_linux.cpp: In function 'char* shmat_at_address(int, char*)':
hotspot/src/os/linux/vm/os_linux.cpp:3427:33: error: 'SHMLBA' was not declared in this scope
if (!is_ptr_aligned(req_addr, SHMLBA)) {
^
hotspot/src/os/linux/vm/os_linux.cpp: In static member function 'static int os::loadavg(double*, int)':
hotspot/src/os/linux/vm/os_linux.cpp:5454:10: error: '::getloadavg' has not been declared
return ::getloadavg(loadavg, nelem);
^
hotspot/src/os/linux/vm/os_linux.cpp: In function 'timespec get_mtime(const char*)':
hotspot/src/os/linux/vm/os_linux.cpp:6082:13: error: 'struct stat' has no member named 'st_mtim'
return st.st_mtim;
semop and other semaphore functions are available as a syscall. I'm using them.
Managed to get past these errors with some hacks. Now the build fails for fatal error: langinfo.h not found
Why is android so difficult
Terminal IDE uses a different approach, rather than compiling the native package for java
command via c/cpp, spartacus rex uses an internal classLoader which uses android's dalvikvm API "dalvik.system.DexClassLoader" with reflection and a custom dexClassLoader class, ALL in java, although you need to check for lots of errors and exceptions. I don't have experience with java reflection APIs so can't do much. If you guys have time, please have a look at the two java classes from Terminal IDE:
java.java and dexClassLoader.java,
Please have a look at this method,it requires a script to invoke and is abit unsafe but I hope someone can work around with it and we'd have a working java classloder to load and run most of the JDK toola like jar,javac,javap etc.
@Harshiv-Patel Reflection? So, does that mean it has a large performance hit? OpenJDK 9 will have native support for Android. In fact, preliminary code for compilation for Android has already been added. I'm waiting for them to tag the next development release so that I can update the disabled openjdk package in the repo.
Terminal IDE does lag a little(~1500-2000ms) for the first time, when I load the tools.jar(~1.8MB, stripped, contains dexed classes from original tools.jar+resources for jar
,javac
and some other tools from JDK so it would make a difference when working with larger libraries I guess. Native support for Android sounds really good, it would be great.
With reagards to running java code on your phone through termux, this seems relatively easy to set up. I used jack (apt install jack
) to compila java code to a dex, and then used dalvikvm to run it:
mkdir -p dex
jack --output-dex dex $(find -name *java)
dalvikvm -cp dex/classes.dex <name of your class>
So far I've only tried some really simple code, I'll experiment to see how far this works 😄 (requires no root btw ;))
@vishalbiswas I have got the JRE 8 working on Android by downloading the files from a guys Dropbox folder. He claims its straight from the oracle website but the folder structure isint the same. It requires root and you have to mount some stuff but it does work
@vishalbiswas , Did you solved that header file not found error? We can already load the (dexed)Java classes via dalvikvm
as suggested by @MarijnS95, and most of the JDK tools are written in java, so I think that we can just dex the classes from JDK's tools.jar and load them via dalvikvm
, mostly we do not need the entire Java SE JRE 8(not sure though), JDK tools are sufficient for most of the android projects.
@TheDiamondYT1 , root requirement and remounting method can be unsafe for noobies(like me) and we need a package that can be added to termux via apt install package_name
.
I know I was just sharing how I can run jar files
The latest source already deals with these issues, but there are others. Zero interpreter on arm has real bad performance
Android already has it's class loader optimized by AndroidRuntime, all they needed was to replace native Linux APIs with those of android's native API, using an interpreter is really bad idea when you can just dex your java classes as most of the java SE libraries are in java. Anyway what java
command does is to load&run code from some archive which dalvikvm
does for us, we can then load the dexed tools.jar and other Java SE libraries to be used with android and load them via dalvikvm
. I've already dexed some tools like javac and jar, if I get success with javah,javadoc and javap, I'll post the scripts and dexed tools.jar for anyone interested to try out and test ,in next weekend.
Zero interpreter is only needed for arm devices. x86 devices can use the client jvm. Does dalvik has the complete java api? What about running apps that require a jdk? I want to ultimately be able to run gradle and build Android apps on Termux as if it was a real Linux box.
dx
and should work on android that way, I guess :smirk:So the JDK (which also happens to include the JRE)
@vishalbiswas I've been fiddling with that for the past two days, and it turns out to be pretty simple (and is able to compile standard java applications as well, as mentioned in my previous comment). I only have apps that consist of a couple java files, some native C++ code through jni, and a simple makefile to invoke the compiler/packer. Nothing fancy, so if your apps include a lot of configuration with gradle, custom build tools etc, this might be more difficult ;)
The only thing I'm still working on is seamlessly installing the application and figuring out how to debug it (see the logs, for instance). But I'll save that for a more appropriate topic. Nevertheless, here's a rough outline of the steps involved:
R.java
file from resources with aapt
(I haven't tried this as I don't have a layout or other resources 😛).classes.dex
using jack
.aapt
, to which the AndroidManifest.xml
file is added.classes.dex
and other resources to the apk, either with aapt
or zip
(eventually your native library, if you're working with JNI).apksigner
(special termux version that does both at the same time, standalone zipalign exists though).
termux-share
with the filename of the final apk.@MarijnS95 lastly, we combine all these steps into a bash script and some extra features like
$?
may be ?) if any error is there than abort the process..project.properties
file in eclipse)
and add others.Porting the entire JDK to Android and then using Gradle is something that takes lots of experience and time AnD more space on device, It would take some time to write and debug the script, I'll probably give it a try.
Edit: That @joakim-noah has already built a script for native apps I guess.
I made a simple script to compile Android apps
I've dexed some JDK tools and got them working. 'java' command isn't the full fledged desktop version, it's just a plain dumb class loader. Rest of tools are almost original. Running them on Samsung's Marshmallow Stock ROM may give errors, haven't tested yet on android 6+, do give it a try. Zip file: JDK_tools.zip
I've dexed some JDK tools and got them working. 'java' command isn't >the full fledged desktop version, it's just a plain dumb class loader. Rest >of tools are almost original. Running them on Samsung's Marshmallow >Stock ROM may give errors, haven't tested yet on android 6+, do give it a >try.
Did anyone looked at the zip ? It's about a month or so, anyone please look at it.
I'm using a Nexus 6p on 7.1.2.
I just copied into ~ and chmod +x on java. Ran ./java from the ~/JDK_Tools:
java.lang.ClassNotFoundException: Didn't find class "com.hrp.java" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib64, /vendor/lib64, /system/lib64, /vendor/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:380) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) Exception in thread "main" java.lang.ClassNotFoundException: Didn't find class "com.hrp.java" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib64, /vendor/lib64, /system/lib64, /vendor/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:380) at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
Note 4 on 6.0.1 java -v -jar kafka_2.11-0.10.2.0.jar kafka ODEX_FOLDER : /data/data/com.termux/files/usr/var/android JAR/DEX FILE : kafka_2.11-0.10.2.0.jar CLASSNAME : kafka My path is: kafka_2.11-0.10.2.0.jar Output file will be /data/data/com.termux/files/usr/var/android/kafka_2.11-0.10.2.0.dex Failed loadDex 'kafka_2.11-0.10.2.0.jar': java.io.IOException: No original dex files found for dex location /data/data/com.termux/files/home/kafka_2.11-0.10.2.0/libs/kafka_2.11-0.10.2.0.jar Native lib path 0: /vendor/lib/ Native lib path 1: /system/lib/ DexClassLoader com.hrp.dexclassloader@3ea08f7: findClass 'kafka' Now searching: kafka_2.11-0.10.2.0.jar java.lang.ClassNotFoundException: kafka in loader com.hrp.dexclassloader@3ea08f7 at com.hrp.dexclassloader.findClass(dexclassloader.java:258) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) at com.hrp.java.main(java.java:90) Suppressed: java.lang.ClassNotFoundException: Didn't find class "kafka" on path: DexPathList[[zip file "/data/data/com.termux/files/usr/bin/loader.jar"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:504) ... 2 more Suppressed: java.lang.ClassNotFoundException: kafka at java.lang.Class.classForName(Native Method) at java.lang.BootClassLoader.findClass(ClassLoader.java:781) at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) at java.lang.ClassLoader.loadClass(ClassLoader.java:504) ... 3 more Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available Usage : java -v -jar [List of Jar files] CLASSNAME $
I was able to get Java working.
This is all in the root user space tho. I'm sure its possible to get it to work outside of it.
As a side note:
I'm using a Nexus 6p on 7.1.2.
Note 4 on 6.0.1
Sorry Guys, I haven't tried to run it on Android Lollipop 5.1.1+, it doesn't seem worth trying as Open JDK would be available on android in future. Android requires dex files to run them, usually "classes.dex" is required, you can't run normal java class files or ".jar" files containing classes, they need to be "dexed" first, using dx tool.
There are some Android apps which build quit well on device with the tools we have at our disposal today! Some of these apps are quite complex. Others are very entertaining. While others are very simple, mere fragments of apps that are complete in themselves. A new repository has just been opened with instructions and scripts that build Android apps on device (a smartphone).
Have you ever wanted to build your own Android application? Now you can easily compile these selected applications that have already been successfully built and installed on device.
Enjoy this project! Your feedback is welcome at either the wiki, the issues pages or through the code itself.
ok here https://github.com/sirmordred/JarClassLoader it can be beneficial for you guys
Info: i have a dx tool which works on android directly (compiled from latest dx sources) and have ecj compiler which works on android directly (latest version ecj)
the big disadvantage of ecj compiler is that it needs "androd.jar" as bootclasspath (34mb) (and it must be placed somewhere) if anyone have a standalone ecj compiler sources? maybe we can fuse both of jars (android.jar and ecj.jar) and create standalone android java compiler and handle that disadvantage
the big disadvantage of ecj compiler is that it needs "androd.jar" as bootclasspath (34mb) (and it must be placed somewhere)
You can place it in your internal storage somewhere, android.jar only requires to have read permission. I've put them in "~/storage/external-1/"
and it works fine and then I added it's path to bashrc
export droidjar=path/to/jar
this can save some megabytes as long as it's only required to have read permission.
I think we could place all jdk9 libraries and other such files like this, it would reduce the memory footprint considerably.
Info: i have a dx tool which works on android directly (compiled from latest dx sources)
- which version?
1.12
or higher?- does it work with android.jar API level 22 or higher?
Yeah its 1.12 version And yeah im on marshmallow(23) its working great
for the ecj compiler, im currently trying to pack them, i mean packing android.jar and ecj.jar and create standalone aar library, i put into assets and compiler will copy from assets into application's internal folder (data/data/com.xyz.. ) via getApplicationContext,getFilesDir.getAbsolutePath
@AravK Java, javac and jar available through:
Now you can install Arch Linux in Termux 📲 on your smartphone and tablet. More information at https://sdrausty.github.io/TermuxArch
Java is available through https://sdrausty.github.io/TermuxArch/ Just follow the easy install instructions at https://sdrausty.github.io/TermuxArch/docs/install or simply copy and paste the following into your Termux window:
cd && git clone https://github.com/sdrausty/TermuxArch
./TermuxArch/setupTermuxArch.sh
Read more about the Arch Linux package manager at duckduckgo arch+linux+install+java+pacman.
To install java run pacman -Syy; pacman -Su; pacman -S jdk8-openjdk
Please add the Java compilers (java, javac, jar, etc.)