Parse error after editing apk's on samsung marshmallow devices - Android Q&A, Help & Troubleshooting

Heya,
A while ago, my phone, which is a samsung A3 from 2015, got an update to marshmallow.
That's cool ofcourse and it runs awesome! but I like when my phone has a nice, clean and organized system and Samsung does not do that for all apps.
What I mean is that
- Some apps are odexed, and some apps are not AND some apps are odexed, but the apk file still contains a classes.dex file.
- Some apps have a folder with libs inside the app directory, and some have this folder inside the apk file AND some have this folder inside both
So ideally, i would like all apps to follow the same structure ofcourse, which would be no classes and lib files inside the apk, and then separate oat and lib folders containing the odexes and libs.
In lollipop this was easily done by copying these files out of the apk and putting them in separate folders, then removing them from the apk itself. My phone accepted this, the apps would run as though nothing had happened and it made me feel happy
However now that i'm on marshmallow, everything i do to an apk to change it results in getting a parsing error with that apk, after which it either becomes very fragile or completely broken.
One way I have found to get around this so far is to resign the apk, but for a lot of apps resigning it makes android ignore the app completely.
So the question is...
Is there something I can change somewhere to make marshmallow act like lollipop in these cases and not care that i removed files from apk's in an attempt to odex or delib them?
Any help would be much appreciated
Further info
- I have also noticed this on an S5 / SM-G900F running marshmallow
- I have not tested this on aosp or lineage because there are no suitable roms for my phone to test this with, and I would not want to use them over stock anyway.
- I have not run into this before marshmallow, it was always fine with me editing apk's like this in older versions of android.
- I am not ready to get over my ocd and accept this :crying:

No one? I suppose it is a really tough question.
So I got around the duplication of lib files by putting the actual libs in the appname\lib\arm folder and then placing zero length lib***.so placeholder files inside the apk.
this somehow keeps the apk intact and does not cause a parse error and makes the app work as it should, even across data wipes, reboots, backups and restores.
putting zero length classes.dex files inside the apk however doesn't work. Although this also doesn't cause a parsing error, the app actually tries to transform the empty classes into dalvik cache and then it breaks.
I'm still open to better suggestions

Related

[Q] How should I de/recompile a system app? What did I do wrong?

Hi,
So the situations is like this:
Just got a new LG Nexus 4, NFC enabled, GREAT!!!!
But then I start using it, and the NFC sound (everytime the phone reads a nfc-tag it makes an sound) annoys me beyond belief.
So I start looking around, it seems there's no solution, except recompiling the app.
So I learn how to compile an app (noob here), using this guide: http://forum.xda-developers.com/showthread.php?t=1860115
I'm up to the point where my apk is decompiled, and I have modified the sound files, located in my decompiled files folder respectively at res/raw/start.ogg & res/raw/end.ogg.
I modded the files using audacity, lowering the volume to zero, used them to replace the original .ogg files. The file size is a bit smaller as the original ones (1Kb difference).
Next I use the recompile command: apktool b decompiled_apk_folder_with_modified_files modded_apk_file.apk
So now I have the new nfc apk file, called NfcNci.apk, with which I replace the original file in /system/app.
Next up I reboot my phone into recovery, wipe all cache and dalvik cache, and reboot again.
First thing that pops up on my screen is a force-close message, saying that the nfc-service force closed.
Anyone who can tell me what I did wrong? Or how I can fix this?
Attached are: my decompiled-files-folder (compressed to zip)
the original NfcNci.apk file
my modded NfcNci.apk file which causes the FC's.
Any help will be greatly appreciated!!!!
S.
Looks like you're still on 4.2
The latest NfcNci.apk has some more files.
And your apk is missing the META-INF folder.
I guess that this is the problem.
But you should use "adb logcat" to ensure we're on the right track.
Micky
1 thing i would recomend is not using the actual apk you just built. instead, open your new apk with a file manager such as 7zip and remove your newly compiled files out of it, then put them into the original apk from your rom using 7zip as well! thus keeping the apk's original signature
try to copy the least amount of files from one to another, so to be safe only pull out your new .ogg files, then put them into your original apk! hope this helps
ldrifta said:
1 thing i would recomend is not using the actual apk you just built. instead, open your new apk with a file manager such as 7zip and remove your newly compiled files out of it, then put them into the original apk from your rom using 7zip as well! thus keeping the apk's original signature
try to copy the least amount of files from one to another, so to be safe only pull out your new .ogg files, then put them into your original apk! hope this helps
Click to expand...
Click to collapse
Hi, I tried this, installed 7zip, and double clicked the original apk, I opende the res/raw/ directory, and only copied the files I was using: start.ogg & end.ogg. Then I close 7zip, and send the file to my phone. But as soon as I it them to /system/apps on my phone, and reboot to recovery, wiping the dalvik cache. I get FC's on reboot (NFC-service has FC'd).
Any reasons for this?
Thanks for the help, both of you!
BTW: I'm on Android 4.3 JB

