What is the proper method to manually odex an apk?


Question

I am looking for a proper and simple method to odex an apk file. I have an upgraded apk file from a ROM with which I want to replace the older one and it is located in the /system-priv directory. The older apk has the .odex file, but I figured out I can't directly overwrite the it, since I can't use the old .odex (hence I need to odex first), lest I'ill be stuck with app crashes or bootloops.


I have tried searching for methods online but are not satisfactory in one of the ways:



  1. This one which involves the use of a dexopt-wrapper.bin seems to be way outdated as binary is not supported, I have this error poping up:


     error: dexopt-wrapper error: only position independent executables (PIE) are supported.


  2. The second one which is lengthy and links to other required resources are no longer there, and is somewhat not compatible with my system.



  3. The only promising one which uses Auto Odexer Script, but currently I'm running issues adb and also seems it uses the same dexopt-wrapper binary which was giving me errors in terminal.




There are tools/methods for doing the entire system at once, but I do not need the entire system re-odexed. I want to personally create an odexed "upgraded" .apk from the extracted ROM.


Update


I upgraded the wrapper binary (now PIE) and should be compatible however still encountering this error:


--- BEGIN '/sdcard/app/A.apk' (bootstrap=0) ---
--- waiting for verify+opt, pid=17200
--- would reduce privs here
execl(/bin/dexopt) failed: No such file or directory
--- END '/sdcard/app/A.apk' --- status=0x4300, process failed
1|mido:/ #

and the result is an empty .odex file in the dir. Someone to point out where I am going wrong here?


Answer

credits to com.modaco.odexme
xda link



Theoretically you should only need your Android device to manually odex, I ended up using both smartphone (running KitKat 4.4) and PC as explained later.



I successfully odexed apks using the following steps:



1.Create a /dir/odex on your Android device



2.Save next script as odex.sh in /dir/odex, give it execute permission 777



#!/system/bin/sh

cd /dir/odex

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

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

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

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

done;


3.Obtain following binaries from com.modaco.odexme.apk\assets



dexopt-wrapper zip zipalign



put those in /dir/odex and give execute permission 777



4.Copy .apk(s) you want to odex from /system/app or /system/priv-app to /dir/odex



5.Open Terminal, cd to /dir/odex and execute ./odex.sh



At this point I had a problem with zipalign which could not LINK EXECUTABLE - cannot locate symbol... but nonetheless script partially executed and obtained odex(es) sitting next to apk(s) in our dir.



6.So I had to resort to the PC, copy original apk to PC, open it with WinRar or 7zip, manually remove classes.dex and zipalign, than put "deodexed" apk back to Android device.



7.Now with a file explorer put newly created .odex and .apk in /system/app or /system/priv-app (have a backup of original apk first). If it fails to write mount system as rw. Give both permission 644 as all the other apks and odex in dir.



8.You can now delete corresponding dex in /data/dalvik-cache



9.Reboot (or soft-reboot)



10.Enjoy your newly odexed app



I successfully odexed LGEIME.apk, a modified keyboard for my G2, and GoogleDrive.apk, I moved it to /system/app to save space on /data partition because newer version are 5.0+ only. I was skeptical about GoogleDrive because it was multi-dex, infact apk contained classes.dex and classes2.dex: turned out I had to strip only classes.dex from the apk and leave classes2.dex inside the apk.



credits to com.modaco.odexme
xda link


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes