Native android development without any java?
Asked Answered
B

2

8

I have recently became interested in android development however the biggest road block for me has been even the mere thought of using java to develop for a mobile phone. I do not have confidence in java's ability to make possible a high performance game with a consistent frame-rate and I do not want my program to stall during garbage collection. I am a C/C++ programmer primarily (I also use assembly if needed) who has programmed in java before and have from past experience found that due to the fact that I have more control over various aspects such as memory allocation I can optimize my program further and I general prefer low level programming.

I have already read questions and answers here and they suggest using the NDK, now I have looked at the NDK and it still introduces the bloat of java. Basically if I understand correctly what I would have to do is write some short java code that would call my native code. The problem with this java is still running in the background therefor consuming valuable ram which mobile phones lack of and java would still need to launch and even on my computer java takes a little bit to start-up and given the fact that I am programming for a mobile phone which I am sure has a much slower cpu it will take even longer. I have found that java and low memory footprint to be a oxymoron and do not want java running in the background idling using ram. I want this program to be accepted in the official application store which I believe is know as "google play". Given the fact that I am programing for such a resource limited device I am very surprised that java is the recommended way.

Bearskin answered 23/11, 2014 at 16:37 Comment(10)
When you said "resources limited device", did you check how much RAM and processing power most Android Smartphones have nowadays? Also, did you check open libraries that allow you to create games in Android and actually tried doing so? Sorry but your question boils down to "I'm a C++ Developer and I want to develop an Android game but Java is too inefficient memory wise. Smartphones are slow and clunky so I don't think they can handle Java."Yecies
You prejudice against Java, which is very different on Android than on the desktop, does you no favours. My phone is more powerful than my desktop and Java causes me no problems whatsoever.Beneficial
Your concerns are not invalid, but fortunately there are some optimizations, such as the fact that the vm is not "started" but simply forked off a running instance. You can write a "native activity" where you supply no java code, but plenty supplied by the system will still be utilized, both in your process and in those it talks to.Priapus
@Yecies I admit to being a bit behind in regards to mobiles (phones and tablets). I have done some preliminary research and hit a roadblock on how I could use only native code hence this questions existence. Yes you are correct in what my question boils down to. I own a raspberry pi and a beaglebone black both of which if I understand correctly has similar hardware to what would be found in a modern mobile phone. It is not as fast as a modern desktop/laptop but with good programming practices I can still make nice programs for it. That is what I wanted to do for android mobile phones.Bearskin
@Beneficial What are the specs on your desktop? I have some old computers that I am sure could be beaten by a mobile phone however that is not a fair comparison as the desktop is much older than the phone.Bearskin
@ChrisStratton That is good to know I thought for each application a java process would be created. I know of some programs such as rxvt-unicode and emacs which can act as a server sharing resources. I guess in this respect it is not as bad as I thought but never the less my program would still be using ram which could be avoided if my program just as most desktop oriented programs run an executable.Bearskin
A modern phone is several times faster than a raspberry pi (which uses a set top box chip so only the video decoder hardware was supposed to have real work). Look at how zygote works with fork (but not exec) and linux copy-on-write behavior. But going pure native would involve wiping away android and building your own userspace under the kernel.Priapus
@Bearskin Quad core, 1.8Ghz, 2GB RAM. My phone is quad core 2.4GHz with 3GB and an Adreno 330 GPU. BTW, most modern phones are significantly more powerful than a Raspberry pi and a Beaglebone (they not even the same league).Beneficial
@ChrisStratton I read a few articles about zygote and it was an interesting read. I must say that is a pretty clever solution. I can tell that memory conservation was a goal of zygote however it does seem like a lot of work just so people could use java.Bearskin
@Beneficial wow I did not know phones go that fast. My guess was that the average phone would have a 1ghz arm process single core 512mb of ram. It looks like I am off quite a bit.Bearskin
B
3

First, I believe you are worrying too much about the performance of java. You cannot avoid "java running in the background", because most of Android is implemented in Java, anyway. And the resources of smartphones are not so limited.

Now if you really can't stand java, you can use a NativeActivity: http://developer.android.com/reference/android/app/NativeActivity.html And make your game with OpenGL.

See also that question: 100% Native C Application on Android?

Blanket answered 23/11, 2014 at 16:45 Comment(1)
I was not aware of that question however when reading it although it appears that the goal of completely avoiding java was not successful as in it is not possible. However the question is three years old, has anything changed or is there really no way to avoid java completely as in I will have to use the JNI or native activity?Bearskin
G
0

This is now possible using projects like rawandroid, although it generates APKs and nowadays Google Play only accepts AAB format. So it's necessary to use bundletools in order to generate an .aab file instead.

Ever wanted to write C code and run it on Android? Sick of multi-megabyte packages just to do the most basic of things. Well, this is a demo of how to make your own APKs and build, install and automatically run them in about 2 seconds, and with an apk size of about 25kB (with API 26). API 30 (Android R+) is unfortunately at 45kB to support ARM64 + ARM32.

Also, just to give some more context, while in the past using C/C++ code required interfacing with java for most things, now the opposite is true for some cases like Vulkan rendering, where you can't actually use Vulkan directly from Java/Kotlin and need to wrap it instead .

Gomel answered 23/5 at 19:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.