-
Notifications
You must be signed in to change notification settings - Fork 372
Request: allow to parse APK file without using File or file-path #92
Comments
Does ByteArrayApkFile meet your need? |
You mean this: This means it has to load the entire APK content in order to parse it. |
Via the SAF API , I could give you the InputStream multiple times if needed. |
Maybe it's possible to have a ZipInputStream that will take only the manifest file and send it as a byte array to ApkFile? Will the library still be able to parse a byte array that only has the manifest file? |
I tried now to get only the manifest into bytes array. Seems to work, but the parser of this library can't handle it alone. It probably has to have it in an APK file, together with some other stuff. Here's the code :
|
Resource table file is a must to get real values of AndroidManifest.xml. Maybe we can provide a minimal api which only read Resource table and AndroidManifest.xml. |
I see. Makes sense. |
OK seems it's almost possible to do it, for manifest and resources files. val manifestBytes: ByteArray? = get bytes array from AndroidConstants.MANIFEST_FILE entry
val resourcesBytes: ByteArray? =get bytes array from AndroidConstants.RESOURCE_FILE entry
val xmlTranslator = XmlTranslator()
val resourceTable: ResourceTable =
if (resourcesBytes == null)
ResourceTable()
else {
val resourceTableParser = ResourceTableParser(ByteBuffer.wrap(resourcesBytes))
resourceTableParser.parse()
resourceTableParser.resourceTable
}
val apkMetaTranslator = ApkMetaTranslator(resourceTable, locale)
val binaryXmlParser = BinaryXmlParser(ByteBuffer.wrap(manifestBytes), resourceTable)
binaryXmlParser.locale = locale
binaryXmlParser.xmlStreamer = CompositeXmlStreamer(xmlTranslator, apkMetaTranslator)
binaryXmlParser.parse() |
Use InputStream , DocumentFile or Uri instead.
The reason:
In the near future, Google will block storage permission, which requires developers to handle files outside of the scope of the current app, to use SAF instead of File and file-path.
More information here:
https://issuetracker.google.com/issues/128591846
And yes, it's very devastating for many apps and libraries that need to access the files in a normal way. Even the Android framework isn't ready for it, as there are functions such as getPackageArchiveInfo (here) that uses a File or file-path, and have no other alternative.
If you want to test your solution without the storage permission and using just the InputStream, here (the app assumes there is a file named "a.apk" on the root path of the normal storage) :
https://issuetracker.google.com/issues/132481545#comment5
The text was updated successfully, but these errors were encountered: