Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Native - When to use 64-bit NDK?

According to NDK's official download page: http://goo.gl/vI7Oek there are two target versions:

  • x86 Target
  • x64 Target

And I was wondering ( as a newbie in the NDK stuff ), does this mean I should use the x64 NDK when compiling an application for devices equipped with x64 processors?

And if I need only one ".apk" file, how to make it contain both x86 & x64 builds? ( if possible of course )

like image 530
Alaa Salah Avatar asked Oct 17 '14 11:10

Alaa Salah


People also ask

Which version of NDK should I use?

You should always be using the latest NDK for the best behavior (possibly N-1 if there's a bug in the latest stable, but that won't be the average case). It does sound like your APP_PLATFORM is set to a newer platform than the device you're trying to run on. APP_PLATFORM is a minimum supported version.

Why do we need Android NDK?

The Android NDK is a companion tool to the Android SDK that lets you build performance-critical portions of your apps in native code. It provides headers and libraries that allow you to build activities, handle user input, use hardware sensors, access application resources, and more, when programming in C or C++.

Is NDK necessary for Android studio?

The Android Native Development Kit (NDK): a set of tools that allows you to use C and C++ code with Android. CMake: an external build tool that works alongside Gradle to build your native library. You do not need this component if you only plan to use ndk-build.

Which is better NDK or SDK?

It also provides all the common APIs used for Android apps. It is important to mention that some Android Apps use NDK to achieve a specific functionality. That makes NDK and SDK somehow complementary in some cases. However, Android still recommends to only used NDK if you really need to.

What is the Android native development kit (NDK)?

The Android Native Development Kit (NDK): a set of tools that allows you to use C and C++ code with Android. CMake: an external build tool that works alongside Gradle to build your native library.

Why is NDK not supported by my Android build system?

This is often the case with third-party dependencies that are not Android-specific, such as OpenSSL and libbzip2. Build system maintainers looking to add native NDK support to their build systems should instead read the Build System Maintainers Guide. As of NDK r19, the toolchains installed by default with the NDK may be used in-place.

How do I compile 64-bit Android with a minsdkversion of 21?

For example, to compile for 64-bit ARM Android with a minSdkVersion of 21, either of the following will work and you may use whichever you find most convenient: In both cases, replace $NDK with the path to the NDK and $HOST_TAG to match the NDK you downloaded according to the following table:

What is the NDK?

The Native Development Kit (NDK) is a set of tools that allows you to use C and C++ code with Android, and provides platform libraries you can use to manage native activities and access physical device components, such as sensors and touch input.


1 Answers

Update: The question is a bit outdated now. Starting from version 10c NDK is distributed in a single package for all target platforms again. The answer has been updated to reflect this fact.


First of all, you should distinguish between the architecture of the device where your application will run (which can be ARM (several kinds) 32 or 64 bit, MIPS 32 or 64 bit, and Intel x86 / x64) and the architecture/OS of your build machine (which can be Windows, Linux or Mac all running on Intel x86 / x64 processors).

So suppose you have Windows 64 bit. Then (as right now the latest version is 10d) you should download android-ndk-r10d-windows-x86_64.exe. It will allow you to build for all target platforms supported by NDK (32 and 64 bit).

If you build for 32-bit target device, the application will run on 64-bit device as well, because all listed 64-bit architectures are backward compatible with their 32-bit counterparts.

But if you want to use 64-bit specific features of target architecture, you should use 64-bit toolchains. If you build only for 64 bits, the application won't run on 32-bit architecture.

If you have to support several targets (like ARM and Intel x86), in your Application.mk you can specify targets which you want your native code to be built for (google for APP_ABI), so you'll build several versions of native library and the system will load the appropriate one in runtime. Also this way you can provide separate binaries for 32 and 64 bit versions of same architecture family, so you may fine-tune them.

You may further read the docs inside NDK package, they are quite exhaustive.

like image 92
Anton Savin Avatar answered Nov 13 '22 08:11

Anton Savin