J开发者_开发技巧ust checking out Android development very superficially, and it seems that most everyone is working in Java. Yet
Android includes a set of C/C++ libraries used by various components of the Android system. These capabilities are exposed to developers through the Android application framework.
does this mean that, in Android applications, Java is used and C++ is used:
- sometimes?
- a lot?
- almost never?
- Never: you cannot use it for applications?
Sometimes. As least as possible, only for time-sensitive code, and even then it might not be a good solution.
The standard way to make Android apps is Java.
This is because the Java code will truly be cross-platform and will work virtually across all devices. While the ndk is only supported for ARM processors as far as I know, and it's not entirely encouraged unless absolutely necessary.
A lot of people abuse the NDK to avoid using Java or the SDK. This is wrong.
You can use c++ in your android app via the NDK. It must be used in conjuction with the Java-based SDK, and is designed only to be used for performance-critical pieces of code. It has more limited functionality than the SDK (can't display UI, etc.).
Reasins for using, from the docs:
The NDK will not benefit most applications. As a developer, you will need to balance its benefits against its drawbacks; notably, using native code does not result in an automatic performance increase, but does always increase application complexity. Typical good candidates for the NDK are self-contained, CPU-intensive operations that don't allocate much memory, such as signal processing, physics simulation, and so on. Simply re-coding a method to run in C usually does not result in a large performance increase. The NDK can, however, can be an effective way to reuse a large corpus of existing C/C++ code.
Thus, the majority of users will not use any C++ code.
You could fork the Android platform and add more native code written in C++ or some other language, but code running on top of the Android platform uses Google's own p-code format which is created by conversion of Java class files.
Underneath the covers most of the OS is C/C++.
http://developer.android.com/guide/basics/what-is-android.html
Anything in Green/Or red is written in C/C++.
Not sure about the Application Framework.
What is exposed to the application developer is done through the Java SDK (the first SDK provided). Though now a more limited (from what I have been told (I don;t have direct experience)) C++ SDK is available.
I suppose you could technically write everything in C++ but I have not seen any of documentation about how to access any of these components so in effect they are hidden behind the SDK and unless somebody reverse engineers how to get at them you will be stuck with what the SDK you use exposes.
In my case, I use NDK to compile a shared, cross-platform C++ app core, and Java for the UI. The said core compiles and runs equally well on WinMobile and iPhone. The code division is about 60% core, 40% UI.
Official Google's position is that developers must use Java as a main development platform, and use C++/NDK for time- and performance-sensitive operations. Also, the only supported APIs are Java ones. I.e. Google gives you only Java API and supports only Java API. Whatever you can find on the device in native world (any shared libraries, libc etc), can and may be changed by Google or device vendors at any time without notice and so you are discouraged to use your findings.
Practically standard libc functions work and probably will work all the time, but you should not rely on any device-specific libraries or lesser-known native libraries.
精彩评论