From e23031c974c9b051ba639f9ad68f891e2ae87da3 Mon Sep 17 00:00:00 2001
From: David Friedman downloads
\ No newline at end of file
+ndk.win64_download=android-ndk-r10e-windows-x86_64.exe
+ndk.win64_bytes=419616132
+ndk.win64_checksum=8412bb4991a95e08fda50b5a44d95df7
+
+ndk.win32_download=android-ndk-r10e-windows-x86.exe
+ndk.win32_bytes=396563176
+ndk.win32_checksum=1a82445baaf62aec3a46386ab1e5772c
+
+page.title=NDK Downloads
+@jd:body
\ No newline at end of file
diff --git a/docs/html-ndk/ndk/guides/abis.jd b/docs/html-ndk/ndk/guides/abis.jd
new file mode 100644
index 000000000000..81604b5eefeb
--- /dev/null
+++ b/docs/html-ndk/ndk/guides/abis.jd
@@ -0,0 +1,493 @@
+page.title=ABI Management
+@jd:body
+
+ Different Android handsets use different CPUs, which in turn support different instruction sets.
+Each combination of CPU and instruction set(s) has its own Application Binary Interface, or
+ABI. The ABI defines, with great precision, how an application's machine code is supposed to
+interact with the system at runtime. You must specify an ABI for each CPU architecture you want
+your app to work with. A typical ABI includes the following information: This page enumerates the ABIs that the NDK supports, and provides information about how each ABI
+works. Each ABI supports one or more instruction sets. Table 1 provides an at-a-glance overview of
+the instruction sets each ABI supports.
+ Table 1. ABIs and supported instruction sets. More detailed information about each ABI appears below. This ABI is for ARM-based CPUs that support at least
+the ARMv5TE instruction set. Please refer to the following documentation for
+more details: The AAPCS standard defines EABI as a family of similar
+but distinct ABIs. Also, Android follows the little-endian
+
+ARM GNU/Linux ABI. This ABI does not support hardware-assisted floating point
+computations. Instead, all floating-point operations use software helper
+functions from the compiler's {@code libgcc.a} static library. The armeabi ABI supports ARM’s
+
+Thumb (a.k.a. Thumb-1) instruction set. The NDK generates Thumb
+code by default unless you specify different behavior using the
+ This ABI extends armeabi to include several
+
+CPU instruction set extensions. The instruction extensions that this Android-specific
+ABI supports are: Other extensions that the v7-a ARM spec describes, including
+
+Advanced SIMD (a.k.a. NEON), VFPv3-D32, and ThumbEE, are optional
+to this ABI. Since their presence is not guaranteed, the system should check at runtime
+whether the extensions are available. If they are not, you must use alternative code paths. This
+check is similar to the one that the system typically performs to check or use
+MMX,
+SSE2, and other specialized
+instruction sets on x86 CPUs. For information about how to perform these runtime checks, refer to
+CPU Features.
+Also, for information about the NDK's support for building
+machine code for NEON, see
+NEON Support. The {@code armeabi-v7a} ABI uses the {@code -mfloat-abi=softfp} switch to
+enforce the rule that the compiler must pass all double values in core register pairs during
+function calls, instead of dedicated floating-point ones. The system can perform all internal
+computations using the FP registers. Doing so speeds up the computations greatly. Although the requirement to use core register pairs produces a modest performance hit, it ensures
+compatibility with all existing armeabi binaries. If you need the additional
+performance, you can specify your ABI as {@code armeabi-v7a-hard} instead. Doing so
+allows you to use hard floats, while still linking with Android native APIs
+that use {@code softfp}. For more information, refer to the comments in
+{@code $NDK/tests/device/hard-float/jni/android.mk}. Note: You cannot specify {@code APP_ABI} as both
+{@code armeabi-v7a} and {@code armeabi-v7a-hard}. In either case, the build system places the
+shared libraries in the {@code armeabi-v7a/} directory. This variant of the {@code armeabi-v7a} ABI is unique to the NDK. The NDK build
+system adds the following flags in addition to those that it uses for the
+{@code armeabi-v7a} ABI: The compiler compiles all code with hard-float, and links it with {@code libm_hard.a}.
+This math library is the same one as {@code libm.a}, except that it follows hard-float ABI
+conventions. In the APK, the generated shared libraries reside in {@code /lib/armeabi-v7a/}. This ABI is for ARMv8-based CPUs that support AArch64. It also includes the NEON and
+VFPv4 instruction sets. For more information, see the
+ARMv8
+Technology Preview, and contact ARM for further details. This ABI is for CPUs supporting the instruction set commonly
+referred to as "x86" or "IA-32". Characteristics of this ABI include: These flags target the the Pentium Pro instruction set, along with the
+the MMX,
+SSE,
+SSE2,
+SSE3, and
+SSSE3 instruction set extensions.
+The generated code is an optimization balanced across the top Intel 32-bit
+CPUs. For more information on compiler flags, particularly related to performance optimization,
+refer to GCC
+x86 Performance. The ABI does not include any other optional IA-32 instruction set
+extensions, such as: You can still use these extensions, as long as you use runtime feature-probing to
+enable them, and provide fallbacks for devices that do not support them. The NDK toolchain assumes 16-byte stack alignment before a function call. The default tools and
+options enforce this rule. If you are writing assembly code, you must make sure to maintain stack
+alignment, and ensure that other compilers also obey this rule. Refer to the following documents for more details: This ABI is for CPUs supporting the instruction set commonly referred to as
+"x86-64." It supports instructions that GCC typically generates with the following
+compiler flags: These flags target the x86-64 instruction set, according to the GCC
+documentation. along with the
+MMX,
+SSE,
+SSE2,
+SSE3,
+SSSE3,
+SSE4.1,
+SSE4.2, and
+POPCNT
+instruction-set extensions. The generated code is an optimization balanced
+across the top Intel 64-bit CPUs. For more information on compiler flags, particularly related to performance optimization,
+refer to GCC
+x86 Performance. This ABI does not include any other optional x86-64 instruction set
+extensions, such as: You can still use these extensions, as long as you use runtime feature probing to
+enable them, and provide fallbacks for devices that do not support them. Refer to the following documents for more details: This ABI is for MIPS-based CPUs that support at least the MIPS32r1 instruction set. It includes
+the following features: For more information, please refer to the following documentation: The MIPS-specific documentation is available
+here, with
+further information
+here. This ABI is for MIPS64 R6. For more information, see
+MIPS Architecture. By default, the NDK generates machine code for the armeabi ABI. You can
+generate ARMv7-a-compatible machine code, instead, by adding the following line
+to your {@code Application.mk} file. To build machine code for two or more distinct ABIs, using spaces as delimiters. For
+example: This setting tells the NDK to build two versions of your machine code: one
+for each ABI listed on this line. For more information on the values you can specify for the
+{@code APP_ABI} variable, see Android.mk.
+ When you build multiple machine-code versions, the build system copies the libraries to your
+application project path, and ultimately packages them into your APK, so creating
+a fat binary. A fat binary
+is larger than one containing only the machine code for a single system; the tradeoff is
+gaining wider compatibility, but at the expense of a larger APK. At installation time, the package manager unpacks only the most appropriate
+machine code for the target device. For details, see Automatic
+extraction of native code at install time. This section provides details about how the Android platform manages native
+code in APKs. Both the Play Store and Package Manager expect to find NDK-generated
+libraries on filepaths inside the APK matching the following pattern: Here, {@code <abi>} is one of the ABI names listed under Supported ABIs,
+and {@code <name>} is the name of the library as you defined it for the {@code LOCAL_MODULE}
+variable in the {@code Android.mk} file. Since
+APK files are just zip files, it is trivial to open them and confirm that the shared native
+libraries are where they belong. If the system does not find the native shared libraries where it expects them, it cannot use
+them. In such a case, the app itself has to copy the libraries over, and then
+perform In a fat binary, each library resides under a directory whose name matches a corresponding ABI.
+For example, a fat binary may contain: Note: ARMv7-based Android devices running 4.0.3 or earlier
+install native libraries from the {@code armeabi} directory instead of the {@code armeabi-v7a}
+directory if both directories exist. This is because {@code /lib/armeabi/} comes after
+{@code /lib/armeabi-v7a/} in the APK. This issue is fixed from 4.0.4. The Android system knows at runtime which ABI(s) it supports, because build-specific system
+properties indicate: This mechanism ensures that the system extracts the best machine code from
+the package at installation time. For best performance, you should compile directly for the primary ABI. For example, a
+typical ARMv5TE-based device would only define the primary ABI: {@code armeabi}. By contrast, a
+typical, ARMv7-based device would define the primary ABI as {@code armeabi-v7a} and the secondary
+one as {@code armeabi}, since it can run application native binaries generated for each of them. Many x86-based devices can also run {@code armeabi-v7a} and {@code armeabi} NDK binaries. For
+such devices, the primary ABI would be {@code x86}, and the second one, {@code armeabi-v7a}. A typical MIPS-based device only defines a primary abi: {@code mips}. When installing an application, the package manager service scans the APK, and looks for any
+shared libraries of the form: If none is found, and you have defined a secondary ABI, the service scans for shared libraries of
+the form: When it finds the libraries that it's looking for, the package manager
+copies them to If there is no shared-object file at all, the application builds and installs, but crashes at
+runtime. This page describes the syntax of the {@code Android.mk} build file,
+which glues your C and C++ source files to the Android NDK. The {@code Android.mk} file resides in a subdirectory of your project's {@code jni/} directory,
+and describes your sources and shared libraries to the build system. It is really a tiny GNU
+makefile fragment that the build system parses once or more. The {@code Android.mk} file is useful
+for defining project-wide settings that {@code Application.mk}, the build system, and your
+environment variables leave undefined. It can also override project-wide settings for specific
+modules. The syntax of the {@code Android.mk} allows you to group your sources into
+modules. A module is either a static library, a shared library, or a standalone
+executable. You can define one or more modules in each {@code Android.mk} file, and
+you can use the same source file in multiple modules. The build system only places shared libraries
+into your application package. In addition, static libraries can generate shared libraries. In addition to packaging libraries, the build system handles a variety of other details for you.
+For example, you don't need to list header files or explicit dependencies between generated files in
+your {@code Android.mk} file. The NDK build system computes these relationships automatically for
+you. As a result, you should be able to benefit from new toolchain/platform support in future NDK
+releases without having to touch your {@code Android.mk} file. The syntax of this file is very close to that used in the {@code Android.mk} files distributed with
+the full Android Open Source Project. While the
+build system implementation that uses them is different, their similarity is an
+intentional design decision aimed at making it easier for application
+developers to reuse source code for external libraries. Before exploring the syntax in detail, it is useful to start by understanding the basics
+of what a {@code Android.mk} file contains. This section uses the {@code Android.mk} file in the
+Hello-JNI sample toward that end, explaining the role that each line in the file plays. An {@code Android.mk} file must begin by defining the {@code LOCAL_PATH} variable:
+
+ This variable indicates the location of the source files in the development tree. Here, the macro
+function {@code my-dir}, provided by the build system, returns the path of the current directory
+(the directory containing the {@code Android.mk} file itself). The next line declares the {@code CLEAR_VARS} variable, whose value the build system provides.
+
+ The {@code CLEAR_VARS} variable points to a special GNU Makefile that clears many
+{@code LOCAL_XXX} variables for you, such as {@code LOCAL_MODULE}, {@code LOCAL_SRC_FILES}, and
+{@code LOCAL_STATIC_LIBRARIES}. Note that it does not clear {@code LOCAL_PATH}. This variable must
+retain its value because the system parses all build control files in a single GNU Make execution
+context where all variables are global. You must (re-)declare this variable before describing each
+module. Next, the {@code LOCAL_MODULE} variable stores the name of the module that you wish to build.
+Use this variable once per module in your application. Each module name must be unique and not contain any spaces. The build system, when it
+generates the final shared-library file, automatically adds the proper prefix and suffix to
+the name that you assign to {@code LOCAL_MODULE|. For example, the example that appears above
+results in generation of a library called {@code libhello-jni.so}. Note: If your module's name already starts with {@code lib}, the
+build system does not prepend an additional {@code lib} prefix; it takes the module name as-is, and
+adds the {@code .so} extension. So a source file originally called, for example, {@code libfoo.c}
+still produces a shared-object file called {@code libfoo.so}. This behavior is to support libraries
+that the Android platform sources generate from {@code Android.mk} files; the names of all such
+libraries start with {@code lib}. The next line enumerates the source files, with spaces delimiting multiple files: The {@code LOCAL_SRC_FILES} variable must contain a list of C and/or C++ source files to build
+into a module. The last line helps the system tie everything together: The {@code BUILD_SHARED_LIBRARY} variable points to a GNU Makefile script that collects all the
+information you defined in {@code LOCAL_XXX} variables since the most recent {@code include}. This
+script determines what to build, and how to do it. There are more complex examples in the samples directories, with commented
+{@code Android.mk} files that you can look at. In addition, the
+walkthrough of the native-activity sample
+disucsses that sample's {@code Android.mk} file in some detail. Finally, the next section explains
+the variables from this section in a bit more detail.
+
+
+ The build system provides many possible variables for use in the the {@code Android.mk} file.
+Many of these variables come with preassigned values. Others, you assign. In addition to these variables, you can also define your own arbitrary ones. If you do so, keep
+in mind that the NDK build system reserves the following variable names: If you need to define your own convenience variables in an {@code Android.mk} file, we
+recommend prepending {@code MY_} to their names.
+
+
+ This section discusses the GNU Make variables that the build system defines before parsing your
+{@code Android.mk} file. Under certain circumstances, the NDK might parse your {@code Android.mk}
+file several times, using a different definition for some of these variables each time. This variable points to a build script that undefines nearly all {@code LOCAL_XXX} variables
+listed in the "Developer-defined variables" section below. Use this variable to include
+this script before describing a new module. The syntax for using it is: This variable points to a build script that collects all the information about the module
+you provided in your {@code LOCAL_XXX} variables, and determines how to build a target shared
+library from the sources you listed. Note that using this script requires that you have already
+assigned values to {@code LOCAL_MODULE} and {@code LOCAL_SRC_FILES}, at a minimum (for more
+information about these variables, see Module-description variables). The syntax for using this variable is: A shared-library variable causes the build system to generate a library file with a {@code .so}
+extension. A variant of {@code BUILD_SHARED_LIBRARY} that is used to build a static library. The build
+system does not copy static libraries into your project/packages, but it can use them to build
+shared libraries (see {@code LOCAL_STATIC_LIBRARIES} and {@code LOCAL_WHOLE_STATIC_LIBRARIES},
+below). The syntax for using this variable is: A static-library variable causes the build system to generate a library with a {@code .a}
+extension. Points to a build script used to specify a prebuilt shared library. Unlike in the case of
+{@code BUILD_SHARED_LIBRARY} and {@code BUILD_STATIC_LIBRARY}, here the value of
+{@code LOCAL_SRC_FILES} cannot be a source file. Instead, it must be a single path to a prebuilt
+shared library, such as {@code foo/libfoo.so}. The syntax for using this variable is: You can also reference a prebuilt library in another module by using the
+{@code LOCAL_PREBUILTS} variable. The following example shows an example of using
+{@code LOCAL_PREBUILTS}:
+
+
+
+ For more information about using prebuilts, see
+NDK Prebuilt Library Support. The same as {@code PREBUILT_SHARED_LIBRARY}, but for a prebuilt static library. For more
+information about using prebuilts, see NDK Prebuilt
+Library Support. The name of the target CPU architecture as the Android Open Source Project specifies it.
+For any ARM-compatible build, use {@code arm}, independent of the CPU architecture revision or
+ABI (see TARGET_ARCH_ABI, below). The value of this variable is taken from the APP_ABI variable that you define in the
+{@code Android.mk} file, which the system
+reads ahead of parsing the {@code Android.mk} file. The Android API level number for the build system to target.
+For example, the Android 5.1 system images correspond to Android API level 22: {@code android-22}.
+For a complete list of platform names and corresponding Android system
+images, see Android NDK Stable APIs.
+The following example shows the syntax for using this variable: This variable stores the name of the CPU and architecture to target when the build system
+parses this {@code Android.mk} file. You can specify one or more of the following values, using
+a space as a delimiter between multiple targets. Table 1 shows the ABI setting to use for each
+supported CPU and architecture.
+
+
+ Table 1. ABI settings for different CPUs and architectures. The following example shows how to set ARMv8 AArch64 as the target CPU-and-ABI combination: Note: Up to Android NDK 1.6_r1, this variable is defined as
+{@code arm}. For more details about architecture ABIs and associated compatibility
+issues, refer to
+
+Android Native CPU ABI Management New target ABIs in the future will have different values. A concatenation of target Android API level and ABI, it is especially useful when you want to test against
+a specific target system image for a real device. For example, to specify a 64-bit ARM device
+running on Android API level 22: Note: Up to Android NDK 1.6_r1, the default value was
+{@code android-3-arm}. The variables in this section describe your module to the build system. Each module description
+should follow this basic flow:
+ This variable is used to give the path of the current file. You must define
+it at the start of your {@code Android.mk} file. The following example shows how to do so: The script to which {@code CLEAR_VARS} points does not clear this variable. Therefore, you only need
+to define it a single time, even if your {@code Android.mk} file describes multiple modules. This variable stores the name of your module. It must be unique among all module names,
+and must not contain any spaces. You must define it before including any scripts (other than
+the one for {@code CLEAR_VARS}). You need not add either the {@code lib} prefix
+or the {@code .so} or {@code .a} file extension; the build system makes these modifications
+automatically. Throughout your {@code Android.mk} and {@code Application.mk} files, refer to
+your module by its unmodified name. For example, the following line results in the generation of a
+shared library module called {@code libfoo.so}: If you want the generated module to have a name other than {@code lib} + the value of
+{@code LOCAL_MODULE}, you can use the {@code LOCAL_MODULE_FILENAME} variable to give the
+generated module a name of your own choosing, instead. This optional variable allows you to override the names that the build system
+uses by default for files that it generates. For example, if the name of your {@code LOCAL_MODULE}
+is {@code foo}, you can force the system to call the file it generates {@code libnewfoo}. The
+following example shows how to accomplish this: For a shared library module, this example would generate a file called {@code libnewfoo.so}. Note: You cannot override filepath or file extension. This variable contains the list of source files that the build system uses to generate the
+module. Only list the files that the build system actually passes to the compiler, since the build
+system automatically computes any associated depencies. Note that you can use both relative (to {@code LOCAL_PATH}) and absolute file paths.
+
+ We recommend avoiding absolute file paths; relative paths make your
+{@code Android.mk} file more
+portable. Note: Always use Unix-style forward slashes (/) in build files.
+The build system does not handle Windows-style backslashes (\) properly. You can use this optional variable to indicate a file extension other than {@code .cpp} for your
+C++ source files. For example, the following line changes the extension to {@code .cxx}.
+(The setting must include the dot.)
+
+ From NDK r7, you can use this variable to specify multiple extensions. For instance: You can use this optional variable to indicate that your code relies on specific C++ features.
+It enables the right compiler and linker flags during the build process. For prebuilt binaries,
+this variable also declares which features the binary depends on, thus helping ensure the final
+linking works correctly. We recommend that you use this variable instead of enabling
+{@code -frtti} and {@code -fexceptions} directly in your {@code LOCAL_CPPFLAGS} definition. Using this variable allows the build system to use the appropriate flags for each module. Using
+{@code LOCAL_CPPFLAGS} causes the compiler to use all specified flags for all modules, regardless
+of actual need.On this page
+
+
+
+
+
+Supported ABIs
+
+
+
+
+
+
+
+ABI
+Supported Instruction Set(s)
+Notes
+
+
+
+{@code armeabi}
+
+No hard float.
+
+
+
+{@code armeabi-v7a}
+
+
+Hard float when specified as {@code armeabi-v7a-hard}.
+Incompatible with ARMv5, v6 devices.
+
+
+
+{@code arm64-v8a}
+
+
+
+
+
+{@code x86}
+
+No support for MOVBE or SSE4.
+
+
+
+{@code x86_64}
+
+
+
+
+
+{@code mips}
+
+Uses hard-float, and assumes a CPU:FPU clock ratio of 2:1 for maximum
+compatibility. Provides neither micromips nor MIPS16.
+
+
+{@code mips64}
+
+
+armeabi
+
+
+
+LOCAL_ARM_MODE variable in your Android.mk
+file.armeabi-v7a (armeabi-v7a-hard)
+
+
+
+armeabi-v7a-hard
+
+TARGET_CFLAGS += -mhard-float -D_NDK_MATH_NO_SOFTFP=1
+TARGET_LDFLAGS += -Wl,--no-warn-mismatch -lm_hard
+
+
+arm64-v8a
+x86
+
+
+
+
+-march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32
+
+
+
+
+
+
+
+x86_64
+
+-march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel
+
+
+
+
+
+
+
+
+mips
+
+
+
+
+
+
+mips64
+Generating Code for a Specific ABI
+
+APP_ABI := armeabi-v7a
+
+
+
+APP_ABI := armeabi armeabi-v7a
+
+
+ABI Management on the Android Platform
+Native code in app packages
+
+/lib/<abi>/lib<name>.so
+
+
+dlopen().
+/lib/armeabi/libfoo.so
+/lib/armeabi-v7a/libfoo.so
+/lib/arm64-v8a/libfoo.so
+/lib/x86/libfoo.so
+/lib/x86_64/libfoo.so
+/lib/mips/libfoo.so
+/lib/mips64/libfoo.so
+
+
+Android Platform ABI support
+
+
+
+Automatic extraction of native code at install time
+
+
+lib/<primary-abi>/lib<name>.so
+
+
+
+lib/<secondary-abi>/lib<name>.so
+
+
+/lib/lib<name>.so, under the application's
+{@code data} directory ({@code data/data/<package_name>/lib/}).On this page
+
+
+ Overview
+Basics
+
+LOCAL_PATH := $(call my-dir)
+
+
+
+include $(CLEAR_VARS)
+
+
+
+LOCAL_MODULE := hello-jni
+
+
+
+LOCAL_SRC_FILES := hello-jni.c
+
+
+
+include $(BUILD_SHARED_LIBRARY)
+
+
+Variables and Macros
+
+
+NDK-defined variables
+CLEAR_VARS
+
+include $(CLEAR_VARS)
+
+
+BUILD_SHARED_LIBRARY
+
+include $(BUILD_SHARED_LIBRARY)
+
+
+BUILD_STATIC_LIBRARY
+
+include $(BUILD_STATIC_LIBRARY)
+
+
+PREBUILT_SHARED_LIBRARY
+
+include $(PREBUILT_SHARED_LIBRARY)
+
+
+PREBUILT_STATIC_LIBRARY
+TARGET_ARCH
+TARGET_PLATFORM
+
+TARGET_PLATFORM := android-22
+
+
+TARGET_ARCH_ABI
+
+
+
+
+
+ CPU and architecture
+ Setting
+
+
+ ARMv5TE
+ {@code armeabi}
+
+
+ ARMv7
+ {@code armeabi-v7a}
+
+
+ ARMv8 AArch64
+ {@code arm64-v8a}
+
+
+ i686
+ {@code x86}
+
+
+ x86-64
+ {@code x86_64}
+
+
+ mips32 (r1)
+ {@code mips}
+
+
+ mips64 (r6)
+ {@code mips64}
+
+
+All
+ {@code all}
+
+TARGET_ARCH_ABI := arm64-v8a
+
+
+TARGET_ABI
+
+TARGET_ABI := android-22-arm64-v8a
+
+
+Module-description variables
+
+
+
+
+
+LOCAL_PATH
+
+LOCAL_PATH := $(call my-dir)
+
+
+LOCAL_MODULE
+
+LOCAL_MODULE := "foo"
+
+
+LOCAL_MODULE_FILENAME
+
+LOCAL_MODULE := foo
+LOCAL_MODULE_FILENAME := libnewfoo
+
+
+LOCAL_SRC_FILES
+LOCAL_CPP_EXTENSION
+
+LOCAL_CPP_EXTENSION := .cxx
+
+
+
+LOCAL_CPP_EXTENSION := .cxx .cpp .cc
+
+
+LOCAL_CPP_FEATURES
+
+
+LOCAL_CPP_FEATURES := rtti ++ +
To indicate that your code uses C++ exceptions, write:
+ ++LOCAL_CPP_FEATURES := exceptions ++ +
You can also specify multiple values for this variable. For example:
+ ++LOCAL_CPP_FEATURES := rtti features ++ +The order in which you describe the values does not matter. + + +
You can use this optional variable to specify a list of paths, relative to the +NDK {@code root} directory, to add to the include search path when compiling all sources +(C, C++ and Assembly). For example:
+ ++LOCAL_C_INCLUDES := sources/foo ++ +
Or even:
+ ++LOCAL_C_INCLUDES := $(LOCAL_PATH)/+ +/foo +
Define this variable before setting any corresponding inclusion flags via {@code LOCAL_CFLAGS} +or {@code LOCAL_CPPFLAGS}.
+ +The build system also uses {@code LOCAL_C_INCLUDES} paths automatically when launching native +debugging with ndk-gdb.
+ + +This optional variable sets compiler flags for the build system to pass when building C +and C++ source files. The ability to do so can be useful for specifying additional macro +definitions or compile options.
+ +Try not to change the optimization/debugging level in your {@code Android.mk} file. +The build system can handle this setting automatically for you, using the relevant information +in the {@code Application.mk} file. Doing it this way allows the build system to generate useful +data files used during debugging.
+ +Note: In android-ndk-1.5_r1, the corresponding flags only applied +to C source files, not C++ ones. They now match the full Android build system behavior. +(You can now use {@code LOCAL_CPPFLAGS} to specify flags for C++ sources only.)
+ +It is possible to specify additional include paths by writing: + +
+LOCAL_CFLAGS += -I<path>, ++ +It is better, however, to use {@code LOCAL_C_INCLUDES} for this purpose, since +doing so also makes it possible to use the paths available for native debugging with ndk-gdb. + + +
An optional set of compiler flags that will be passed when building C++ +source files only. They will appear after the LOCAL_CFLAGS on the +compiler's command-line.
+ + +Note: In android-ndk-1.5_r1, the corresponding flags applied to +both C and C++ sources. This has been corrected to match the full Android build system. +To specify flags for both C and C++ sources, use {@code LOCAL_CFLAGS}.
+ + +This variable stores the list of static libraries modules on which the current module depends.
+ +If the current module is a shared library or an executable, this variable will force +these libraries to be linked into the resulting binary.
+ +If the current module is a static library, this variable simply indicates that other +modules depending on the current one will also depend on the listed +libraries.
+ +This variable is the list of shared libraries modules on which this module depends at +runtime. This information is necessary at link time, and to embed the corresponding information +in the generated file.
+ +This variable is a variant of {@code LOCAL_STATIC_LIBRARIES}, and expresses that the linker +should treat the associated library modules as whole archives. For more information +on whole archives, see the GNU linker's +documentation for the +{@code --whole-archive} flag.
+ +This variable is useful when there are circular dependencies among +several static libraries. When you use this variable to build a shared library, it will force +the build system to add all object files from your static libraries to the final binary. The same +is not true, however, when generating executables.
+ + +This variable contains the list of additional linker flags for use in building your shared +library or executable. It enables you to use the {@code -l} prefix to pass the name of specific +system libraries. For example, the following example tells the linker to generate a module that +links to {@code /system/lib/libz.so} at load time:
+ ++LOCAL_LDLIBS := -lz ++ +
For the list of exposed system libraries against which you can link in this NDK release, see +Android NDK Stable APIs.
+ +Note: If you define this variable for a static library, +the build system ignores it, and {@code ndk-build} prints a warning.
+ +The list of other linker flags for the build system to use when building your shared library +or executable. For example, the following example uses the {@code ld.bfd} linker on ARM/X86 GCC +4.6+, on which {@code ld.gold} is the default
+ ++LOCAL_LDFLAGS += -fuse-ld=bfd ++ +
Note: If you define this variable for a static library, the build +system ignores it, and ndk-build prints a warning.
+ +By default, when the build system encounters an undefined reference encountered while trying to +build a shared, it will throw an undefined symbol error. This error can help you catch +catch bugs in your source code.
+ +To disable this check, set this variable to {@code true}. Note that this setting may cause the +shared library to load at runtime.
+ +Note: If you define this variable for a static library, +the build system ignores it, and ndk-build prints a warning.
+ +By default, the build system generates ARM target binaries in thumb mode, where each +instruction is 16 bits wide and linked with the STL libraries in the {@code thumb/} directory. +Defining this variable as {@code arm} forces the build system to generate the module's object +files in 32-bit {@code arm} mode. The following example shows how to do this:
+ ++LOCAL_ARM_MODE := arm ++ +
You can also instruct the build system to only build specific sources in {@code arm} mode by +appending {@code .arm} suffix to the the source filenames. For example, the following example +tells the build system to always compile {@code bar.c} in ARM mode, but to build +{@code foo.c} according to the value of {@code LOCAL_ARM_MODE}.
+ ++LOCAL_SRC_FILES := foo.c bar.c.arm ++ + + +
Note: You can also force the build system to generate ARM binaries +by setting {@code APP_OPTIM} in your +Android +NDK & ARM NEON Instruction Set Extension Support and Android +NDK CPU Features Detection Library.
+ +Alternatively, you can use the {@code .neon} suffix to specify that the build system only +compile specific source files with NEON support. In the following example, the build system compiles +{@code foo.c} with thumb and neon support, {@code bar.c} with thumb support, and +{@code zoo.c} with support for ARM and NEON:
+ ++LOCAL_SRC_FILES = foo.c.neon bar.c zoo.c.arm.neon ++ + +
If you use both suffixes, {@code .arm} must precede {@code .neon}.
+ +Android NDK r4 added support for the "NX bit" security feature. It is +enabled by default, but you can disable it by setting this variable to {@code true}. We do not +recommend doing so without a compelling reason.
+ +This feature does not modify the ABI, and is only enabled on kernels +targeting ARMv6+ CPU devices. Machine code with this feature enabled +will run unmodified on devices running earlier CPU architectures.
+For more information, see Wikipedia: NX bit +and The GNU stack kickstart. + +
By default, the NDK compiles code with read-only relocations and GOT +protection. This variable instructs the runtime linker to mark certain regions of memory +as read-only after relocation, making certain security exploits (such as GOT overwrites) +more difficult. Note that these protections are only effective on Android API level 16 and higher. +On lower API levels, the code will still run, but without memory protections.
+ +This variable is turned on by default, but you can disable it by setting its value to +{@code true}. We do not recommend doing so without a compelling reason.
+ +For more information, see +RELRO: +RELocation Read-Only and Security +enhancements in RedHat Enterprise Linux (section 6).
+ +By default, the build system compiles code with format string protection. Doing so forces a +compiler error if a non-constant format string is used in a {@code printf}-style function.
+This protection is off by default, but you can disable it by setting its value to +{@code true}. We do not recommend doing so without a compelling reason.
+ + +This variable records a set of C/C++ compiler flags to add to the {@code LOCAL_CFLAGS} definition +of any other module that uses this one via the {@code LOCAL_STATIC_LIBRARIES} or +{@code LOCAL_SHARED_LIBRARIES} variables.
+ +For example, consider the following pair of modules: {@code foo} and {@code bar}, which depends +on {@code foo}:
+ ++include $(CLEAR_VARS) +LOCAL_MODULE := foo +LOCAL_SRC_FILES := foo/foo.c +LOCAL_EXPORT_CFLAGS := -DFOO=1 +include $(BUILD_STATIC_LIBRARY) + + +include $(CLEAR_VARS) +LOCAL_MODULE := bar +LOCAL_SRC_FILES := bar.c +LOCAL_CFLAGS := -DBAR=2 +LOCAL_STATIC_LIBRARIES := foo +include $(BUILD_SHARED_LIBRARY) ++ +
Here, the build system passes the flags {@code -DFOO=1} and {@code -DBAR=2} to the compiler when +building {@code bar.c}. It also prepends exported flags to your your module's {@code LOCAL_CFLAGS} +so you can easily override them.
+ +In addition, the relationship among modules is transitive: If {@code zoo} depends on +{@code bar}, which in turn depends on {@code foo}, then {@code zoo} also inherits all flags +exported from {@code foo}. + +Finally, the build system does not use exported flags when building locally (i.e., building the +module whose flags it is exporting). Thus, in the example above, it does not pass {@code -DFOO=1} +to the compiler when building {@code foo/foo.c}. To build locally, use {@code LOCAL_CFLAGS} +instead.
+ +This variable is the same as {@code LOCAL_EXPORT_CFLAGS}, but for C++ flags only.
+ +This variable is the same as {@code LOCAL_EXPORT_CFLAGS}, but for C include paths. It is useful +in cases where, for example, {@code bar.c} needs to include headers from module {@code foo}.
+ +This variable is the same as {@code LOCAL_EXPORT_CFLAGS}, but for linker flags.
+ +This variable is the same as {@code LOCAL_EXPORT_CFLAGS}, telling the build system to pass names +of specific system libraries to the compiler. Prepend {@code -l} to the name of each library you +specify.
+ +Note that the build system appends imported linker flags to the value of your module's +{@code LOCAL_LDLIBS} variable. It does this due to the way Unix linkers work.
+ +This variable is typically useful when module {@code foo} is a static library +and has code that depends on a system library. You can then use {@code LOCAL_EXPORT_LDLIBS} to +to export the dependency. For example:
+ ++include $(CLEAR_VARS) +LOCAL_MODULE := foo +LOCAL_SRC_FILES := foo/foo.c +LOCAL_EXPORT_LDLIBS := -llog +include $(BUILD_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := bar +LOCAL_SRC_FILES := bar.c +LOCAL_STATIC_LIBRARIES := foo +include $(BUILD_SHARED_LIBRARY) ++ +
In this example, the build system puts {@code -llog} at the end of the linker command when it +builds {@code libbar.so}. Doing so tells the linker that, because {@code libbar.so} depends +on {@code foo}, it also depends on the system logging library.
+ +Set this variable to {@code true} when your module has a very high +number of sources and/or dependent static or shared libraries. Doing so forces the +build system to use {@code @} syntax for archives containing intermediate object files +or linking libraries.
+ +This feature can be useful on Windows, where the command line accepts a maximum of only +of 8191 characters, which can be too small for complex projects. It also impacts the compilation of +individual source files, placing nearly all compiler flags inside list files, too.
+ +Note that any value other than {@code true} will revert to the +default behaviour. You can also define {@code APP_SHORT_COMMANDS} in your +{@code Application.mk} file to force this +behavior for all modules in your project.
+ +We do not recommend enabling this feature by default, since it makes the build slower.
+ + +Set this variable to {@code true} when building static libraries. +Doing so will generate a thin archive, a library file that does not contain +object files, but instead just file paths to the actual objects that it would normally +contain.
+This is useful to reduce the size of your build output. The drawback is that +such libraries cannot be moved to a different location (all paths +inside them are relative).
+Valid values are {@code true}, {@code false} or empty. A +default value can be set in your {@code Application.mk} file through the {@code APP_THIN_ARCHIVE} + +variable.
+Note: This is ignored for non-static library modules, or prebuilt +static library ones.
+ +Define this variable as a shell command that the build system will use to filter the +assembly files extracted or generated from the files you specified for {@code LOCAL_SRC_FILES}.
+Defining this variable causes the following things to occur:
+ +For example:
+ ++LOCAL_SRC_FILES := foo.c bar.S +LOCAL_FILTER_ASM := + +foo.c --1--> $OBJS_DIR/foo.S.original --2--> $OBJS_DIR/foo.S --3--> $OBJS_DIR/foo.o +bar.S --2--> $OBJS_DIR/bar.S --3--> $OBJS_DIR/bar.o ++ +
"1" corresponds to the compiler, "2" to the filter, and "3" to the assembler. The filter must +be a standalone shell command that takes the name of the input file as its first argument, and the +name of the output file as the second one. For example:
+ ++myasmfilter $OBJS_DIR/foo.S.original $OBJS_DIR/foo.S +myasmfilter bar.S $OBJS_DIR/bar.S ++ +
This section explains GNU Make function macros that the NDK provides. Use +{@code $(call <function>)} to evaluate them; they return textual information.
+ +This macro returns the path of the last included makefile, which typically is the +current {@code Android.mk}'s directory. {@code my-dir} is useful for defining +{@code LOCAL_PATH} at the start of your {@code Android.mk} file. For example:
+ ++LOCAL_PATH := $(call my-dir) ++ +
Due to the way GNU Make works, what this macro really returns is the +path of the last makefile that the build system included when parsing the build scripts. For this +reason, you should not call {@code my-dir} after including another file.
+ +For example, consider the following example:
+ ++LOCAL_PATH := $(call my-dir) + +# ... declare one module + +include $(LOCAL_PATH)/foo/`Android.mk` + +LOCAL_PATH := $(call my-dir) + +# ... declare another module ++ +
The problem here is that the second call to {@code my-dir} defines +{@code LOCAL_PATH} as {@code $PATH/foo} instead of {@code $PATH}, because that was where its +most recent include pointed.
+ +You can avoid this problem by putting additional includes after everything +else in the {@code Android.mk} file. For example:
+ ++LOCAL_PATH := $(call my-dir) + +# ... declare one module + +LOCAL_PATH := $(call my-dir) + +# ... declare another module + +# extra includes at the end of the Android.mk file +include $(LOCAL_PATH)/foo/Android.mk + ++ +
If it is not feasible to structure the file in this way, save the value of the first +{@code my-dir} call into another variable. For example:
+ ++MY_LOCAL_PATH := $(call my-dir) + +LOCAL_PATH := $(MY_LOCAL_PATH) + +# ... declare one module + +include $(LOCAL_PATH)/foo/`Android.mk` + +LOCAL_PATH := $(MY_LOCAL_PATH) + +# ... declare another module ++ +
Returns the list of {@code Android.mk} files located in all subdirectories of +the current {@code my-dir} path. + +
You can use this function to provide deep-nested source directory hierarchies to the build +system. By default, the NDK only looks for files in the directory containing the +{@code Android.mk} file.
+ +Returns the path of the current makefile (from which the build system called the function).
+ +Returns the path of the parent makefile in the inclusion tree (the path of the makefile that +included the current one).
+ +Returns the path of the grandparent makefile in the inclusion tree (the path of the makefile that +included the current one).
+ +A function that allows you to find and include the {@code Android.mk} +of another module by name. A typical example is as follows:
+ ++$(call import-module,<name>) ++ +
In this example, the build system looks for the module tagged <name> in the list of +directories referenced that your {@code NDK_MODULE_PATH} environment variable references, and +includes its {@code Android.mk} file automatically for you.
+ +For more information, see Android Module Paths (Sharing Code). +
diff --git a/docs/html-ndk/ndk/guides/application_mk.jd b/docs/html-ndk/ndk/guides/application_mk.jd new file mode 100644 index 000000000000..be82fbe513dc --- /dev/null +++ b/docs/html-ndk/ndk/guides/application_mk.jd @@ -0,0 +1,241 @@ +page.title=Application.mk +@jd:body + + + +This document explains the syntax of the {@code Application.mk} build file, which describes the +native modules that your app requires. A module can be a static library, a shared library, +or an executable.
+ +We recommend that you read the Concepts and +Android.mk pages before this one. Doing so will +help maximize your understanding of the material on this page.
+ ++$NDK/apps/<myapp>/Application.mk ++ +
Here, {@code <myapp>} is a short name used to describe your app to the NDK build system. It +doesn't actually go into your generated shared libraries or your final packages.
+ +This variable stores the absolute path to your app's project-root directory. The build system +uses this information to place stripped-down versions of the generated JNI shared libraries +into a specific location known to the APK-generating tools.
+ +If you place your {@code Application.mk} file under {@code $NDK/apps/<myapp>/}, you must +define this variable. If you place it under {@code $PROJECT/jni/}, it is optional. + +
Define this optional variable as either {@code release} or {@code debug}. You use it to +alter the optimization level when building your application's modules.
+ +Release mode is the default, and generates highly optimized binaries. Debug mode generates +unoptimized binaries that are much easier to debug.
+ +Note that you can debug either release or debug binaries. Release binaries, however, provide less +information during debugging. For example, the build system optimizes out some variables, +preventing you from inspecting them. Also, code re-ordering can make it more difficult to step +through the code; stack traces may not be reliable.
+ +Declaring {@code android:debuggable} in your application manifest's {@code <application>} +tag will cause this variable to default to {@code debug} instead of {@code release}. Override this +default value by setting {@code APP_OPTIM} to {@code release}.
+ + +This variable stores a set of C compiler flags that the build system passes to the compiler +when compiling any C or C++ source code for any of the modules. You can use this variable to change +the build of a given module according to the application that needs it, instead of having to modify +the {@code Android.mk} file itself.
+ + +All paths in these flags should be relative to the top-level NDK directory. For example, if you +have the following setup:
+ ++sources/foo/Android.mk +sources/bar/Android.mk ++ +
To specify in {@code foo/Android.mk} that you want to add the path to the {@code bar} sources +during compilation, you should use: + +
+APP_CFLAGS += -Isources/bar ++ +
Or, alternatively:
+ ++APP_CFLAGS += -I$(LOCAL_PATH)/../bar ++ +
{@code -I../bar} will not work since it is equivalent to +{@code -I$NDK_ROOT/../bar}.
+ +Note: This variable only works on C, not C++, sources in +android-ndk-1.5_r1. In all versions after that one, {@code APP_CFLAGS} matches the full Android +build system.
+ +This variable contains a set of C++ compiler flags that the build system passes to the compiler +when building only C++ sources.
+ +Note: In android-ndk-1.5_r1, this variable works on both C and +C++ sources. In all subsequent versions of the NDK, {@code APP_CPPFLAGS} now matches the full +Android build system. For flags that apply to both C and C++ sources, use {@code APP_CFLAGS}.
+ +A set of linker flags that the build system passes when linking the application. This variable +is only relevant when the build system is building shared libraries and executables. When the +build system builds static libraries, it ignores these flags.
+ +By default, the NDK build system looks under {@code jni/} for a file named +{@code Android.mk}.
+ +If you want to override this behavior, you can define {@code APP_BUILD_SCRIPT} to point to an +alternate build script. The build system always interprets a non-absolute path as relative to the +NDK's top-level directory.
+ +By default, the NDK build system generates machine code for the +{@code armeabi} ABI. This machine code +corresponds to an ARMv5TE-based CPU with software floating point operations. You can use +{@code APP_ABI} to select a different ABI. Table 1 shows the {@code APP_ABI} +settings for different instruction sets.
+ ++ Table 1. {@code APP_ABI} settings for different instruction sets.
+| Instruction set | +Value | +
|---|---|
| Hardware FPU instructions on ARMv7 based devices | +{@code APP_ABI := armeabi-v7a} | +
| ARMv8 AArch64 | +{@code APP_ABI := arm64-v8a} | +
| IA-32 | +{@code APP_ABI := x86} | +
| Intel64 | +{@code APP_ABI := x86_64} | +
| MIPS32 | +{@code APP_ABI := mips} | +
| MIPS64 (r6) | +{@code APP_ABI := mips64} | +
| All supported instruction sets | +{@code APP_ABI := all} | +
Note: {@code all} is available starting from NDKr7.
+ +You can also specify multiple values by placing them on the same line, delimited by spaces. +For example:
+ ++APP_ABI := armeabi armeabi-v7a x86 mips ++ +
For the list of all supported ABIs and details about their usage and limitations, refer to +Android Native CPU ABI Management.
+ +This variable contains the name of the target Android platform. For example, {@code android-3} +specifies the Android 1.5 system images. For a complete list of platform names and corresponding +Android system images, see Android NDK Stable APIs +.
+ +By default, the NDK build system provides C++ headers for the minimal C++ runtime library +({@code system/lib/libstdc++.so}) provided by the Android system. In addition, it comes with +alternative C++ implementations that you can use or link to in your own applications. +Use {@code APP_STL} to select one of them. Table 2 shows the {@code APP_STL} values to specify +support for different libraries.
+ ++ Table 2. {@code APP_STL} settings to support different libraries.
+| Library | +Value | +
|---|---|
| Static STLport | +{@code APP_STL := stlport_static} | +
| Shared STLport | +{@code APP_STL := stlport_shared} | +
| Default C++ runtime | +{@code APP_STL := system} | +
For more information on this subject, see C++ +Support.
+ + +The equivalent of {@code LOCAL_SHORT_COMMANDS} in {@code Application.mk} for your whole project. +For more information, see the documentation for this variable on +{@code Android.mk}.
+ +Define this variable as either {@code 4.9} or {@code 4.8} to select a version of the GCC +compiler. Version 4.9 is the default for 64-bit ABIs, and 4.8 is the default for 32-bit ABIs. +To select a version of Clang, define this variable as {@code clang3.4}, {@code clang3.5}, or +{@code clang}. Specifying {@code clang} chooses the most recent version of Clang.
+ +Starting from Android 4.1 (API level 16), Android's dynamic linker supports position-independent +executables (PIE). Use the {@code -fPIE} flag to build them. This flag makes it harder to exploit +memory corruption bugs by randomizing code location. By default, {@code ndk-build} automatically +sets this value to {@code true} if your project targets {@code android-16} or higher. You may set +it manually to either {@code true} or {@code false}.
+ +This flag applies only to executables. It has no effect when building shared or static +libraries.
+ +Note: PIE executables cannot run on Android releases prior to 4.1. +
This restriction only applies to executables. It has no effect when building shared or static +libraries.
+ +Sets the default value of {@code LOCAL_THIN_ARCHIVE} in the {@code Android.mk} file for all +static library modules in this project. For more information, see the documentation for +{@code LOCAL_THIN_ARCHIVE} on {@code Android.mk}. +
diff --git a/docs/html-ndk/ndk/guides/arch.jd b/docs/html-ndk/ndk/guides/arch.jd new file mode 100644 index 000000000000..875bbd90f5ea --- /dev/null +++ b/docs/html-ndk/ndk/guides/arch.jd @@ -0,0 +1,31 @@ +page.title=Architectures and CPUs +@jd:body + +This section includes detailed information about ABIs and detailed information on support for respective instruction sets. It includes these topics:
+This section explains, in detail, how to use the NDK to build your project. It comprises the following topics:
+This guide assumes that you are:
+This section provides a high-level explanation of how the NDK works. The Android NDK is a set of +tools allowing you to embed C or C++ (“native code”) into your Android apps. The ability to use +native code in Android apps can be particularly useful to developers who wish to do one or more of +the following:
+This section introduces the main components used in building a native application for Android, +and goes on to describe the process of building and packaging.
+You should have an understanding of the following components as you build your app:
+For more information, see the +ndk-build section of this guide.
+When developing Java components, use the {@code native} keyword to indicate methods implemented +as native code. For example, the following function declaration tells the compiler that the +implementation is in a native library:
+ + + ++public native int add(int x, int y); ++
Note: If two libraries implement respective methods with the same +signature, a link error occurs. In C, "signature" means method name only. In C++, "signature" means +not only method name, but also its argument names and types.
+The following two items only apply in cases in which you are using the toolchains provided with +the Android NDK as standalone compilers.
+ +For more information, see the +Application.mk section.
+The general flow for developing a native app for Android is as follows:
+Note: While it is possible to completely avoid Java, you are likely +to find the Android Java framework useful for tasks including controlling the display and UI.
+Note that Eclipse can perform steps 7. through 9. in a single operation.
+ +The Android SDK provides a helper class, {@link android.app.NativeActivity}, that allows you to +write a completely native activity. {@link android.app.NativeActivity} handles the communication +between the Android framework and your native code, so you do not have to subclass it or call its +methods. All you need to do is declare your application to be native in your +{@code AndroidManifest.xml} file, and begin creating your native application.
+ +An Android application using {@link android.app.NativeActivity} still runs in its own virtual +machine, sandboxed from other applications. You can therefore still access Android framework APIs +through the JNI. In certain cases, however–such as for sensors, input events, and +assets–the NDK provides native interfaces that you can use instead of having to call +across the JNI. For more information about such support, see +Stable APIs.
+ +Regardless of whether or not you are developing a native activity, we recommend that you create +your projects with the traditional Android build tools. Doing so helps ensure building and packaging +of Android applications with the correct structure.
+ +The Android NDK provides you with two choices to implement your native activity:
+ +The {@code <ndk_root>/sources/android/native_app_glue/android_native_app_glue.c} source is +also available, allowing you to modify the implementation.
+For more information on how to use this static library, examine the native-activity sample +application and its documentation. Further reading is also available in the comments in the {@code <ndk_root>/sources/android/native_app_glue/android_native_app_glue.h} file.
+ +To implement a native activity with the {@code native-activity.h} interface:
+ +Because your application has no Java code, set {@code android:hasCode} to {@code false}.
+ ++<application android:label="@string/app_name" android:hasCode="false"> ++ +
You must set the {@code android:name} attribute of the activity tag to +{@link android.app.NativeActivity}.
+ ++<activity android:name="android.app.NativeActivity" + android:label="@string/app_name"> ++
Note: You can subclass {@link android.app.NativeActivity}. If you +do, use the name of the subclass instead of {@link android.app.NativeActivity}.
+The {@code android:value} attribute of the {@code meta-data} tag specifies the name of the shared +library containing the entry point to the application (such as C/C++ {@code main}), omitting the +{@code lib} prefix and {@code .so} suffix from the library name.
+ ++ <meta-data android:name="android.app.lib_name" + android:value="native-activity" /> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> + </manifest> ++ +
+$ cd <path>/<to>/<project> +$ <ndk>/ndk-build ++ +
You can find further information on using {@code native-activity.h} here.
+ + + diff --git a/docs/html-ndk/ndk/guides/cpp-support.jd b/docs/html-ndk/ndk/guides/cpp-support.jd new file mode 100644 index 000000000000..60541815ff28 --- /dev/null +++ b/docs/html-ndk/ndk/guides/cpp-support.jd @@ -0,0 +1,328 @@ +page.title=C++ Library Support +@jd:body + +The Android platform provides a very minimal C++ runtime support library ({@code libstdc++}). +This minimal support does not include, for example:
+ +The NDK provides headers for use with this default library. In addition, the NDK provides a +number of helper runtimes that provide additional features. This page provides information about +these helper runtimes, their characteristics, and how to use them. +
+ +Table 1 provides names, brief explanations, and features of runtimes available inthe NDK.
+ ++ Table 1. NDK Runtimes and Features.
+ +| Name | +Explanation> + | Features + |
|---|---|---|
| {@code libstdc++} (default) | +The default minimal system C++ runtime library. | +N/A | +
| {@code gabi++_static} | +The GAbi++ runtime (static). | +C++ Exceptions and RTTI | +
| {@code gabi++_shared} | +The GAbi++ runtime (shared). | +C++ Exceptions and RTTI | +
| {@code stlport_static} | +The STLport runtime (static). | +C++ Exceptions and RTTI; Standard Library | +
| {@code stlport_shared} | +The STLport runtime (shared). | +C++ Exceptions and RTTI; Standard Library | +
| {@code gnustl_static} | +The GNU STL (static). | +C++ Exceptions and RTTI; Standard Library | +
| {@code gnustl_shared} | +The GNU STL (shared). | +C++ Exceptions and RTTI; Standard Library | +
| {@code c++_static} | +The LLVM libc++ runtime (static). | +C++ Exceptions and RTTI; Standard Library | +
| {@code c++_shared} | +The LLVM libc++ runtime (shared). | +C++ Exceptions and RTTI; Standard Library | +
Use the {@code APP_STL} variable in your +{@code Application.mk} file to specify the runtime you wish to use. Use the values in +the "Name" column in Table 1 as your setting. For example:
+ ++APP_STL := gnustl_static ++ +
You may only select one runtime for your app, and can only do in +{@code Application.mk}.
+ +Even if you do not use the NDK build system, you can still use STLport, libc++ or GNU STL. +For more information on how to use these runtimes with your own toolchain, see Standalone Toolchain.
+ +This runtime only provides the following headers, with no support beyond them:
+This runtime provides the same headers as the default runtime, but adds support for RTTI +(RunTime Type Information) and exception handling.
+ + +This runtime is an Android port of STLport +(http://www.stlport.org). It provides a complete set of C++ +standard library headers. It also, by embedding its own instance of GAbi++, provides support for +RTTI and exception handling.
+ +While shared and static versions of this runtime are avilable, we recommend using the shared +version. For more information, see Static runtimes.
+ +The shared library file is named {@code libstlport_shared.so} instead of {@code libstdc++.so} +as is common on other platforms.
+ +In addition to the static- and shared-library options, you can also force the NDK to +build the library from sources by adding the following line to your {@code Application.mk} +file, or setting it in your environment prior to building:
+ ++STLPORT_FORCE_REBUILD := true ++ + +
This runtime is the GNU Standard C++ Library, ({@code libstdc++-v3}). Its shared library file is +named {@code libgnustl_shared.so}.
+ + +This runtime is an Android port of LLVM libc++. Its +shared library file is named {@code libc++_shared.so}.
+ +By default, this runtime compiles with {@code -std=c++11}. As with GNU {@code libstdc++}, you +need to explicitly turns on exceptions or rtti support. For information on how to do this, see +C++ Exceptions and RTTI.
+ +The NDK provides prebuilt static and shared libraries for {@code libc++} compiled by Clang 3.4, +but you can force the NDK to rebuild {@code libc++} from sources by adding the following line to +your {@code Application.mk} file, or setting it in your environment prior to building:
+ ++LIBCXX_FORCE_REBUILD := true ++ +
If you include {@code <atomic>}, it's likely that you also need {@code libatomic}. +If you are using {@code ndk-build}, add the following line:
+ ++LOCAL_LDLIBS += -latomic ++ +
If you are using your own toolchain, use:
+ ++-latomic ++ +
Note: {@code -latomic} is only available for GCC 4.8. +Because Clang 3.5 and Clang 3.6 use GCC 4.8's headers and libraries, as well as its +{@code as} and {@code ld} options, those versions of Clang also get {@code -latomic}.
+ + +Around 99% of tests pass when compiling {@code libc++} with Clang 3.4 for all supported ABIs. +The failures are mostly in the areas of {@code wchar_t} and locales that Android bionic +doesn't support. Switching locale from the default produces the following warning in +{@code logcat}:
+ ++newlocale() WARNING: Trying to set locale to en_US.UTF-8 other than "", "C" or "POSIX" ++ +
We do not recommend using {@code libc++} with GCC 4.6 because of GCC 4.6's limited c++11 +support.
+ +For information on {@code libc++} tests that fail to compile, {@code black_list*} in +{@code $NDK/tests/device/test-libc++-shared-full/jni/Android.mk}. For information about tests +that fail to run correctly, see {@code $NDK/tests/device/test-libc++-shared-full/BROKEN_RUN}. +{@code $NDK}, here, is the your NDK installation's root directory.
+ + +In all versions of the NDK later than NDKr5, the NDK toolchain allows you to use C++ runtimes +that support exception handling. However, to ensure compatibility with earlier releases, it +compiles all C++ sources with {@code -fno-exceptions} support by default. You can enable C++ +exceptions either for your entire app, or for individual modules. + +
To enable exception-handling support for your entire app, add the following line to +your {@code Application.mk} file. +To enable exception-handling support for individual modules', add the following line to +their respective {@code Android.mk} files.
+ ++APP_CPPFLAGS += -fexceptions ++ +
In all versions of the NDK later than NDKr5, the NDK toolchain allows you to use C++ runtimes +that support RTTI. However, to ensure compatibility with earlier releases, it compiles all C++ +sources with {@code -fno-rtti} by default. + +
To enable RTTI support for your entire app for your entire application, add the following line to +your {@code Application.mk} file: + +
+APP_CPPFLAGS += -frtti ++ +To enable RTTI support for individual modules, add the following line to +their respective {@code Android.mk} files: + +
+LOCAL_CPP_FEATURES += rtti ++ +Alternatively, you can use: + +
+LOCAL_CPPFLAGS += -frtti ++ +
Linking the static library variant of a C++ runtime to more than one binary may result in +unexpected behavior. For example, you may experience:
+ +In addition, if you link two shared libraries–or a shared library and an executable– +against the same static runtime, the final binary image of each shared library includes a copy of +the runtime's code. Having multiple instances of runtime code is problematic because of duplication +of certain global variables that the runtime uses or provides internally.
+ +This problem does not apply to a project comprising a single shared library. For example, +you can link against {@code stlport_static}, and expect your app to behave correctly. If your +project requires several shared library modules, we recommend that you use the shared library +variant of your C++ runtime.
+ +If your app targets a version of Android earlier than Android 4.3 (Android API level 18), +and you use the shared library variant of a given C++ runtime, you must load the shared library +before any other library that depends on it.
+ +For example, an app may have the following modules:
+ +You must need to load the libraries in reverse dependency order:
+
+ static {
+ System.loadLibrary("stlport_shared");
+ System.loadLibrary("bar");
+ System.loadLibrary("foo");
+ }
+
+
+Note: Do not use the {@code lib} prefix when calling +{@code System.loadLibrary()}.
+ +STLport is licensed under a BSD-style open-source license. See +{@code $NDK/sources/cxx-stl/stlport/README} for more details about STLport.
+ +GNU libstdc++ is covered by the GPLv3 license, and not the LGPLv2 or LGPLv3. For +more information, see +License on the GCC website.
+ +LLVM {@code libc++} +is dual-licensed under both the University of Illinois "BSD-Like" license and the MIT license.
\ No newline at end of file diff --git a/docs/html-ndk/ndk/guides/cpu-arm-neon.jd b/docs/html-ndk/ndk/guides/cpu-arm-neon.jd new file mode 100644 index 000000000000..32e9942b8e7c --- /dev/null +++ b/docs/html-ndk/ndk/guides/cpu-arm-neon.jd @@ -0,0 +1,109 @@ +page.title=NEON Support +@jd:body + +The NDK supports the ARM Advanced SIMD, an optional instruction-set extension of the ARMv7 spec. +NEON provides a set of scalar/vector instructions and registers (shared with the FPU) comparable to +MMX/SSE/3DNow! in the x86 world. To function, it requires VFPv3-D32 (32 hardware FPU 64-bit +registers, instead of the minimum of 16).
+ +The NDK supports the compilation of modules or even specific source files with support for NEON. +As a result, a specific compiler flag enables the use of GCC ARM NEON intrinsics and VFPv3-D32 +at the same time.
+ +Not all ARMv7-based Android devices support NEON, but devices that do may benefit significantly
+from its support for scalar/vector instructions. For x86 devices, the NDK can also translate NEON
+instructions into SSE, although with several restrictions. For more information, see
+Using LOCAL_ARM_NEON
+ To have the NDK build all its source files with NEON support, include the following line in
+your module definition: It can be especially useful to build all source files with NEON support if you want to build a
+static or shared library that specifically contains NEON code paths. When listing source files for your {@code LOCAL_SRC_FILES} variable, you have the option of
+using the {@code .neon} suffix to indicate that you want to build binaries with NEON support.
+For example, the following example builds one file with {@code .neon} support, and another
+without it: You can combine the {@code .neon} suffix with the {@code .arm} suffix, which specifies the 32-bit
+ARM instruction set for non-NEON instructions. In such a definition, {@code arm} must come before
+{@code neon}. For example: {@code foo.c.arm.neon} works, but {@code foo.c.neon.arm} does not. NEON support only works with the {@code armeabi-v7a} and {@code x86} ABIs. If the NDK build
+scripts encounter other ABIs while attempting to build with NEON support, the NDK build scripts
+exit. x86 provides partial NEON support via translation header. It is
+important to use checks like the following in your
+{@code Android.mk} file: Your app must perform runtime detection to confirm that NEON-capable machine code can be run on
+the target device. This is because not all ARMv7-based Android devices support NEON. The app can
+perform this check using the
+{@code cpufeatures} library that comes with
+this NDK. You should explicitly check that {@code android_getCpuFamily()} returns {@code
+ANDROID_CPU_FAMILY_ARM}, and that {@code android_getCpuFeatures()} returns a value including the
+{@code ANDROID_CPU_ARM_FEATURE_NEON flag} set. For example: The source code for the NDK's hello-neon sample provides an example of how to use the
+{@code cpufeatures} library and NEON intrinsics at the same time. This sample implements a tiny
+benchmark for a FIR filter loop using a C version, and a NEON-optimized one for devices that
+support it. The NDK provides a small library named {@code cpufeatures} that your app can use at runtime to
+detect the target device's CPU family and the optional features it supports. It is designed to work
+as-is on all official Android platform versions. The {@code cpufeatures} library is available as an import module. To use it, follow the procedure
+below: Here is a simple example of an {@code Android.mk} file that imports the {@code cpufeatures}
+library: The {@code cpufeatures} library provides two functions. The first function returns the family to
+which the device's CPU belongs. Declare it as follows: The function returns one of the following enums, representing the CPU family/architecture that
+the device supports. For a 32-bit executable on a 64-bit system, this function returns only the 32-bit value. The second function returns the set of optional features that the device's CPU supports. Declare
+it as follows:
+
+ The return value takes the form of a set of bit flags, each flag representing one
+CPU-family-specific feature. The rest of this section provides information on features for
+the respective families. The following flags are available for the 32-bit ARM CPU family: This value is equivalent to the {@code VFPv3-D16} instruction set, which provides provides only
+16 hardware double-precision FP registers. The following flags are available for the 64-bit ARM CPU family: The following flags are available for the 32-bit x86 CPU family.
+ {@code android_getCpuFeatures()} returns {@code 0} for CPU families for which there are no
+listed extensions. The following function returns the maximum number of CPU cores on the target device: For the complete change history of this library, see the comments in
+{@code $NDK/sources/android/cpufeatures/cpu-features.c}, where {@code $NDK} is the root of your
+NDK installation.
+LOCAL_ARM_NEON := true
+
+
+Using the .neon Suffix
+
+LOCAL_SRC_FILES := foo.c.neon bar.c
+
+
+Build Requirements
+
+# define a static library containing our NEON code
+ifeq ($(TARGET_ARCH_ABI),$(filter $(TARGET_ARCH_ABI), armeabi-v7a x86))
+include $(CLEAR_VARS)
+LOCAL_MODULE := mylib-neon
+LOCAL_SRC_FILES := mylib-neon.c
+LOCAL_ARM_NEON := true
+include $(BUILD_STATIC_LIBRARY)
+endif # TARGET_ARCH_ABI == armeabi-v7a || x86
+
+
+Runtime Detection
+
+#include <cpu-features.h>
+...
+...
+if (android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM &&
+ (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0)
+{
+ // use NEON-optimized routines
+ ...
+}
+else
+{
+ // use non-NEON fallback routines instead
+ ...
+}
+
+...
+
+
+Sample Code
+On this page
+
+
+
+ Usage
+
+
+
+
+LOCAL_STATIC_LIBRARIES := cpufeatures
+
+
+$(call import-module,android/cpufeatures)
+
+
+
+<project-path>/jni/Android.mk:
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := <your-module-name>
+LOCAL_SRC_FILES := <your-source-files>
+LOCAL_STATIC_LIBRARIES := cpufeatures
+include $(BUILD_SHARED_LIBRARY)
+
+$(call import-module,android/cpufeatures)
+
+Functions
+
+AndroidCpuFamily android_getCpuFamily();
+
+
+
+
+
+
+uint64_t android_getCpuFeatures();
+
+
+32-bit ARM CPU family
+
+
+
+
+64-bit ARM CPU family
+
+
+
+
+32-bit x86 CPU family
+
+
+
+
+
+int android_getCpuCount(void);
+
+
+MIPS CPU family
+
+
+
+
+Change History
+
This section introduces you to debugging with the NDK. It includes:
+ndk-gdb, which allows you to launch a native debugging session for your NDK-generated machine code.logcat in your debugging. To use the NDK, you must download it and install it separately from the SDK. To do so, follow these directions. \ No newline at end of file +
This section provides the information you need to get up and running +with the NDK.
+This section discusses libraries included with the NDK, as well as how to use other people's libraries and modules in your own application. It discusses:
+This section provides a high-level explanation of how the NDK works. The Android NDK is a set of tools allowing you to embed C or C++ (“native code”) into your Android apps. The ability to use native code in Android apps can be particularly useful to developers who wish to do one or more of the following: \ No newline at end of file diff --git a/docs/html-ndk/ndk/guides/mips.jd b/docs/html-ndk/ndk/guides/mips.jd new file mode 100644 index 000000000000..1aa1868db7ad --- /dev/null +++ b/docs/html-ndk/ndk/guides/mips.jd @@ -0,0 +1,43 @@ +page.title=MIPS Support +@jd:body + +
The NDK supports the {@code mips} ABI, which allows native code to run on Android-based devices +that have CPUs supporting the MIPS32 instruction set.
+ +To generate MIPS machine code, include {@code mips} in your +{@code Application.mk} file's +{@code APP_ABI} definition. For example:
+ ++APP_ABI := mips ++ +
For more information about defining the {@code APP_ABI} variable, see +{@code Application.mk}.
+ +The build system places generated libraries into {@code $PROJECT/libs/mips/}, where +{@code $PROJECT} represents your project's root directory, and embeds them in your APK under +{@code /lib/mips/}.
+ +The Android package manager extracts these libraries when installing your APK on a compatible +MIPS-based device, placing them under your app's private data directory.
+ +In the Google Play store, the server filters applications so that a consumer sees only the native +libraries that run on the CPU powering his or her device.
+ +MIPS support requires, at minimum, Android 2.3 (Android API level 9). If your project files +target an older API level, but include MIPS as a targeted platform, the NDK build script +automatically selects the right set of native platform headers/libraries for you.
\ No newline at end of file diff --git a/docs/html-ndk/ndk/guides/ndk-build.jd b/docs/html-ndk/ndk/guides/ndk-build.jd new file mode 100644 index 000000000000..d52d22464bda --- /dev/null +++ b/docs/html-ndk/ndk/guides/ndk-build.jd @@ -0,0 +1,194 @@ +page.title=ndk-build +@jd:body + +ndk-build is a tiny shell script introduced in Android NDK r4. Its purpose +is simply to invoke the right NDK build script. + +
+$GNUMAKE -f <ndk>/build/core/build-local.mk +<parameters> ++ +
$GNUMAKE points to GNU Make 3.81 or later, and
+<ndk> points to your NDK installation directory. You can use
+this information to invoke ndk-build from other shell scripts, or even your own
+make files.
ndk-build lives in the top level the NDK installation directory. To run it from the +command line, invoke it while in or under your application project directory. +For example:
+ ++cd <project> +$ <ndk>/ndk-build ++ +
In this example, <project> points to your
+project’s root directory, and <ndk> is the directory where
+you installed the NDK. As noted in Setup, you can add {@code $NDK} to your
+{@code PATH} to avoid having to type the whole filepath every time you use ndk-build.
+Alternatively, you can create an alias.
All parameters to ndk-build are passed directly to the underlying GNU {@code make}
+command that runs the NDK build scripts. Combine ndk-build and
+options in the form ndk-build <option>. For example:
+$ ndk-build clean ++ +
The following options are available:
+Application.mk file pointed to by the
+ {@code NDK_APPLICATION_MK} variable.To build from Eclipse, make sure that you have configured it as described in
+Setup. If you
+wish to build using the default ndk-build command, with no
+options, you can just build your project just as you would any Android project.
+To get Eclipse to add any of the options described above, follow these steps:
+Figure 1. Specifying a debug build from within +Eclipse
+ +Use the NDK_DEBUG option and, in certain cases,
+{@code AndroidManifest.xml} to specify debug or release build,
+optimization-related behavior, and inclusion of symbols. Table 1 shows the
+results of each possible combination of settings.
Table 1. Results of NDK_DEBUG (command line) and
+android:debuggable (manifest) combinations.
| NDK_DEBUG=0 | NDK_DEBUG=1 | NDK_DEBUG not specified + | |
|---|---|---|---|
| android:debuggble="true" | Debug; Symbols; Optimized*1 + | Debug; Symbols; Not optimized*2 | (same as NDK_DEBUG=1) + |
| android:debuggable="false" | Release; Symbols; Optimized + | Release; Symbols; Not optimized | Release; No symbols; +Optimized*3 |
Note: {@code NDK_DEBUG=0} is the equivalent of +{@code APP_OPTIM=release}, and complies with the GCC {@code -O2} option. {@code NDK_DEBUG=1} is the +equivalent of {@code APP_OPTIM=debug} in {@code Application.mk}, and complies with the GCC +{@code -O0} option. For more information about {@code APP_OPTIM}, see +Application.mk.
+The syntax on the command line is, for example:
+ ++$ ndk-build NDK_DEBUG=1 ++ +
If you are using build tools from prior to SDK r8, you must also modify your +{@code AndroidManifest.xml} file to specify debug mode. The syntax for doing so resembles the +following:
+ +<application android:label="@string/app_name" +android:debuggable="true"> ++ +From SDK r8 onward, you do not need to touch {@code AndroidManifest.xml}. Building a debug package +(e.g. with ant debug or the corresponding option of the ADT plugin) causes the tool automatically to +pick the native debug files generated with {@code NDK_DEBUG=1}. + + +
Some toolchains come with both 64-bit and 32-bit versions. For example, +directories {@code <ndk>/toolchain/<name>/prebuilt/} and +{@code <ndk>/prebuilt/} may contain both {@code linux-x86} and +{@code linux-x86_64} folders for Linux tools in 32-bit and 64-bit modes, +respectively. The ndk-build script automatically chooses a 64-bit version of +the toolchain if the host OS supports it. You can force the use of a 32-bit +toolchain by using {@code NDK_HOST_32BIT=1} either in your environment or +on the ndk-build command line.
+Note that 64-bit tools utilize host resources better (for instance, they are faster, and handle +larger programs), and they can still generate 32-bit binaries for Android.
+ +You need GNU Make 3.81 or later to use ndk-build or the NDK in general. +The build scripts will detect a non-compliant Make tool, and generate an error +message.
+If you have GNU Make 3.81 installed, but the default make
+command doesn’t launch it, define {@code GNUMAKE} in your environment to point to it
+before launching ndk-build. For example:
+$ export GNUMAKE=/usr/local/bin/gmake +$ ndk-build ++ +
You can override other host prebuilt tools in {@code $NDK/prebuilt/<OS>/bin/} +with the following environment variables:
+ ++$ export NDK_HOST_AWK=<path-to-awk> +$ export NDK_HOST_ECHO=<path-to-echo> +$ export NDK_HOST_CMP=<path-to-cmp> +diff --git a/docs/html-ndk/ndk/guides/ndk-gdb.jd b/docs/html-ndk/ndk/guides/ndk-gdb.jd new file mode 100644 index 000000000000..2370ba2a90f6 --- /dev/null +++ b/docs/html-ndk/ndk/guides/ndk-gdb.jd @@ -0,0 +1,241 @@ +page.title=ndk-gdb +@jd:body + +
The NDK includes a helper shell script named {@code ndk-gdb} to easily launch a native debugging + session for your NDK-generated machine code.
+ +For native debugging to work, you must follow these requirements:
+ ++cd $PROJECT +$NDK/ndk-gdb ++ +
Here, {@code $PROJECT} points to your project's root directory, and {@code $NDK} points to your +NDK installation path.
+ +When you invoke {@code ndk-gdb}, it configures the session to look for your source files +and symbol/debug versions of your generated native libraries. On successfully attaching to your +application process, {@code ndk-gdb} outputs a long series of error messages, noting that it cannot +find various system libraries. This is normal, because your host machine does not contain +symbol/debug versions of these libraries on your target device. You can safely ignore these +messages.
+ +Next, {@code ndk-gdb} displays a normal GDB prompt.
+ +You interact with {@code ndk-gdb} in the same way as you would with GNU GDB. For example, you can +use {@code b <location>} to set breakpoints, and {@code c} (for "continue") to +resume execution. For a comprehensive list of commands, see the +GDB manual.
+ +Note that when you quit the GDB prompt, the application process that you're debugging stops. This +behavior is a gdb limitation.
+ +{@code ndk-gdb} handles many error conditions, and displays an informative error message if it +finds a problem. these checks include making sure that the following conditions are satisfied:
+ +By default, {@code ndk-gdb} searches for an already-running application process, and displays an +error if it doesn't find one. You can, however, use the {@code --start} or +{@code --launch=<name>} option to automatically start your activity before the debugging +session. For more information, see Options.
+ + +To see a complete list of options, type {@code ndk-gdb --help} on the command line. Table 1 +shows a number of the more commonly used ones, along with brief descriptions.
+ ++ Table 1. Common ndk-gdb options and their descriptions.
+ +| Option | +Description> | +
|---|---|
| {@code --verbose} | +This option tells the build system to print verbose information about the native-debugging +session setup. It is necessary only for debugging problems when the debugger can't connect to the +app, and the error messages that {@code ndk-gdb} displays are not enough. |
+
| {@code --force} | +By default, {@code ndk-gdb} aborts if it finds that another native debugging session is already + running on the same device. This option kills the other session, and replaces it with a new one. + Note that this option does not kill the actual app being debugged, which you must kill + separately. | +
| {@code --start} | +When you start {@code ndk-gdb}, it tries by default to attach to an existing running instance of +your app on the target device. You can override this default behavior by using {@code --start} to +explicitly launch the application on the target device before the debugging session. |
+
+
| {@code --launch=<name>} | +This option is similar to {@code --start}, except that it allows you to start a specific + activity from your application. This feature is only useful if your manifest defines multiple + launchable activities. |
+
| {@code --launch-list} | +This convenience option prints the list of all launchable activity names found in your + app manifest. {@code --start} uses the first activity name. |
+
| {@code --project=<path>} | +This option specifies the app project directory. It is useful if you want to launch the + script without first having to change to the project directory. | +
| {@code --port=<port>} | + By default, {@code ndk-gdb} uses local TCP port 5039 to communicate with the app it + is debugging on the target device. Using a different port allows you to natively debug programs + running on different devices or emulators connected to the same host machine. |
+
| {@code --adb=<file>} | +This option specifies the adb +tool executable. It is only necessary if you have not set your path to include that executable. + |
+
|
+ |
+These flags are similar to the adb commands with the same names. Set these flags if you have +several devices or emulators connected to your host machine. Their meanings are as follows: +
Alternatively, you can define the {@code ADB_SERIAL} environment variable to list a specific +device, without the need for a specific option. |
+
|
+ |
+This option tells {@code ndk-gdb} to run the GDB initialization commands found in +{@code <file>} after connecting to the process it is debugging. This is a useful feature if +you want to do something repeatedly, such as setting up a list of breakpoints, and then resuming +execution automatically. |
+
| {@code --nowait} | +Disable pausing the Java code until GDB connects. Passing this option may cause the debugger + to miss early breakpoints. + |
| {@code --tui} +{@code -t} | +Enable Text User Interface if it is available. |
+
| {@code --gnumake-flag=<flag>} | +This option is an extra flag (or flags) to pass to the +{@code ndk-build} system when +querying it for project information. You can use multiple instances of this option in the +same command. |
+
| {@code --stdcxx-py-pr={auto|none|gnustdcxx[-GCCVER]|stlport}} | +Use specified Python pretty-printers for displaying types in the Standard C++ Library. + {@code auto} mode works by looking at the {@code .so} files for a {@code libstdc++} library, + and as such only works for a shared library. When linking statically to a {@code libstdc++} library, + you must specify the required printers. The default is {@code none}. |
+
Note: The final three options in this table are only for the +Python version of {@code ndk-gdb}.
+ +If your app runs on a platform older than Android 2.3 (API level 9), {@code ndk-gdb} +cannot debug native threads properly. The debugger can only debug the main thread, abd completely +ignores the execution of other threads.
+ +Using a version of Android prior to 2.3 causes {@code ndk-gdb} to display the following message +prior to showing the GDB prompt:
+ ++Thread debugging is unsupported on this Android platform! ++ + +
If you place a breakpoint on a function executed on a non-main thread, the program exits, and +GDB displays the following message:
+ ++Program terminated with signal SIGTRAP, Trace/breakpoint trap. + The program no longer exists. +diff --git a/docs/html-ndk/ndk/guides/ndk-stack.jd b/docs/html-ndk/ndk/guides/ndk-stack.jd new file mode 100644 index 000000000000..27c752af12c8 --- /dev/null +++ b/docs/html-ndk/ndk/guides/ndk-stack.jd @@ -0,0 +1,84 @@ +page.title=ndk-stack +@jd:body + +
The {@code ndk-stack} tool allows you to filter stack traces as they appear in the +output of {@code adb logcat}, and replace any address inside a shared library with the corresponding +{@code <source-file>:<line-number>} values.
+ +For example, it translates something like:
+ ++I/DEBUG ( 31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** +I/DEBUG ( 31): Build fingerprint: 'generic/google_sdk/generic/:2.2/FRF91/43546:eng/test-keys' +I/DEBUG ( 31): pid: 351, tid: 351 %gt;%gt;%gt; /data/local/ndk-tests/crasher <<< +I/DEBUG ( 31): signal 11 (SIGSEGV), fault addr 0d9f00d8 +I/DEBUG ( 31): r0 0000af88 r1 0000a008 r2 baadf00d r3 0d9f00d8 +I/DEBUG ( 31): r4 00000004 r5 0000a008 r6 0000af88 r7 00013c44 +I/DEBUG ( 31): r8 00000000 r9 00000000 10 00000000 fp 00000000 +I/DEBUG ( 31): ip 0000959c sp be956cc8 lr 00008403 pc 0000841e cpsr 60000030 +I/DEBUG ( 31): #00 pc 0000841e /data/local/ndk-tests/crasher +I/DEBUG ( 31): #01 pc 000083fe /data/local/ndk-tests/crasher +I/DEBUG ( 31): #02 pc 000083f6 /data/local/ndk-tests/crasher +I/DEBUG ( 31): #03 pc 000191ac /system/lib/libc.so +I/DEBUG ( 31): #04 pc 000083ea /data/local/ndk-tests/crasher +I/DEBUG ( 31): #05 pc 00008458 /data/local/ndk-tests/crasher +I/DEBUG ( 31): #06 pc 0000d362 /system/lib/libc.so +I/DEBUG ( 31): ++ +
Into the more readable output:
+ ++********** Crash dump: ********** +Build fingerprint: 'generic/google_sdk/generic/:2.2/FRF91/43546:eng/test-keys' +pid: 351, tid: 351 >>> /data/local/ndk-tests/crasher <<< +signal 11 (SIGSEGV), fault addr 0d9f00d8 +Stack frame #00 pc 0000841e /data/local/ndk-tests/crasher : Routine zoo in /tmp/foo/crasher/jni/zoo.c:13 +Stack frame #01 pc 000083fe /data/local/ndk-tests/crasher : Routine bar in /tmp/foo/crasher/jni/bar.c:5 +Stack frame #02 pc 000083f6 /data/local/ndk-tests/crasher : Routine my_comparison in /tmp/foo/crasher/jni/foo.c:9 +Stack frame #03 pc 000191ac /system/lib/libc.so +Stack frame #04 pc 000083ea /data/local/ndk-tests/crasher : Routine foo in /tmp/foo/crasher/jni/foo.c:14 +Stack frame #05 pc 00008458 /data/local/ndk-tests/crasher : Routine main in /tmp/foo/crasher/jni/main.c:19 +Stack frame #06 pc 0000d362 /system/lib/libc.so ++ +
To use {@code ndk-stack}, you first need a directory containing symbolic versions of your app's +shared libraries. If you use the NDK build system ({@code ndk-build}), these shared-library +files reside under {@code $PROJECT_PATH/obj/local/<abi>}, where {@code <abi>} represents +your device's ABI. By default, the system uses the {@code armeabi} ABI.
+ +There are two ways to use the tool. You can feed the logcat text as direct input to the program. +For example:
+ ++adb logcat | $NDK/ndk-stack -sym $PROJECT_PATH/obj/local/armeabi ++ +
You can also use the {@code -dump} option to specify the logcat as an input file. For example: +
+ ++adb logcat > /tmp/foo.txt +$NDK/ndk-stack -sym $PROJECT_PATH/obj/local/armeabi -dump foo.txt ++ +
When it begins parsing the logcat output, the tool looks for an initial line of asterisks. +For example:
+ ++*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ++ +
Note: When copy/pasting traces, don't forget this line, or +{@code ndk-stack} won't work correctly.
\ No newline at end of file diff --git a/docs/html-ndk/ndk/guides/prebuilts.jd b/docs/html-ndk/ndk/guides/prebuilts.jd new file mode 100644 index 000000000000..f0530d197a44 --- /dev/null +++ b/docs/html-ndk/ndk/guides/prebuilts.jd @@ -0,0 +1,145 @@ +page.title=Using Prebuilt Libraries +@jd:body + +The NDK supports the use of prebuilt libraries, both static and shared. There are two principal +use cases for this functionality:
+ +This page explains how to use prebuilt libraries.
+ +You must declare each prebuilt library you use as a single independent module. To do + so, perform the following steps: + +
Note: You must make sure to select the version of your prebuilt + library appropriate to your target ABI. For more information on ensuring library support for + ABIs, see Selecting ABIs for Prebuilt Libraries.
Here is a trivial example that assumes that the prebuilt library {@code libfoo.so} resides in + the same directory as the {@code Android.mk} + file that describes it.
+ ++LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := foo-prebuilt +LOCAL_SRC_FILES := libfoo.so +include $(PREBUILT_SHARED_LIBRARY) ++ +
In this example, the name of the module is the same as that of the prebuilt library.
+ +The build system places a copy of your prebuilt shared library into {@code $PROJECT/obj/local}, +and another copy, stripped of debug information, into {@code $PROJECT/libs/<abi>}. Here, +{@code $PROJECT} is the root directory of your project.
+ +To reference a prebuilt library from other modules, specify its name as the value +of the {@code LOCAL_STATIC_LIBRARIES} or {@code LOCAL_SHARED_LIBRARIES} variable in the +{@code Android.mk} files associated with those +other modules.
+ +For example, the description of a module using {@code libfoo.so} might be as follows:
+ ++include $(CLEAR_VARS) +LOCAL_MODULE := foo-user +LOCAL_SRC_FILES := foo-user.c +LOCAL_SHARED_LIBRARIES := foo-prebuilt +include $(BUILD_SHARED_LIBRARY) ++ +
Here, {@code LOCAL_MODULE} is the name of the module referring to the prebuilt; {@code + LOCAL_SHARED_LIBRARIES} is the name of the prebuilt, itself.
+ +The code in {@code foo-user.c} depends on specific declarations that normally +reside in a header file, such as {@code foo.h}, distributed with the prebuilt library. +For example, {@code foo-user.c} might have a line like the following:
+ ++#include <foo.h> ++ +
In such a case, you need to provide the header and its include path to the compiler when you +build the {@code foo-user} module. A simple way to accomplish this task is to use exports in the +prebuilt module definition. For example, as long as header {@code foo.h} is located under the +{@code include} directory associated with the prebuilt module, you can declare it as follows:
+ ++include $(CLEAR_VARS) +LOCAL_MODULE := foo-prebuilt +LOCAL_SRC_FILES := libfoo.so +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include +include $(PREBUILT_SHARED_LIBRARY) ++ +
The {@code LOCAL_EXPORT_C_INCLUDES} definition here ensures that the build system +exports the path to the prebuilt library's {@code include} directory, prepending that path onto the +value of the {@code LOCAL_C_INCLUDES} for the module dependent on it.
+ +This operation allows the build system to find the necessary headers.
+ +We recommend that you provide prebuilt shared libraries containing debug symbols. The NDK build +system always strips the symbols from the version of the library that it installs into +{@code $PROJECT/libs/<abi>/}, but you can use the debug version for debugging with +{@code ndk-gdb}.
+ +You must make sure to select the right version of your prebuilt shared library for your targeted +ABI. The +{@code TARGET_ARCH_ABI} variable in the +{@code Android.mk} file can point the build system at the appropriate version of the library. +
+ +For example, assume that your project contains two versions of library {@code libfoo.so}:
+ ++armeabi/libfoo.so +x86/libfoo.so ++ +
The following snippet shows how to use {@code TARGET_ARCH_ABI} so that the build system selects + the appropriate version of the library:
+ ++include $(CLEAR_VARS) +LOCAL_MODULE := foo-prebuilt +LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libfoo.so +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include +include $(PREBUILT_SHARED_LIBRARY) ++ +
If you have specified {@code armeabi} as the value of {@code TARGET_ARCH_ABI}, the build system +uses the version of {@code libfoo.so} located in the {@code armeabi} directory. If you have +specified {@code x86} as the value {@code TARGET_ARCH_ABI}, the build system uses the version in the +{@code x86} directory.
\ No newline at end of file diff --git a/docs/html-ndk/ndk/guides/sample.jd b/docs/html-ndk/ndk/guides/sample.jd new file mode 100644 index 000000000000..18ca0b82a0b0 --- /dev/null +++ b/docs/html-ndk/ndk/guides/sample.jd @@ -0,0 +1,11 @@ +page.title=Sample Walkthroughs +@jd:body + +This section explains several of the sample apps provided with the NDK. It assumes that you already have a working knowledge of programming in Java and native code, and focuses on issues particular to working with the NDK.
+It discusses the following samples:
+ndk_helper class. This sample provides a bare-bones look at a minimal +application built with the NDK.
+ +The following two lines provide the name of the native source file, along +with the name of the shared library to build. The full name of the built +library is {@code libhello-jni.so}, but you should omit the +{@code lib} prefix and the {@code .so} extension.
+ ++LOCAL_SRC_FILES := hello-jni.c +LOCAL_MODULE := hello-jni ++ +
For more information on what this file does, and how to use it, see +Android.mk.
+ +This line tells the build system the architecture against which to build. If +you don't specify anything, the build system defaults to {@code armeabi}.
+ ++APP_ABI := all ++ +
For more information on what this file does, and how to use it, see +Application.mk.
+ +This file calls a function to retrieve a string from the native side, then +displays it on the screen.
+ +The source code contains three lines of particular interest to the NDK user. +They are presented here in the order in which they are used, rather than by +line order.
+ +This function call loads the {@code .so} file upon application startup.
+ +
+System.loadLibrary("hello-jni");
+
+
+The {@code native} keyword in this method declaration tells the +virtual machine that the function is in the shared library (i.e., implemented on the native side). +
+ ++public native String stringFromJNI(); ++ +
The Android framework calls the function loaded and declared in the +previous steps, displaying the string on the screen.
+ ++tv.setText( stringFromJNI() ); ++ +
This file contains a function that returns a string that the Java side +requested (see Java-side implementation). The function declaration is as +follows:
+ ++jstring Java_com_example_hellojni_HelloJni_stringFromJNI( +JNIEnv* env, + jobject x ) ++ +
This declaration corresponds to the native function declared in the +Java source code. The return type, {@code jstring}, is a data type defined +in the +Java Native +Interface Specification. It is not actually a string, but a +pointer to a Java string.
+ +After {@code jstring} comes the function name, which is based on the +Java function name and and the path to the file containing it. Construct it +according to the following rules:
+ +Based on these rules, in this example, the function name +{@code Java_com_example_hellojni_HelloJni_stringFromJNI} refers to a Java +function called {@code stringFromJNI()}, which resides in +{@code hellojni/src/com/example/hellojni/HelloJni.java}.
+ +Finally, {@code JNIEnv*} is the pointer to the VM, and +{@code jobject} is a pointer to the implicit {@code this} object passed from +the Java side.
+ +The following line calls the VM API {@code (*env)}, and passes it a return value: +that is, the string that the function on the Java side had requested.
+ ++return (*env)->NewStringUTF(env, "Hello from JNI ! +Compiled with ABI " ABI "."); +\ No newline at end of file diff --git a/docs/html-ndk/ndk/guides/sample_na.jd b/docs/html-ndk/ndk/guides/sample_na.jd new file mode 100644 index 000000000000..e6f36ba19f29 --- /dev/null +++ b/docs/html-ndk/ndk/guides/sample_na.jd @@ -0,0 +1,194 @@ +page.title=Sample: Native Activity +@jd:body + +
This is a very simple example of a purely native +application, with no Java source code. In the absence of any Java source, the +Java compiler still creates an executable stub for the Dalvik Virtual Machine +("DVM") to run. The stub serves as a wrapper for the actual, native program, +which lives in the .so file.
+The application itself simply renders a color onto the entire screen, and +then changes the color partly in response to detected movement.
+Make sure not to specify an Android API level lower than 9.
+<uses-sdk android:minSdkVersion="9" /> +
Because this application has only native code, specify
+android:hasCode as false.
<application android:label="@string/app_name" +android:hasCode="false"> +
Declare the NativeActivity class.
<activity android:name="android.app.NativeActivity" +
For android:value, provide the name of the shared library
+to be built, minus the initial lib and the .so
+extension. This value must be the same as the one you described for
+LOCAL_MODULE in Android.mk.
<meta-data android:name="android.app.lib_name" + android:value="native-activity" /> +
This file tells the build system the following information:
+The name of the shared library to generate.
+LOCAL_MODULE := native-activity +
The name of the native source-code file.
+LOCAL_SRC_FILES := main.c +
A list of external libraries that will be used in building the binary,
+each preceded by the -l (link-against) option.
Note that, for each library:
+lib, and ends with the
+.so extension. For example, the actual file name for the
+log library is liblog.so.<ndk>/platforms/android-<sdk_version>/arch-<abi>/usr/lib/.LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM +
A static library, android_native_app_glue, that the
+application uses to manage NativeActivity lifecycle events, along
+with touch input.
LOCAL_STATIC_LIBRARIES := android_native_app_glue +
The final line tells the build system to build this static library.
+ndk-build places the built library
+(libandroid_native_app_glue.a) into the obj directory
+generated during the build process. The next sample discusses the
+android_native_app_glue in more detail.
$(call import-module,android/native_app_glue) +
For more information about the Application.mk file, consult the Application.mk section of this guide.
+Application.mkThis line defines the minimum level of Android API Level support.
+APP_PLATFORM := android-10 +
Because there is no ABI definition, the build system defaults to +building only for armeabi.
+This file essentially contains the entire progam.
+The following includes correspond to the libraries, both shared and static,
+enumerated in Android.mk.
#include <EGL/egl.h> +#include <GLES/gl.h> + + +#include <android/sensor.h> +#include <android/log.h> +#include <android_native_app_glue> +
android_native_app_glue calls the following function,
+passing it a predefined state structure. It also serves as a wrapper that
+simplifies handling of NativeActivity callbacks.
void android_main(struct android_app* state) {
+Next, the program handles events queued by the glue library. The event +handler follows the state structure.
+struct engine engine; + + +// Make sure glue isn't stripped by suppressing link-time optimization that +removes unreferenced code. +app_dummy(); + + +memset(&engine, 0, sizeof(engine)); +state->userData = &engine; +state->onAppCmd = engine_handle_cmd; +state->onInputEvent = engine_handle_input; +engine.app = state; +
The application prepares to start monitoring the sensors, using the
+APIs in sensor.h.
engine.sensorManager = ASensorManager_getInstance(); + engine.accelerometerSensor = + ASensorManager_getDefaultSensor(engine.sensorManager, + ASENSOR_TYPE_ACCELEROMETER); + engine.sensorEventQueue = + ASensorManager_createEventQueue(engine.sensorManager, + state->looper, LOOPER_ID_USER, NULL, NULL); +
Now, a loop begins, in which the application polls the system for
+messages (sensor events). It sends messages to
+android_native_app_glue, which checks to see whether they match
+any onAppCmd events defined in android_main. When a
+match occurs, the message is sent to the handler for execution.
while (1) {
+ // Read all pending events.
+ int ident;
+ int events;
+ struct android_poll_source* source;
+
+
+ // If not animating, we will block forever waiting for events.
+ // If animating, we loop until all events are read, then continue
+ // to draw the next frame of animation.
+ while ((ident=ALooper_pollAll(engine.animating ? 0 : -1, NULL,
+&events,
+ (void**)&source)) >= 0) {
+
+
+ // Process this event.
+ if (source != NULL) {
+ source->process(state, source);
+ }
+
+
+ // If a sensor has data, process it now.
+ if (ident == LOOPER_ID_USER) {
+ if (engine.accelerometerSensor != NULL) {
+ ASensorEvent event;
+ while (ASensorEventQueue_getEvents(engine.sensorEventQueue,
+ &event, 1) > 0) {
+ LOGI("accelerometer: x=%f y=%f z=%f",
+ event.acceleration.x, event.acceleration.y,
+ event.acceleration.z);
+ }
+ }
+ }
+
+
+ // Check if we are exiting.
+ if (state->destroyRequested != 0) {
+ engine_term_display(&engine);
+ return;
+ }
+ }
+Once the queue is empty, and the program exits the polling loop, the +program calls OpenGL to draw the screen.
+ if (engine.animating) {
+ // Done with events; draw next animation frame.
+ engine.state.angle += .01f;
+ if (engine.state.angle > 1) {
+ engine.state.angle = 0;
+ }
+
+
+ // Drawing is throttled to the screen update rate, so there
+ // is no need to do timing here.
+ engine_draw_frame(&engine);
+ }
+}