Introduction to Android Development

Source: Internet
Author: User

This article is designed to help you learn the basics of Android development and quickly configure your work environment. The documentation is based on the Windows 7 configuration, but it also applies to Linux (Ubuntu), Mac OS X and other operating systems that support the Android SDK.

If you are still experiencing problems after completing the steps below, please contact us through the opencv4android discussion group or OPENCV Q&a Forum, and we will do our best to help you solve the problem.

First, preface (preface)

   Android is an open-source operating system based on the Linux kernel, a system developed by the Open handset Alliance, a company led by Google. For more information, please visit the Android website.

Android development is significantly different from other platform software development, before developing the Android program, we strongly recommend that you familiarize yourself with the following key points of knowledge:

1. The Java programming language is the main development language of the Android operating system, and you can access Oracle's introduction to java.

2. Java Native Interface (JNI) (Java Local interface) is a technique that allows native code to run on Java Virtual machine (Java VM). Also, you can access Oracle's introduction to JNI.

3. Android activity (Android activities) and its life cycle, which is very important to understand the Android API class.

4. OpenCV development clearly requires some knowledge about the specific Android Camera.

Second, Android development rapid environment configuration

If you are configuring from scratch, you can try the Tegra Android development Pack (TADP) released by Nvidia.

Note: Since the V2.0 version, the TADP development package already contains the OPENCV for Tegra SDK, which is our usual opencv4android SDK, except that it adds some Tegra-specific stuff.

    • Installation requires at least 1.6Gb of disk space.
    • TADP will download the Android SDK platform and the Android SDK for Google services, so please download it online (the wall may also be FQ).
    • At the end of the installation TADP may request your flash your development kit, if you don't have Tegra development kit, then ignore it.
    • (UNIX) TADP will request your root permission during the installation process. So you have to be a member of the sudo group.
Third, Android development manual environment configuration(i) Java development

In order to develop Android in a Java environment, the following software must be installed:

1. Sun JDK 6 (Sun JDK 7 also available)

2. Android SDK

3. Android SDK Components

4. Eclipse IDE

5. ADT Plugin for Eclipse

Detailed download and follow the procedure please visit the original text.

(ii) C + + Local development

In order to develop Android in C + + you need to install the following software:

1. Android NDK   

In order to compile C + + code under Android platform requires Android Native Development Kit (NDK) (Local development package).

You can download the latest NDK version from here and install the Android NDK just by extracting it to a folder on your computer.

Note: You can first read the official Android NDK documentation, which is in the NDK library docs/directory. The main document about using the NDK is the android-mk.html file. You can also visit application-mk.html, ndk-build.html, and cpu-arm-neon.html, cplusplus-support.html, prebuilts.html to learn some of the amount of information.

2.CDT plugin for Eclipse

Detailed download and follow the procedure please visit the original text.

iv. Android Program Structure

Typically, the source code of the Android program resembles the following structure:

    • Project root directory/
      • jni/
      • ibs/
      • res/
      • src/
      • Androidmanifest.xml
      • Project.Properties
      • ... Other documents ...

which

      • src The folder contains the Java code for the program
      • res folder contains the program's resources (Pictures, XML files, etc.),
      • lib folder contains a local (native) library file after the build was successfully built,
      • jni folder contains the C + + program source code and the NDK build script android.mk and Application.mk,
      • androidmanifest.xml file describes the system information of the Android program (program name, The main program's package name, program components, authorization, etc.). Android tools that use the Eclipse Wizard or the Android SDK can create the file.
      • project.properties is a text file, It contains information on the target Android platform and other build details. This file is produced by Eclipse or Android tools.

Note:AndroidManifest.xml and Project.Properties files are indispensable for compiling C + + parts, because the Android NDK build system relies on them, and if any of them does not exist, it will be compiled in C + + Some money compiles the Java section first.

v. ANDROID.MK and APPLICATION.MK scripts

The script android.mk usually has the following structure:

1 Local_path: = $ (call my-dir)  2  3include $ (clear_vars)  4 Local_ MODULE    : = <module_name> 5 local_src_files: = <list of. C and. CPP Project files> 6 <s ome variable name>: = <some variable value> 7... 8 <some variable name>: = <some variable value> 9 include $ (build_shared_ LIBRARY)

This is the most simplified android.mk, it can build the Android program C + + source code, it should be noted that the first two lines and the last line is any android.mk necessary.

Typically, application.mk is optional, but when you use Opencv,stl or C + + exceptions, you need to create it, and the general structure of APPLICATION.MK is as follows:

App_stl: = gnustl_staticapp_cppflags:=-frtti-fexceptionsapp_abi:= All

Note: We recommend setting App_abi:=all for all of the files, if you want to specify specific targets, you can use Armeabi for Armv5/armv6, armeabi-v7a for ARMV7, x86 for Intel kernel, Use MIPS for MIPS. All mentioned above are the binary interface Abi of the program, because C + + is CPU-oriented, so you have to specify the CPU model of the machine you are using, and most of the Android phones are armeabi-v7a CPU architectures at the moment.

VI. Building Program Local code using the command line

This is a standard way to compile the C + + native code for Android programs:

Warning: We strongly recommend using Cmd.exe (standard console) instead of Cygwin on Windows. You can use the latter only if you are very specific about your operation.

1. Open the console and go to the root directory of the Android application.

CD <root folder of the project>/

2. Run the following command

<path_where_NDK_is_placed>/Ndk-build

Note: On windows, we recommend using Ndk-build.cmd instead of the bash script Cygwin shell on the standard console (Cmd.exe).

3. After executing the above C + + code, the source code is compiled. The Java part of the program can then be compiled.

some parameters in the note:ndk-build can be set: Example 1:verbose compilation<path_where_NDK_is_placed>/ndk-build v=1 example 2:rebuildall <path_where_NDK_is_placed>/ndk-build-b

Vii. building program native code using eclipse

There are several possible ways to configure the integrated compilation environment for native C + + code that integrates the Android NDK into the eclipse build process. We recommend using the Eclipse CDT Builder-based approach.

The preconfigured CDT Builders for the sample project is already included in the OPENCV for Android package from version 2.4.2. For your own project you should follow these steps to set up:

1. Define the NDKROOT environment variable and set the path to the path named your system Android NDK. (For example, "X:\\apps\\android-ndk-r8" or "/opt/android-ndk-r8").

Note: You can also define the NDKROOT environment variable in Eclipse, but you will need to reset it when changing the workspace, if you prefer to configure the environment variable in this way, open the menu window, Preferences-C +--Build-environment, press add ... button, and then set the variable name to Ndkroot, set the variable value to your local Android NDK path.

2. Restart Eclipse app changes.

3. Open Eclipse loading Android program project.

4. Add A/C + + feature for the project by using the convert to a C + + project from the menu new

5. Select the project you want to convert, specify "project Type" = Makefile project, "Toolchains" = Other toolchain.

6. Open Project Properties, C + + Build. Cancel using the default build command to change the "build command" content from "make" to:

"${ndkroot}/ndk-build.cmd"  // on Windows "${ndkroot}/ndk-build"         // on Linux and MacOS.

7. Switch to the Behaviour tab and follow the display below to operate the "Workbench Build Type" section.

8. Press OK to ensure that the ndk-build can be successfully invoked.

9. If you open a C + + source file in the Eclipse Editor, you will see a syntax error callout. These are not true errors, and setting the CDT can eliminate these errors.

10. Open the Project Properties, C + + general Paths and Symbols. Then add the following include path for C + +.

1# forNDK R8 and prior:2${ndkroot}/Platforms/Android-9/Arch-arm/Usr/Include3${ndkroot}/Sources/Cxx-stl/Gnu-libstdc++/include4${ndkroot}/Sources/Cxx-stl/Gnu-libstdc++/Libs/armeabi-v7a/include5${projdirpath}/../../Sdk/Native/Jni/Includ

# forNDK r8b and Later:${ndkroot}/Platforms/Android-9/Arch-arm/Usr/Include${ndkroot}/Sources/Cxx-stl/Gnu-libstdc++/4.6/Include${ndkroot}/Sources/Cxx-stl/Gnu-libstdc++/4.6/Libs/armeabi-v7a/Include${projdirpath}/../../Sdk/Native/Jni/Include

The final path should be changed to the absolute path or relative path of the Opencv4android SDK. This will eliminate the syntax error token.

Eight, commissioning and testing

This section will learn how to set up simulators or hardware devices to test and debug Android applications.

(i) Android virtual device AVD (ii) hardware device (mobile)

The above two parts are relatively simple, detailed can refer to the original text.

(This part can be simplified, in fact, according to a 360 mobile phone assistant on it)

Nine, what should be done next?

Now that you have configured the Android development environment, you can continue to follow the opencv4android SDK. You can learn exactly how to do it in the standalone Opencv4android SDK tutorial.

Introduction to Android Development

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.