Monday, January 17, 2011

Important framework structures/directories in android

Framework structure

Many would be working on android framework level to achieve something which is common across android system wide ( ex. it will be seen across all android applications like activity switching animations, status bar changes,any UI component changes )

I would like to share what are the important folder structures available and what are the important jar files created , how are they created , compilation sequences.

Below are the three main important jar files created in /out/target/generic/system/framework for make @ root level of AOSP......!!

1 - framework.jar
/framework/base --> Android.mk

Some of the important items which gets build as a part of this jar are

- all widgets, view groups, notification aidl...

2 - services.jar
/framework/base/services/java --> Android.mk

- All system level services are defined here, ex. statusBarService, NotificationManagerService,
- status bar view creation, designining is handled here.

3 - android.phone_policy.jar
/framework/base/policies/impl/phone -->Android.mk

4 - framework-res.apk
/framework/base/core/res/ -->Android.mk + AndroidManifest.xml

This is not a jar. An apk is created, which has a critical importance in framework. The resources present in framework are compiled and an intermediate R.java is created as a part of this apk compilation.

/out/target/common/obj/APPS/framework-res_intermediates/src/android/R.java
/out/target/common/obj/APPS/framework-res_intermediates/src/com/R.java

These R.java s are important while compiling rest of framework code. So if u take a look at Android.mk file present in framework/base, this intermediate R.java file is included while compilation.



fg-res-source-path := APPS/fg-res_intermediates/src
# $(fg-res-source-path)/com/fusiongarage/R.java
LOCAL_INTERMEDIATE_SOURCES := \
$(framework-res-source-path)/android/R.java \
$(framework-res-source-path)/android/Manifest.java \
$(framework-res-source-path)/com/android/internal/R.java \
$(fg-res-source-path)/com/fusiongarage/R.java


Further all services declaration, permission declarations, and some activities declarations are defined as a part of framework-res.apk's AndroidManifest.xml


Compilation process:

- When framework code is getting compiled there are intermediates folder created before creating the final Dex file(framework.jar,services.jar) which only can be run on android system.

For each compilation of Android.mk file there will be a intermediates folder created in 'out/target/common/obj/JAVA_LIBRARIES/'
If the android.mk file is defined to create java library out of it,it should have the below definition in it..
include $(BUILD_JAVA_LIBRARY)

Similarly for if an android.mk has the specification to build an package(apk) out of it, then its intermediates will be located in 'out/target/common/obj/APPS'

Below definition is required to create an apk from an android.mk.
include $(BUILD_PACKAGE)

When the logs are analysed when the compilation is going on, below are the flow i observed. And some hints from that.

- use ' mmm frameworks/base showcommands'
to see the logs what is going on for compilation sequences.

Dex file:

- All .java files will be compiled to .class filed and a jar file will be created first 'classes.jar'. From this classes.jar , classes.dex will be created using 'dx' executable.

out/host/linux-x86/bin/dx -JXms16M -JXmx1536M --dex --output=out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/tmp/classes.dex out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/tmp/classes.jar


javalib.jar
-

touch out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/tmp//dummy
(cd out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/tmp/ && jar cf javalib.jar dummy)
zip -qd out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/tmp/javalib.jar dummy
rm out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/tmp//dummy


aapt:

out/host/linux-x86/bin/aapt add -k
out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/tmp/javalib.jar out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/tmp/classes.dex
'out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.dex' as 'classes.dex'...
jar uf out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/javalib.jar -C frameworks/base preloaded-classes

Install: out/target/product/harmony/system/framework/framework.jar
acp:

out/host/linux-x86/bin/acp -fpt out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/tmp/javalib.jar out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/tmp/framework.jar

8 comments:

  1. Hey I'm trying to add a library of my own in frameworks/base/libs/ in a folder called myServiceManager. I have created its Android.mk in the folder. How do I get this folder to be included in the build process. Will I have to edit the Android.mk in frameworks/base ?

    ReplyDelete
  2. No not needed. When frameworks/libs folder is being taken for compilation, it would go to each and every folder and looks for Android.mk and build the library accordingly.You just need to properly write Android.mk file to create a library for you.

    ReplyDelete
  3. hello, nice article. How do i go about including android-support-v4 in frameworks/base/android.mk ?
    thanks.

    ReplyDelete
  4. I want to build only frameworks. i'm using mmm Command to build. But it is returning 'No rule to make target' error and compilation is being stop. Can u please suggest something on this.
    Command used 'mmm frameworks/base'
    Thanks.

    ReplyDelete
  5. As I want to add precompile .jar file in aosp and the classes of the compiled used by the framework classes like LocationManager. Can you please suggest on this.

    ReplyDelete
  6. Nice blog,keep sharing more posts with us.
    thank you....

    android developer training

    ReplyDelete