[Q] Deleting Folders from Recovery

Hello all.
All of my mobile devices are Samsung devices (2 Phones and 2 Tablets) all but one device is rooted, and all are on stock Lollipop ROM. I have went through my phone (Note 3) and removed all the bloatware and have it pretty trim and fit. I want to do the same also for my tablet (Galaxy Tab S). I poured over a bunch of safe to remove type lists and compiled a list of what I could remove and tested things out on my phone. All went well until I got to KNOX and I guess I got a little aggressive (searched for everything with 'knox' in it and deleted what I could), and when I rebooted it got stuck on the boot sequence. No idea why. So I wiped and started over and then used Uninstall ROOT from the Playstore and just deleted the Knox entries that showed up there and that worked better.
Once I was happy that all was working as it should I installed all the normal apps that I use and things have been working perfectly. So I turned my attention to the tablet. I used the list of bloatware from my phone and found, as would be expected, there was much the same with respect to the bloatware just different names.
On my phone, in order to remove the .apk file and the odex files I just deleted the folder since they were in the same place. The odex files were in a sub-folder named 'arm'. I thought with the tablet it would just be easier to use some kind of script run from recovery to delete all the folders and be done with it in a matter of a minute or two if that long instead of doing it manually. To my surprise I found one already made that even used the Aroma installer so you could just select what you wanted to remove, which seemed perfect, except it didn't work. It was removing nothing despite the fact when the script ran it looked like it was doing all it should. Looking at the script that ran, some of the file names were wrong and it wasn't pointing to the 'arm' folder to remove the odex files. So I modified the script to test and set it to remove just one folder as a trial run. The script ran, but did nothing. It seems redundant to me to remove the .apk file and the odex file separately when you can just delete the folder and do in one action. However, I am at a loss as to how to accomplish that from the script.
One of the scripts is Bloatware Removal Script 1.
I can't seem to find the location that I got the one with the Aroma installer, but I have the file on my computer.
So, all this said (I wanted you all to know the process I went through in hopes it would help) to ask, how would one delete a folder from recovery using a script. The CoolBoy script uses:
Code:
delete("/system/app/Chrome.apk");
But not only does it not delete the apk, if I drop the file extension to delete the folder, it does not do that either. The Aroma installer option seems perfect, I just am not familiar with the command that would needed to be used in order to delete the folder. Thanks for reading my long winded post and for any help.

Odex file compilation - Android N/7

I'm playing around with installing apps to the system partition before first boot, using a generic installer zip(by Andybones). All I'm doing is taking the apps from /data/app and renaming their directories to something more readable, then installing them to /system/app using the installer zip and setting permissions. I've noticed that some ROMs include odex files in their system partitions, to save time on first boot.
I assume I can just transfer the odex files over with the apk's, but I remember reading that the reason apps install so much faster in Android N is that the apps are no longer fully compiled during the install, but instead do that in the background over time.
Does anyone know if this refers to the odex files? I just don't want to copy over a bunch of odex files if they're incomplete. Any help or advice would be greatly appreciated! =D

