Why shouldn't an Android application be written in C / C ++ because you just prefer to program in C / C ++?

Updated (for clarity and to reduce ambiguity):

I'm going to start working on Android apps. I planned to write in C ++ using the NDK (since I have more experience in C ++ and I prefer it in Java), but on the Android NDK page:

you should use only NDK if it is important for your app - never, because you just prefer to program in C / C ++.

I got the impression that you should use the language that you prefer, if it is suitable for work. Can someone explain why it is so strongly not recommended to use C / C ++ for Android development?




Original:

I'm going to start working on mobile applications, in particular, android, which is the OS of my current phone, and I was wondering if writing an application in C ++ (or at least the kernel, and then wrapping it in Java) is an acceptable option.

In some ways, I am an IT specialist who took 3 courses in C ++ (input, intermediate, OOP, and I take the STL course in spring) and only 1 Java course (intermediate). Because of this, I like C ++ more and prefer it to Java. I came across the following Android NDK page:

Using native code on Android does not usually result in a noticeable increase in performance, but it always increases the complexity of your application. In general, you should only use NDK if it is important for your app - never, because you just prefer to program in C / C ++.

  • I got the impression that you should use a language, a suitable job, as well as one with which you are familiar
  • Maybe I want to transfer the application to another mobile platform, such as iOS, which supports C ++, but not java
  • Although Java is a high-level language and therefore should be faster, I feel that development will be slower because I would retrain almost everything (since I took only one class per language)

Any advice would be greatly appreciated.

ps: many answers to this topic are taken from several years ago, and there are very few answers to subsequent answers that mention the NDK, which allows you to develop full-fledged applications on Android 2.3 and newer.

+78
java c ++ android
Dec 08
source share
8 answers

Think of it this way. You have the opportunity to use the Java SDK to create a full-fledged working application that uses 100% of the available APIs for developers. You cannot do anything with the NDK, which cannot be done with the SDK (in terms of the API), the NDK provides better performance.

Now look at it in reverse order. If you decide to write the application 100% in the NDK, you can still write a fully functional application, but you are limited in the number of infrastructure APIs that you can access. Not all Android frameworks may be available at their own level; most APIs are Java only. Not to say that you need all the APIs for YOU , they are not available in the NDK, but nowhere near the ALL APIs are displayed.

In addition, NDK introduces platform-specific code that extends the size of your distribution. For each device architecture that you intend to support, your own code must be embedded in .so files (one for armv5, armv7, and x86), all packaged in the same APK. This duplication of executable code makes your application 3x in size (i.e. Bold Binary) unless you take on the task of creating separate APKs for each architecture when distributing the application. Thus, the deployment process becomes a little more useful if you do not want your APK to increase significantly.

Again, while none of this prohibits you from doing what you choose, it indicates why Google describes Java as the β€œpreferred” method for most of your code and the path of least resistance. I hope this sheds light on why the documentation is worded as it is.

+97
Dec 08
source share

If you are going to develop only one application in your life, use the NDK.

If you aim to learn Android development with the goal of developing more than one application throughout your life β€” and want to be able to properly support all of them β€” you are more likely to do better in the long run if you learn Java and use the Android Java SDK.

+21
Dec 08 2018-12-12T00:
source share

King programmers use C ++ for their game logic. And they seem to be well versed in their turnover.

In my experience, C ++ is for problem solving, and Java is for troubleshooting. I like any language, but C ++ is pretty useful when you write good code. However, it may take a few minutes of magic to get there.

You could also recommend C ++ for data scientists who would normally do their job, like Python or R. C ++ could do the same with good or not better performance, but you just need to be a genius in the language. That's why I never recommend C ++ to anyone who wants to do this - I would just make it clear what they want.

+6
Aug 10 '15 at 14:17
source share

The most important consideration is that compiled Java code will work on all Android devices unchanged, while native code will need to be compiled for all target platforms.

The general intention for Java and Android is that you write most, if not all, of your application in Java, and use native things only when there is no other choice ... therefore, everything about writing an application is suitable for this in Java .

By writing in Java, you will save yourself from many difficulties in connecting the native world with the Java world.

In addition, you will be of great service if you take a step and learn Java. Not only will your Android application be better for him, you will expose yourself to a completely different approach to OO, and you will become the best programmer for him.

Add to this the fact that you will bypass a bunch of security risks by writing in Java.

In my opinion, it is not difficult to use Java.

+3
Dec 08
source share

I found this interesting article from: http://betanews.com/2014/07/22/why-c-is-the-perfect-choice-for-modern-app-development/

C ++ was created specifically for platform independence and, as such, is found on every operating system. Your typical mobile user may know that Android applications are written by Java and iOS applications in Objective-C, but many do not know that your devices have more C-C ++ code than anything else. C / C ++ supports most of the technology of small devices (for example, a kernel that interacts with equipment, as well as typical runtime libraries) and telecommunication networks that allow these devices to be used. More importantly for the development team, there are C / C ++ interfaces and libraries for everything you need to do on any device and platform. The Android NDK Toolkit is a great example of the full C / C ++ support that was originally added for game development teams so that they can get the most performance out of the device, avoiding Java and Java Java Dalvik, the virtual machine on which Android code Java is running. It has been improved regularly to activate all Android services.

+3
Jan 17 '16 at 3:02
source share

I would say use java for the main application. But if you have C ++ code, you need a port or some library that you need that is efficiently implemented in C ++, and then use ndk for these bits

+2
Oct 26 '13 at 10:48 on
source share

I see no reason not to use C ++ for normal Android development. If you have a lot of experience working in C ++ and with a complex OS such as Windows or any other, then you can quickly grab Android and not be as complicated as other OSs. learning Java or working without training, it will be more unpleasant and difficult!

+2
Jun 19 '15 at 3:41
source share

The SDK is already built on top of the NDK. If you use the NDK, you will have to write the same code that the SDK already provided. This is a remake.

This is similar to java coding in native code, while you have an API available for the same task.

In short, you want to reinvent the wheel.

0
Jun 29 '17 at 10:12
source share



All Articles