Wednesday, December 22, 2010

How to compile Launcher / Calendar or any packages/apps from AOSP in eclipse...!!

How to compile the launcher or any app from packages/apps from eclipse

File->New > Android Project-> Create project from existing workspace ->
-> Point to any of the application in AOSP/packages/apps/AlarmClock (or) Calendar any app.

Now you would be facing many compilation errors for most of the apis.
Currently, You would be working with Android SDK.So it would be linking against android.jar provided from SDK version, in which these apis wont be available.


To make it compile in eclipse, you need to do following steps.



1 - when 'make' is made at root of AOSP, certain jar files will be created in /out directory.

/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes-full-debug.jar

2 - In eclipse, right click your project , select properties -> JAVA Build path ->Libraries tab.
You would have option as 'Add Library' in the side.
Click it. Then select 'User Library'-> 'user libraries'.

then click 'New' and give a name to it.
Then select the newly entered name and select 'Add jars' options in the side. Choose the path of the classes-debug.jar.

3 - Back to Java Build path window. Go to 'Order and export' make the newly added library to be at the top.



Done...!! Now you are ready to compile and debug as well...!!



Note :
'classes-full-debug.jar' file is nothing but collection of .classes files required for compilation. But when you want to run the apk build using this method ( eclipse ) on the emulator, we need the corresponding dex files to be present. DEX files are nothing but dalvik compiled files, which android OS requires for running your application. So you need to push the framework.jar created from compiling 'make' @ root of AOSP to the emulator /system/framework.

go to /out/target/product/generic/system/framework/framework.jar

adb -s emulator-5554 remount
adb -s emulator-5554 push framework.jar /system/framework
adb -s emulator-5554 shell reboot.



For reference eclipse screen shots:











11 comments:

  1. Hey buddy, I was trying to modify some app from CM source and found many errors when I tried importing the code in eclipse. I got the info on including classes-debug.jar to from your tutorial. Thx for the writeup buddy.

    ReplyDelete
  2. i've done this but I'm still receiving errors in Eclipse. Can you help me please???

    ReplyDelete
  3. What is the eclipse error you are getting ??

    ReplyDelete
  4. Wow I got it! I was missing the default.properties file so I created it manually. THANKS SO MUCH! I have been trying to figure this out for 2 weeks now! I would totally donate to your blog if you had the option available!

    ReplyDelete
  5. Thanks...!! Happy that this post helped you..!! You can try my apps in market..!!

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. I was looking for such tutorial yesterday evening. Thanks it is helpful. I followed it this morning for the Calendar application, but I still face a lot of errors:
    The import com.google.common cannot be resolved
    VisibleForTesting cannot be resolved to a type
    Note that the errors I have now are different from the ones I had yesterday. So probably your tutorial fixed some of them but not all.
    I copied the "project.properties" in "default.properties", as Jayenoh suggested.

    I also tried the "System library" option:
    In "Project Properties", I select my newly added library, click on "Edit", then "User Libraries", "Edit" again. There is a tick box for "System library (added to the boot class path)". Does it need to be ticked? Do you the purpose of this option?

    No luck so far. Do you have an idea?

    ReplyDelete
  8. Hi,
    I'm using Eclipse Juno, and I'm having trouble adding the classes-full-debug.jar in the user libraries window. When I click on "Add JARs", I don't get an option to select any directory I want. Rather, I can only select directories that are on top of my app, for example Launcher2. Hence, I only get to select bin/ gen/ res/ src/ etc. Do you know how to solve this problem?

    Thanks!

    ReplyDelete
  9. +1 for the motivation man !!!!!

    ReplyDelete