ODEX files thru Build system

3,408 views
Skip to first unread message

Ravindranath Dammalapati

unread,
Oct 20, 2010, 8:30:17 AM10/20/10
to Android Building
From Source: http://android.git.kernel.org/?p=platform/dalvik.git;a=blob_plain;f=docs/dexopt.html;hb=HEAD

"""
here are at least three different ways to create a "prepared" DEX
file, sometimes known as "ODEX" (for Optimized DEX):

1. The VM does it "just in time". The output goes into a special
dalvik-cache directory. This works on the desktop and engineering-only
device builds where the permissions on the dalvik-cache directory are
not restricted. On production devices, this is not allowed.
2. The system installer does it when an application is first added.
It has the privileges required to write to dalvik-cache.
3. The build system does it ahead of time. The relevant jar / apk
files are present, but the classes.dex is stripped out. The optimized
DEX is stored next to the original zip archive, not in dalvik-cache,
and is part of the system image.

"""

Can some one help with the procedure to create ODEX files using third
procedure i.e Build system?

Ying Wang

unread,
Oct 20, 2010, 8:20:31 PM10/20/10
to android-...@googlegroups.com
You can build the dex-preopted files by:
$make WITH_DEXPREOPT=true
Dexpreopt can only be done in Linux dev environment.
Note that it may fail to build, because currently dexpreopt has to been run in the emulator, which has some bug.
We will soon switch to a host-dex based dexopt tool, which does not rely on the emulator.


--
You received this message because you are subscribed to the "Android Building" mailing list.
To post to this group, send email to android-...@googlegroups.com
To unsubscribe from this group, send email to
android-buildi...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

Ernst Sjöstrand

unread,
Oct 22, 2010, 3:53:22 PM10/22/10
to android-...@googlegroups.com
"We will soon switch to a host-dex based dexopt tool, which does not rely on the emulator."

This sounds wonderful, the current system has given me some headaches at $DAYJOB!
Can you give any more info on how that system will work?

Best Regards
//Ernst Sjöstrand

Ying Wang

unread,
Oct 23, 2010, 4:10:40 PM10/23/10
to android-...@googlegroups.com
For each apk (or jar for java library) there will be a Dalvik VM running on the build host to do the pre-optimization and generate the .odex file.
The .odex file will get installed next to the .apk (or .jar) file on the device.
The build command will keep the same:
$make WITH_DEXPREOPT=true

2010/10/22 Ernst Sjöstrand <ern...@gmail.com>

johnny

unread,
Nov 24, 2010, 10:06:37 AM11/24/10
to Android Building
I'm working on the Froyo codebase and trying to enable the dexpreopt
in build system. However, I am curious what the benefits of enabling
dexpreopt. It seems to me that that will definitely improve the first
time boot up speed. Will it improve the speed of second boot? Will it
improve the performance of the apk?

Regards,
Johnny

