G
G
Governor2017-01-17 19:28:57
Android
Governor, 2017-01-17 19:28:57

Is there a compiler for android to binary code?

As I understand it, Java is compiled into bytecode, which is then eaten by the JVM. It turns out Java is interpreted. Are all ANDROID applications interpreted?[1] This confuses me. I want to start developing a mob. applications, cross-platform is not interested. I'm chasing speed. Is there a compiler that would compile an android application into binary code? Without the use of virtual machines. Preferably in C++.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evgeny Shatunov, 2017-01-18
@Mr-Governor

As I understand it, Java is compiled into bytecode, which is then eaten by the JVM.

A little wrong. At the heart of the application process is not the JVM, but Dalvik . No matter what, there are sharp differences from the JVM.
Only Dalvik has already outlived its usefulness, the English wiki article tells about the so-called Android Runtime (ART) , which has been present in Android since version 4.4, and from 5.0 it completely supplanted Dalvik. You can read more about how ART works again in the English wiki . Just don't think that ELF can only contain instructions for real processors. ELF is just a container of executable code.
Now let's turn to the code.
https://android.googlesource.com/platform/art/+/ma...
This is the code for the dex2oat utility, which does the conversion from DEX to ELF.
https://android.googlesource.com/platform/art/+/ma...
Here are some explanations of the data itself and the principles of storing it in the ELF format.
This does not mean that after DEX processing, ELF will store only the instructions of the real processor. All this only says that the ELF format stores already prepared and optimized code that does not require additional compilation and optimization during its launch.
So why bother with all this? There is little difference, for a virtual instruction processor there or for a real one. Everything is already optimally assembled.
Move on.
https://android.googlesource.com/platform/art/+/ma...
This is a description of the main function of the application process.
https://android.googlesource.com/platform/art/+/ma...
Here Dalvik is created unconditionally, i.e. there is nowhere to go from him. Here is the exact location .
Further, regarding the notorious Native activity.
https://github.com/android/platform_frameworks_bas... This is the NativeActivity
source code , which is hardwired inside the Android standard library. https://github.com/android/platform_frameworks_bas... In order for NativeActivity to be able to load its low level, in AndroidManifest.xml you need to describe the meta with this name and the name of the .so file as the value. https://github.com/android/platform_frameworks_bas... This is where the low-level loading takes place. As you can see, this is done from the onCreate method of the NativeActivity itself. That is, this is the very beginning of the Activity life cycle.
In other words, you can't build a custom app directly for Android without some high-level code.
NDK gives something, but not everything, literally trifles. As soon as you need to access the phone book, find out the volume of the notification sound or the silent state, somehow interrogate the device's environment, you will have to write code in Java.
The NDK is not an application development tool. NDK is a means of implementing only performance-critical parts of a program.
Do not rush to chase speed, apparently you do not need C ++ as a development tool, because. It's not at all clear what and why you decided to use it.
Tools are chosen based on goals. Targets have not been set yet. Performance cannot be the goal, because it is only a condition for achieving only some goals.
In many cases, in mobile development, it is the use of the main programming language offered that gives maximum performance. Personally, I suggest that you first spend 5-6 months (but preferably a year or more) daily reading documentations, books and source code of both open source projects and repositories of mobile platform developers.
as an epilogue.
https://developer.android.com/ndk/guides/index.html
The NDK may not be appropriate for most novice Android programmers who need to use only Java code and framework APIs to develop their apps.

D
Denis Zagaevsky, 2017-01-17
@zagayevskiy

You have already been told about the Android NDK. I note that it is possible to write an android application entirely in C ++, without Java at all. Difficult, but possible.
Java is not interpreted. The bytecode is executed in a virtual machine, yes, but it is not an interpretation.
Then there are things like JIT(just in time) and AOT(ahead of time) compilations.
The first one compiles the bytecode into native code, on the fly, during application execution. At the same time, the JIT compiler can optimize the program based on runtime analysis.
The second compiles the bytecode into native code before execution, right during installation, if we talk about android. This takes into account the specific architecture of the device.
So you should learn some basic things first, rather than chasing speed.

V
Vitaly Stolyarov, 2017-01-17
@Ni55aN

Android NDK. Under it, native modules (in C / C ++) are assembled for the application, which are called from the Java application via JNI.
In fact, any application on Android cannot be without Java.
And first of all, it all depends on the type of application.
For example, this is a 3D game - it needs speed (especially without the intervention of the garbage collector), and things from the SDK are not particularly needed (but you can still refer to them). To do this, almost everything can be done on the NDK side
And if a regular application with lists, buttons, .., then all this should be done in Java, and only separate resource-intensive parts should be transferred to the NDK, otherwise the development process can drag on for a long time, which is simply pointless with a 10% increase in performance (well, let lists there will be faster to form and render) and significantly increased development time
Notes:
Java is not interpreted, as it is compiled into bytecode during assembly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question