How to import class from other package when building android image

Base on Android build system

If a package or library want to use class which is defined in other 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) to LOCAL_JAVA_LIBRARIES variable in your own Android.mk


If a package or library want to user class which is defined in other 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_SOURCES variable 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值