On 10月24日, 上午4时10分, Ying Wang <wangy...@android.com> wrote:
> For each apk (or jar for java library) there will be a Dalvik VM running on
> the build host to do the pre-optimization and generate the .odex file.
> The .odex file will get installed next to the .apk (or .jar) file on the
> device.
> The build command will keep the same:
> $make WITH_DEXPREOPT=true
>
> 2010/10/22 Ernst Sjöstrand <ern...@gmail.com>
>
> > "We will soon switch to a host-dex based dexopt tool, which does not rely
> > on the emulator."
>
> > This sounds wonderful, the current system has given me some headaches at
> > $DAYJOB!
> > Can you give any more info on how that system will work?
>
> > Best Regards
> > //Ernst Sjöstrand
>
> > On Thu, Oct 21, 2010 at 02:20, Ying Wang <wangy...@android.com> wrote:
>
> >> You can build the dex-preopted files by:
> >> $make WITH_DEXPREOPT=true
> >> Dexpreopt can only be done in Linux dev environment.
> >> Note that it may fail to build, because currently dexpreopt has to been
> >> run in the emulator, which has some bug.
> >> We will soon switch to a host-dex based dexopt tool, which does not rely
> >> on the emulator.
>
> >> On Wed, Oct 20, 2010 at 5:30 AM, Ravindranath Dammalapati <
> >> ravindranath.dammalap...@gmail.com> wrote:
>
> >>> From Source:
> >>>http://android.git.kernel.org/?p=platform/dalvik.git;a=blob_plain;f=d...
>
> >>> """
> >>> here are at least three different ways to create a "prepared" DEX
> >>> file, sometimes known as "ODEX" (for Optimized DEX):
>
> >>>   1. The VM does it "just in time". The output goes into a special
> >>> dalvik-cache directory. This works on the desktop and engineering-only
> >>> device builds where the permissions on the dalvik-cache directory are
> >>> not restricted. On production devices, this is not allowed.
> >>>   2. The system installer does it when an application is first added.
> >>> It has the privileges required to write to dalvik-cache.
> >>>   3. The build system does it ahead of time. The relevant jar / apk
> >>> files are present, but the classes.dex is stripped out. The optimized
> >>> DEX is stored next to the original zip archive, not in dalvik-cache,
> >>> and is part of the system image.
>
> >>> """
>
> >>> Can some one help with the procedure to create ODEX files using third
> >>> procedure i.e Build system?
>
> >>> --
> >>> You received this message because you are subscribed to the "Android
> >>> Building" mailing list.
> >>> To post to this group, send email to android-...@googlegroups.com
> >>> To unsubscribe from this group, send email to
> >>> android-buildi...@googlegroups.com<android-building%2Bunsu...@googlegroups.com>
> >>> For more options, visit this group at
> >>>http://groups.google.com/group/android-building?hl=en
>
> >>  --
> >> You received this message because you are subscribed to the "Android
> >> Building" mailing list.
> >> To post to this group, send email to android-...@googlegroups.com
> >> To unsubscribe from this group, send email to
> >> android-buildi...@googlegroups.com<android-building%2Bunsu...@googlegroups.com>
> >> For more options, visit this group at
> >>http://groups.google.com/group/android-building?hl=en
>
> >  --
> > You received this message because you are subscribed to the "Android
> > Building" mailing list.
> > To post to this group, send email to android-...@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-buildi...@googlegroups.com<android-building%2Bunsu...@googlegroups.com>

Jean-Baptiste Queru

unread,
Nov 24, 2010, 10:25:50 AM11/24/10
to android-...@googlegroups.com
-it reduces the overall flash usage by stripping the original dex data
from the apks.

-most importantly, it guarantees that system upgrades will install
regardless of how full the data partition is (without that, it's
possible for a system upgrade to make a device unbootable unless doing
a factory reset).

JBQ

--
Jean-Baptiste M. "JBQ" Queru
Software Engineer, Android Open-Source Project, Google.

Questions sent directly to me that have no reason for being private
will likely get ignored or forwarded to a public forum with no further
warning.

A.C.

unread,
Nov 24, 2010, 11:16:42 AM11/24/10
to Android Building
I've tried this, but it doesn't seem to work.
As far as I'm missing something, after downloading the source (master)
and preparing the vendor files, I run $make -j4 otapackage
WITH_DEXPREOPT=true, but I don't see it having any effect.
I'm building on Ubuntu 10.04 x64. I noticed on core.mk that
WITH_DEXPREOPT is forcibly disabled, and even after correcting that, I
get no odex on my build.
Any ideas?

On Oct 23, 1:10 pm, Ying Wang <wangy...@android.com> wrote:
> For each apk (or jar for java library) there will be a Dalvik VM running on
> the build host to do the pre-optimization and generate the .odex file.
> The .odex file will get installed next to the .apk (or .jar) file on the
> device.
> The build command will keep the same:
> $make WITH_DEXPREOPT=true
>
> 2010/10/22 Ernst Sjöstrand <ern...@gmail.com>
>
> > "We will soon switch to a host-dex based dexopt tool, which does not rely
> > on the emulator."
>
> > This sounds wonderful, the current system has given me some headaches at
> > $DAYJOB!
> > Can you give any more info on how that system will work?
>
> > Best Regards
> > //Ernst Sjöstrand
>
> > On Thu, Oct 21, 2010 at 02:20, Ying Wang <wangy...@android.com> wrote:
>
> >> You can build the dex-preopted files by:
> >> $make WITH_DEXPREOPT=true
> >> Dexpreopt can only be done in Linux dev environment.
> >> Note that it may fail to build, because currently dexpreopt has to been
> >> run in the emulator, which has some bug.
> >> We will soon switch to a host-dex based dexopt tool, which does not rely
> >> on the emulator.
>
> >> On Wed, Oct 20, 2010 at 5:30 AM, Ravindranath Dammalapati <
> >> ravindranath.dammalap...@gmail.com> wrote:
>
> >>> From Source:
> >>>http://android.git.kernel.org/?p=platform/dalvik.git;a=blob_plain;f=d...
>
> >>> """
> >>> here are at least three different ways to create a "prepared" DEX
> >>> file, sometimes known as "ODEX" (for Optimized DEX):
>
> >>>   1. The VM does it "just in time". The output goes into a special
> >>> dalvik-cache directory. This works on the desktop and engineering-only
> >>> device builds where the permissions on the dalvik-cache directory are
> >>> not restricted. On production devices, this is not allowed.
> >>>   2. The system installer does it when an application is first added.
> >>> It has the privileges required to write to dalvik-cache.
> >>>   3. The build system does it ahead of time. The relevant jar / apk
> >>> files are present, but the classes.dex is stripped out. The optimized
> >>> DEX is stored next to the original zip archive, not in dalvik-cache,
> >>> and is part of the system image.
>
> >>> """
>
> >>> Can some one help with the procedure to create ODEX files using third
> >>> procedure i.e Build system?
>
> >>> --
> >>> You received this message because you are subscribed to the "Android
> >>> Building" mailing list.
> >>> To post to this group, send email to android-...@googlegroups.com
> >>> To unsubscribe from this group, send email to
> >>> android-buildi...@googlegroups.com<android-building%2Bunsu...@googlegroups.com>
> >>> For more options, visit this group at
> >>>http://groups.google.com/group/android-building?hl=en
>
> >>  --
> >> You received this message because you are subscribed to the "Android
> >> Building" mailing list.
> >> To post to this group, send email to android-...@googlegroups.com
> >> To unsubscribe from this group, send email to
> >> android-buildi...@googlegroups.com<android-building%2Bunsu...@googlegroups.com>
> >> For more options, visit this group at
> >>http://groups.google.com/group/android-building?hl=en
>
> >  --
> > You received this message because you are subscribed to the "Android
> > Building" mailing list.
> > To post to this group, send email to android-...@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-buildi...@googlegroups.com<android-building%2Bunsu...@googlegroups.com>

Mali Laurent

unread,
Nov 24, 2010, 12:26:27 PM11/24/10
to android-...@googlegroups.com
make WITH_DEXPREOPT=true is not working for me though. Any thoughts about that?

Ying Wang

unread,
Nov 24, 2010, 2:10:06 PM11/24/10
to android-...@googlegroups.com
Make sure DISABLE_DEXPREOPT is not defined in your environment.
(Note that DISABLE_DEXPREOPT is defined in build/envsetup.sh).

Ravindranath Dammalapati

unread,
Nov 25, 2010, 11:35:48 AM11/25/10
to Android Building
Thanks Ying, for your comments.

I had mixed results.
1. On my old work PC It compiled like a charm and created apk and odex
files
But the image when I flashed on the device it did not work, it kept on
rebooting. (works fine for emulator).

2. When compiling Target device = generic, its able to open the
emulator and proceed further.
But fails to create folders under /data (says read only file system)

3. When Compiled Target device = <our product>, the emulator is
opening but not booting up
it stays in "android" screen and times out after 20 sec

4). Manual Procedure:

1. First compile and get copy of dexopt-wrapper
2. Connect the device in debug mode.
3. ./adb remount
4. ./adb push <local path>/dexopt-wrapper /system/bin
5. ./adb shell
6. # cd /system/bin
7. #export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
8. #export PATH=.:$PATH
9. dexopt-wrapper /system/app/test.apk /system/app/test.odex

