I’ve recently heard that DL4J is usable on an Android device which I am interested in doing. Just to be clear with what I am trying to do: on Android there is a Linux emulator known as Termux which is basically a sandboxed virtual machine type of setup that gives an Android device a Linux command line environment. I have a version of Java 9 installed on this sandboxed “distro” that I code in using the vim feature and I’d like to do some projects where I write source code, train networks and run the networks on new data - all on my mobile device. I have standard Maven installed and running on this setup. Since I understand it is possible to train and run networks with the latest version of DL4J on Android, I assume native code of the math engine that powers DL4J has been prepared to run on arm processors found in Android tablets.
Would you please tell me if it sounds possible to write DL4J code, train and run neural networks on an Android device as described above using only maven in a command line environment without touching Eclipse or other IDEs? I am willing to step through any recommended installation process to definitively answer this question but I figured this might require a more customized approach which is why I’ve decided to ask here. Thanks for any help anyone can provide.
Thanks for the link. Now I saw that there was mention of requiring access to a Raspberry Pi. I unfortunatly do not have one. How crucial is it that I have this? Do I need to have a rooted device in order to install DL4J on my Android and use it? I also saw mention of something called LineageOS in the link’s material and I am not familiar with this (it sounds like some sort of OS to replace Android). I was hoping the installation process would just involve certain dependencies in Maven’s pom file and maybe some less commonly used settings for Javacpp but my glance at the material seems like this is a rather involved process (regretfully I am not at an advanced level of Linux tinkering so my apologies for any novice concerns above). Thanks and I’d welcome any of your thoughts on the above.
@LobsterMan the raspberry pi is just what I used to run android. LineageOS is a customized version of android that people use in rooted phones. Since most android devices are also ARM (alongside the pi) it’s just an easy way to develop/prototype android libraries.
Just using the JDK I mentioned from termux in the docs should be enough.
Ok, that’s a relief that I don’t need the Pi or the alternative OS. Would you then please direct me to where I should begin with installing DL4J on the Android with Termux? The jdk deb files you provide in the link look like the jdk I have installed from my previous work.
@LobsterMan there’s no “installing” dl4j. It’s a software library. If you mean “installation of a development environment” then that involves the JDK linked from the documentation and setting up the maven build tool to run in termux based on maven using the JDK you setup within termux.
What I meant was (just to be sure I’ve understood things correctly):
What do I write in my Maven pom file as a dependency to summon DL4J in my project (since I’ll be working purely in Termux I won’t be using/installing an IDE)?
Is the only Maven line necessary to build a project using DL4J in Android Termux simply what was mentioned in the link (i.e. mvn -DargLine=“org.bytedeco.javacpp.pathsfirst=true -Djavacpp.platform=android-arm” -Dorg.bytedeco.javacpp.pathsfirst=true -Djavcpp.platform=android-arm clean test)?
Is the last thing I’d need to do be simply to alter my bashrc file to contain the 4 export commands given in the link?
Once items 1-3 above are done (and assuming no build errors), I should be ready to begin programming/working?
Would you please provide me with a link of where the standard dependencies are found on the DL4J website that I can use in Termux on Android (there’s a lot of material on the website and I want to be sure I use the right things)?
Do the “export” commands from the link you gave me (i.e. export JAVA_HOME=/data/data/com.termux/files/usr/lib/jvm/openjdk-9) go in the bash rc file? They looked to me like modifications to bash rc I’d seen in the past which is why I ask.
This will use the cpu backend (which is what you want on android). As long as you set the android classifier (android-arm64 or android-arm in this case) when running maven you should be setup with these dependencies.
Ok, so I tried to build from the provided pom file but I got the following error:
T E S T S
Error: Could not find or load main class org.bytedeco.javacpp.pathsfirst=true
Caused by: java.lang.ClassNotFoundException: org.bytedeco.javacpp.pathsfirst=true
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD FAILURE
[INFO] Total time: 47.516 s
[INFO] Finished at: 2022-05-11T02:51:14Z
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project dl4jTesting: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: The forked VM terminated without saying properly goodbye. VM crash or System.exit called ? → [Help 1]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] PluginExecutionException - Apache Maven - Apache Software Foundation
The maven command I used once my pom file was finished was: mvn -DargLine=“org.bytedeco.javacpp.pathsfirst=true -Djavacpp.platform=android-arm” -Dorg.bytedeco.javacpp.pathsfirst=true -Djavcpp.platform=android-arm clean test
@LobsterMan that just tells me you’re not setting up the command line properly. Because of the way you’re passing the arguments it thinks the system property is a class. I would step back and understand how java parses arguments independent of anything to do with termux. Here’s a fairly good overview: Java System Properties - HowToDoInJava
From the looks of it you have a missing -D in there, try this:
mvn -DargLine=“-Dorg.bytedeco.javacpp.pathsfirst=true -Djavacpp.platform=android-arm" -Dorg.bytedeco.javacpp.pathsfirst=true -Djavcpp.platform=android-arm clean test
Wonderful. Is there a sample program I can try running, perhaps something on GitHub to start off with?
Also, I noticed that packaging my uber file results in a uber jar that’s over 1 Gigabyte in size. Are there any dependencies that can be excluded that aren’t used in doing just deep learning analysis to make this smaller? If not it’s ok, but I was taken back by the resulting jar file size (and it was just for a “Hello World” program).
Specify -Djavacpp.platform=android-arm or android-arm64 to reduce the dependencies down to just the dependencies you use. I linked to our maven entry level project already. That contains a simple neural network for you to run. Find that again here: