PHP:如何获取版本从机器人的.apk文件?机器人、版本、文件、PHP

2023-09-03 20:48:30 作者:萌喵甜甜酱

我想创建一个PHP脚本来得到的Andr​​oid APK文件的应用程序版本。 从提取的APK(ZIP)文件的XML文件,然后解析XML是一种方式,但我想它应该是简单的。像 PHP手册,例如#3。 任何想法如何创建脚本?

I am trying to create a PHP script to get the app version from Android APK file. Extracting XML file from the APK (zip) file and then parsing XML is one way, but I guess it should be simpler. Something like PHP Manual, example #3. Any ideas how to create the script?

推荐答案

如果您已经安装在服务器上的Andr​​oid SDK中,你可以使用PHP的exec(或类似)执行 AAPT 工具(在 $ ANDROID_HOME /平台/ Android的X /工具)。

If you have the Android SDK installed on the server, you can use PHP's exec (or similar) to execute the aapt tool (in $ANDROID_HOME/platforms/android-X/tools).

$ aapt dump badging myapp.apk

和输出应包括:

package: name='com.example.myapp' versionCode='1530' versionName='1.5.3'

如果您的不能的安装Android SDK,无论出于何种原因,那么你就需要解析Android的二进制XML格式。该的Andr​​oidManifest.xml 文件中的APK拉链结构内部的不可以纯文本。

If you can't install the Android SDK, for whatever reason, then you will need to parse Android's binary XML format. The AndroidManifest.xml file inside the APK zip structure is not plain text.

您需要的端口像AXMLParser 从Java到PHP。

You would need to port a utility like AXMLParser from Java to PHP.