Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write an APK parser that extracts the APK's bundleId and supported architectures #589

Closed
hackergrrl opened this issue May 10, 2021 · 0 comments
Assignees

Comments

@hackergrrl
Copy link
Contributor

hackergrrl commented May 10, 2021

Split off from #585, which depends on this.

There is an Android Java API to read this data, and that API can be called from React Native e.g. see https://github.com/staltz/dat-installer/blob/master/android/app/src/main/java/com/staltz/datinstaller/PackageInfoModule.java

However, this information is needed by the backend nodejs process, so accessing it via the Android Java API would require a complex back-and-forth via the React Native process.

It would be better to read this information directly from the APK in the nodejs-mobile process. An APK is a Zip archive, and the version and bundleId are stored in the file AndroidManifest.xml that is always present in the root of the Zip archive (see https://developer.android.com/guide/topics/manifest/manifest-intro). AndroidManifest.xml is encoded as binary XML.

Fortunately there is a tool to read this information: app-info-parser. This tool also reads the resources.arsc file, which includes the app icons, which we don't need to it adds a small memory overhead, but if this is a performance issue in the future we could fork app-info-parser and make that parsing separate.

Note that the package field of the APK almost always, but not actually always, the same as the applicationId see https://developer.android.com/guide/topics/manifest/manifest-element#package I think in our case we can trust that it is the same, but I don't quite understand this difference.

Unfortunately there is no Java API for reading the supported architectures within an APK (at least I can't find one). I think the best way to read the supported architectures of an APK would be to read the contents of the lib folder in the APK. It will contain a folder for each supported architecture. I have started work to add a readdir() method to random-access-zip (also, the name is bad, it should be zip-fs since it replicates the fs methods for a zipfile).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants