How to compile Android applications into image/ROM

Source: Internet
Author: User

Http://blog.csdn.net/silvervi/article/details/6315606

Sometimes we want to integrate our Android appProgramCompile to image/ROM, so that the program will be installed in the/system/APP directory and cannot be uninstalled. Below
I use my own program testjniapp as an exampleSource codeThe self-contained simplejni demonstrates how to compile your application into Rom.

1. Build the compiling environment

Compiling environment: Ubuntu 10.10
Android version: Android 2.2

During compilation, you may need to install necessary software on Ubuntu. I have installed the following software. Different systems may be different:
JDK 6 (Android official recommendations installed JDK 5, but I will encounter Java override issues during compilation, switch to 6 without any problem), Bison, lib64z1-dev, libasound2-dev, flex, gperf, libncurses5-dev

2. Application storage directory

Simplejni is a program written in Android ndk and Java, including the APK and so library files. Its SourceCodeUnder the development/samples/directory of the source tree.
In fact, the directory where package is stored during compilation is not clearly defined. The location of the APK and so files after compilation is determined by the compilation type specified by Android. mk in the directory, for example:

    • Android. MK contains a line of include $ (build_package), which indicates that the modules in the directory are compiled into a package, that is, the APK file. The default storage location is/system/app.
    • Android. MK contains the behavior include $ (build_shared_library), which indicates that the native. CPP is compiled as a shared library file, that is, the so file. The default storage location is/system/lib.

Therefore, if we want to compile our own program into an image, we only need to copy the entire project completed in eclipse to a directory under the source tree, I usually use packages/apps.

3. Add Android. mk

After completing the previous step, you can know that android. mk plays a crucial role in compiling. This is actually the make
File. To complete our work, we need to add Android. mk to the source code. You can add your own Android. mk as shown in simplejni.
Android. mk, just modify it. Let's first take a look at the content of two Android. mk in the simplejni directory:

    • Root
      Android. mk in the directory

Top_local_path: = $ (call my-DIR)

# Build Activity

Local_path: = $ (top_local_path)
Include $ (clear_vars)

Local_module_tags: = Samples

Local_src_files: = $ (call all-subdir-Java-files)

Local_package_name: = simplejni

Local_jni_shared_libraries: = libsimplejni

Local_proguard_enabled: = disabled

Include $ (build_package)

#===================================================== ==================================

# Also build all of the sub-targets under this one: the shared library.
Include $ (call all-makefiles-under, $ (local_path ))

The android. mk in the root directory determines the configuration of the entire project compilation,

Local_path defines the current directory

Local_mudule_tags
Defines the type of the current module. The Compiler may vary depending on the type during compilation, and some tags modules will not even be compiled into the system.
Local_mudule_tags mainly includes the following types: User debug Eng tests optional samples shell_ash

Shell_mksh. Optional indicates that all versions are compiled to the image under the compiling conditions, and the rest indicates that only the image will be compiled in this version, such as the user
Indicates that the image will be compiled into the image only in the user version.
For the MK file containing local_package_name, the default value is optinal. For details, see build/CORE/package. mk.
I am not quite clear about the specific role of samples defined in simplejni. For the sake of insurance, my own APK is generally defined as optional.

Local_src_files defines the Java code directory required for APK compilation.

Local_package_name: Change the name of your package.

Local_jni_shared_libraries defines the name of The so library file to be included. If your program does not use JNI, this line is not required.

Local_proguard_enabled defines the proguard compression method in Java Development, which is mainly used to analyze the compression program. I did not add this line in my own applications.

Include $ (build_package) is the key to build, indicating that the current Java code is built into APK

Include $ (call all-makefiles-under, $ (local_path) indicates the files of subdirectories in the directory to be built. In this way, the compilation system searches for Android in the subdirectories of the current directory. MK to compile other programs such as so.

According to the above, create my own Android. mk as follows:

Top_local_path: = $ (call my-DIR)

# Build Activity

Local_path: = $ (top_local_path)
Include $ (clear_vars)

Local_module_tags: = optional

Local_src_files: = $ (call all-subdir-Java-files)

Local_package_name: = testjniapp

Local_jni_shared_libraries: = libtestjniapp

Include $ (build_package)

#===================================================== ==================================

# Also build all of the sub-targets under this one: the shared library.
Include $ (call all-makefiles-under, $ (local_path ))

It looks very simple. You don't need to change it.

    • Android. mk in the jni directory

Because our testjniapp is completed with JNI and contains the C source code, we also need Android. mk in the jni directory. First, let's take a look at the content of Android. mk in the jni directory of simplejni:

Local_path: = $ (call my-DIR)
Include $ (clear_vars)

Local_module_tags: = Samples

# This is the target being built.
Local_module: = libsimplejni

# All of the source files that we will compile.
Local_src_files: =/
Native. cpp

# All of the shared libraries we link against.
Local_shared_libraries: =/
Libutils

# No static libraries.
Local_static_libraries: =

# Also need the JNI headers.
Local_c_includes + =/
$ (Jni_h_include)

# No special compiler flags.
Local_cflags + =

# Don't prelink this library. For more efficient code, you may want
# To add this library to the prelink map and set this to true. However,
# It's difficult to do this for applications that are not supplied
# Part of a system image.

Local_prelink_module: = false

Include $ (build_shared_library)

The name of the current module of local_module, that is, the name of the so file after compilation

Local_src_files

Local_shared_libraries, local_static_libraries dynamic and static libraries to be linked to this module.

Header file to be included in local_c_includes

Local_cflags C language compilation Option

Local_prelink_module defines whether to use the prelink tool. It uses the prelink instead of the runtime link to accelerate the loading of shared libraries, which not only speeds up startup, but also reduces some memory overhead.

After modification, the android. mk in the jni directory of my testjniapp is as follows:

local_path :=$ (call my-DIR)

include $ (clear_vars)

local_module
:= libtestjniapp

local_src_files: = com_test_app_jni.c

local_c_includes + = $ (jni_h_include)

local_prelink_module: = false

include $ (build_shared_library)

Note that if you want to compile the so file into the image,You must modify local_module_tags to change the original value samples to user, or you can delete it directly.
. If local_module_tags is not specified for the MK file containing local_module, the default value is user. The so file is compiled into the image only when it is defined as user, for specific definitions, see build/CORE/base_rule.mk.

4. Modify/bulid/target/product/generic. mk to compile the project to the system.

So far, there is still the last job. To compile the project into an image, you also need to add the package name in the/bulid/target/product/generic. mk File

Product_packages: =/
Accountandsyncset.pdf/
Carhome/
Deskclock/
......
Syncprovider/
Testjniapp



after completing the above steps, on the
source tree
compile in the root directory
image
.

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.