This creats the odex file in the device, but the test.apk is not
stripped of classes.dex file.
so follow this procedure to strip the classses.dex file inside the apk
file.

1. ./adb pull /system/app/test.apk /pclocalpath/test.apk
2. ./adb pull /system/app/test.odex /pclocalpath/test.odex
3. zip -d /pclocalpath/test.apk classes.dex
You get the classes.dex stripped .apk



To get the odex and apk file come in the system image.
Now copy the .odex and .apk obtained to out\target\product
\<yourproduct>\system\app\
make to get the binaries.


If only emulator was working properly it would save lots of time.
Please suggest to make the emulator work.

I am not an expert please correct me if the procedure is wrong.

Regards,
Ravi D
Test Engineer









On Nov 25, 12:10 am, Ying Wang <wangy...@android.com> wrote:
> Make sure DISABLE_DEXPREOPT is not defined in your environment.
> (Note that DISABLE_DEXPREOPT is defined in build/envsetup.sh).
>
> > <android-building%2Bunsu...@googlegroups.com<android-building%252Buns...@googlegroups.com>
>
> > > >>> For more options, visit this group at
> > > >>>http://groups.google.com/group/android-building?hl=en
>
> > > >>  --
> > > >> You received this message because you are subscribed to the "Android
> > > >> Building" mailing list.
> > > >> To post to this group, send email to
> > android-...@googlegroups.com
> > > >> To unsubscribe from this group, send email to
> > > >> android-buildi...@googlegroups.com<android-building%2Bunsu...@googlegroups.com>
> > <android-building%2Bunsu...@googlegroups.com<android-building%252Buns...@googlegroups.com>
>
> > > >> For more options, visit this group at
> > > >>http://groups.google.com/group/android-building?hl=en
>
> > > >  --
> > > > You received this message because you are subscribed to the "Android
> > > > Building" mailing list.
> > > > To post to this group, send email to android-...@googlegroups.com
> > > > To unsubscribe from this group, send email to
> > > > android-buildi...@googlegroups.com<android-building%2Bunsu...@googlegroups.com>
> > <android-building%2Bunsu...@googlegroups.com<android-building%252Buns...@googlegroups.com>

Mali Laurent

unread,
Nov 26, 2010, 9:37:52 AM11/26/10
to android-...@googlegroups.com
Thanks. I was also having a little fight with this.

Armando Ceniceros

unread,
Nov 26, 2010, 10:36:46 AM11/26/10
to android-...@googlegroups.com
I myself made a script that i run to do just this recursively for every framework jar (need to do the boot classpath jars first) and app apk, but, like you say, it'd be nice if the build system could do this automaticaly.
Is this doable for a real device rather than just the emulator or is the generation of he odexes architecture dependent? What i mean is, if i want my build to generate odexes for an x86 target, and goldfish is ARM-based, the dexpreopt would have to be done in the actual device rather than launching an emulator, right?

Mali Laurent

unread,
Nov 29, 2010, 9:47:38 AM11/29/10
to android-...@googlegroups.com
If anyone could share how to do this exactly for the framework files please do so as I can not seem to get it right for those. I tried with the bootclasspath:
dexopt-wrapper core.jar core.odex [bootclasspath]

But it fails.

On Mon, Nov 29, 2010 at 3:46 PM, Mali Laurent <i.m.l...@gmail.com> wrote:
Yeah you should do it from within the device itself:

cd /system/app

for apps in `find . -name '*.apk'`
do

    # step 1 - odex the apk
    dexopt-wrapper $apps `echo $apps | sed 's/\(.*\.\)apk/\1odex/'`

    # step 2 - did we succesfully odex?
    if [ -f `echo $apps | sed 's/\(.*\.\)apk/\1odex/'` ]
    then
        # step 3 - remove the classes.dex from the apk
        zip -d $apps classes.dex

        # step 4 - zipalign, just in case
        zipalign -f -v 4 $apps $apps.new
        mv $apps.new $apps
    fi

done;

# clear dalvik cache
rm -r /data/dalvik-cache/*

# reboot
reboot
Reply all
Reply to author
Forward
0 new messages