Correctly copy APK fast

by Ricardo Fernández Serrata

Version 1 (April 21, 2022)

Download (51 downloads)

I've seen a lot of "APK extractors" that do this wrong, causing some APKs to fail to be extracted, and even poor execution performance. This flow will show you how to do it properly and efficiently.

"pm path" is a command that returns A LIST of APK paths delimited by \n. Most apps only have 1 file, so the cmd returns 1 line that ends in \n. Some APKs like Chrome have multiple APKs in their installation directory. This cmd is equivalent to searching the install-dir and then listing all files contained in it that use the apk extension.

The minimum index of the 1st \n is 14, because each line starts with "package:/" URI scheme, ends in ".apk" and has (theoretically) at least 1 char in-between. I said "theoretically", because they have more than 1 char in general. The probability of a path having the same length as "package:/a.apk" is ridiculously low.

To avoid assumptions that could cause bugs on exceptional cases, an index of 14 is used, because it's the fastest & safest bare minimum (an index of 17 or 24 can be used for faster speed, but it's risky)

`APK_list_CSV` has "CSV" in its name because it's a "Character Separated Value" string (the separator is \n in this case, not comma ",")

What if you want to allow the user to input any pack name? Then you should validate it using this regex: "(?:[A-Za-z]\\w*\\.)+[A-Za-z]\\w*". What if the pack isn't found by "pm path"? Then `APK_list_CSV` var will be "", so your code should check the shell stdout to detect that it's empty.

LICENSE: https://unlicense.org/

4.5 average rating from 2 reviews

5 stars
1
4 stars
1
3 stars
0
2 stars
0
1 star
0
Reports
0

Rate and review within the app in the Community section.