Help modifying APK files on recovery image

Hello,
I bought a Umi Diamond X and i just found out that it came with adware.
Since i could not find any custom roms for it, i tried editing the recovery image. Manged to remove some APK files, but SystemUI is giving me some problems.
What I did until now:
1) Used simg2img to convert system.img to a mountable image
2) mounted the previously generated image and deleted suspicious folders from system/app and system/priv-app.
3) Use SPFT to flash the edited image to the device.
However, I found that SystemUI.apk is also making dubious requests in the background, so I need to replace it with a stock version. I tried taking SystemUI.apk from different roms of similar phones, with a similar SoC, and copy-paste it into my edited system.img. However, everytime i do this, SystemUI crashes when the phone starts up.
Going into the stock recovery, i have the option to "check root integraty". This appears to scan (among others) all APK files in system/app and system/priv-app. I see it detects the deleted APKs and the 1 modified APK. Could the installer have a signature of the expected APKs and not install if the file doesn't match that signature?
Is there any way I can replace SystemUI.apk with a known good version?
Bump..
Bump again..

Help odexing a framework file on Android 7.0 (convert jar file back to odex)

Hello,
I deodexed a framework file (services.odex) to jar, modified it and now I am trying to create an odex file out of it.
I was using this guide: https://forum.xda-developers.com/galaxy-s2/themes-apps/how-to-manually-deodex-odex-t1208320
Everything works until the "dexopt-wrapper" part:
Code:
dexopt-wrapper /system/framework/XXX.jar /system/framework/patched_XXX.odex /system/framework/core.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/core-junit.jar
Executing dexopt-wrapper will return: "error: Android 5.0 and later only support position-independent executables (-fPIE)."
So this wrapper is only usable up to android version 4.4.
Is there any other method to do this for android 7.0 ?
I was thinking about recompiling the wrapper with the needed flags but I don't know how and the source seems to be really old.
https://android.googlesource.com/platform/build/+/donut-release/tools/dexpreopt/dexopt-wrapper/
I did some more research and came to the cunclusion that my phone calls .oat files .odex files.
So the my phone manufacturer Xiaomi renames .oat files to .odex, for whatever reason.
The folder structure is as follows: "framework/oat/arm" and "framework/oat/arm64"
Everything in there has the .odex extension
So it looks like you just have to use dex2oat and rename the file extension from .oat to .odex.
rawika said:
I did some more research and came to the cunclusion that my phone calls .oat files .odex files.
So the my phone manufacturer Xiaomi renames .oat files to .odex, for whatever reason.
The folder structure is as follows: "framework/oat/arm" and "framework/oat/arm64"
Everything in there has the .odex extension
So it looks like you just have to use dex2oat and rename the file extension from .oat to .odex.
Click to expand...
Click to collapse
Curious, why do you want to odex it?
On my side there is no real reason. I just don't want to deal with potential problems that might happen when mixing framework files with a .jar version while the rest is still .odex/.oat. (I guess there aren't any but I don't want to find that out in practice)
I have read that there are performance problems with android pie when you convert framework .vdex files to .jar.
Also I wonder: Why did my phone manufacturer switch to oat / odex framework files? It was deodexed a week ago.
rawika said:
On my side there is no real reason. I just don't want to deal with potential problems that might happen when mixing framework files with a .jar version while the rest is still .odex/.oat. (I guess there aren't any but I don't want to find that out in practice)
I have read that there are performance problems with android pie when you convert framework .vdex files to .jar.
Also I wonder: Why did my phone manufacturer switch to oat / odex framework files? It was deodexed a week ago.
Click to expand...
Click to collapse
On my phone framework jars have always been deodexed but most apps and priv-app are deodexed since Pie. I haven't messed with jar files enough to know if there are performance issues with deodexed jar files with Pie but as long as they are done correctly I don't know why there would be.

Categories

Resources