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.