How to import class from other package when building android image

来源:互联网 发布:淘宝申请退款几天到账 编辑:程序博客网 时间:2024/05/22 10:58

Base on Android build system

If a package or library want to use class which is defined inother library (jar file), we need to do:

1. import packageName.className in your java source code

2. Add package file name (defined by LOCAL_MODULE) toLOCAL_JAVA_LIBRARIES variable in your own Android.mk


If a package or library want to user class which is defined inother package (apk file), we need to do:

1. import packageName.className in your java source code

2. add intermediates object to LOCAL_INTERMEDIATE_SOURCES variable in your own Android.mk

For example: LOCAL_INTERMEDIATE_SOURCES += APPS/android.example.perm_intermediates/src/android/example/perm/Manifest.java


LOCAL_INTERMEDIATE_SOURCESvariable mean import special files into your compile. Just like add a source file in your project.

This variable is usually used to add the following intermediates objects.

$(framework-res-source-path)/android/R.java \$(framework-res-source-path)/com/android/internal/R.java


My understanding of why we need LOCAL_INTERMEDIATE_SOURCES variable.

There are 3 cases of import class (or resource) from other library or package.

1. The class is defined in java file in a library, we can import that class directly and add that library into our dependency.

2. The class is defined in java file in a package, we can copy that file into our own project if possible.

3. The class is generated from resource (Android resources and permissions are packed into a java file), and these class are compiled into a dex file in apk file. The generated java file is just a intermediate object.

In this case, we can not get the java file before building. So we use LOCAL_INTERMEDIATE_SOURCES variable to import these intermediate objects into our project.

0 0
原创粉丝点击