[Android Software Development] CosmicDan:
Fair enough, same story as MIUIv5 then.

Well obvious suggestion is to try removing the APK entirely, unless it's a framework APK? Decompiling it might shine some light on its function too. But this is all obvious and you've likely tried already.

Patchrom can be buggy at times and insert files designed for different hardware/xiaomi products too.

One last thing, since its a dependency issue - are all framework jar's in the RAMDisk boot classpath? And does your base ROM have ODM specific framework extensions (I.e. additional framework-res in the *base*, not MIUI)? There may be a conflict which is preventing the framework injection that MIUI requires. In earlier Android I think this was done in PackageManagerService but Its been a while.

In every case that I ported MIUI, I had to make my own additions and changes to smali due to PatchROM bugs or inconsistencies with bases that aren't 100% AOSP (e.g. CyanogenMod has a habit of leaving dead methods behind in order to preserve compatibility; this leads to PatchROM inserting code in places that are never reached).

Sent via Tapatalk on my Xperia Z

EDIT: Some more points:

- Quick research on this miui.apk file tells me that it's the "MIUI SDK" which seems to be a shared function library of sorts. Usually code like this goes in framework jars/apk's but Xiaomi are clearly being tricky here to remove the need to inject changes in the boot class path. This however is not how Android is designed, or is an undocumented feature AFAIK - so MIUI seems to be even *more* hacky than it used to be lol. Anyway, I also discovered this, maybe you can diff it with the one you have and find some clues? Although it's fairly old and a port so likely has a lot of irrelevant differences.

- Have you considered / tried re-signing the whole firmware with new keys (namely platform key) and is your apkcerts.txt in PatchROM accurate? I *always* had to modify this text file manually, bad/inconsistent signatures on core packages can sometimes lead to that dexopt "bad magic" error (which, BTW, just means that dexopt/dalvikvm crashed unexpectedly while trying to optimize). Replacing the keys are probably a good idea anyway if you don't already do it, since the ones already there are the Google public/test keys and that's a huge security risk for malware.

- The fact that it's complaining about a missing dep on userdata partition also suggests that this MIUI SDK APK needs to be installed as a user app (i.e. put into preinstall rather than app), but that doesn't make sense to me. However that *might* be how it needs to be done, recalling my earlier comment of it possibly being an undocumented thing in Android or a hack (i.e. to treat an app APK as a shared framework library + resources without needing boot class path changes). I believe this kind of special behavior would also be injected into PackageManagerService.

In the end, all things point to an incomplete PatchROM process - either due to a bug in current PatchROM, or an inconsistency in your base ROM (if not 100% AOSP, which technically no ROM is unless you're on a Nexus device really!). In my experience, both are just as likely.

Oh, one more thing. There is always the sledgehammer approach. Find a device that already has MIUI6 working with as similar hardware as yours *or* one that has as few ODM overlays as possible, and diff the entire decompiled framework with yours :p

EDIT2: Are you using MIUI's binaries for dexopt, dalvikvm, app_process and zygote? Or your device originals? Try both, even try diff. combinations of these. Forget about Xposed compatibility for now, that's another complexity you can figure out later if you wish (and can handle the overall system lag it brings ;))

EDIT3: Oh, I completely forgot! Jump into an adb shell and just try to run the binaries I mentioned above too, especially dexopt and dalvikvm. No parameters, just check the output to ensure there's no linking errors (they should either give the usual usage or a polite message such as "You should not run this binary manually, it's used internally"). If you get a linking error or something else unexpected, you might have bad/missing libraries. If you're not sure how to resolve these or aren't sure if it's OK, just share the output with us.