问题描述
我正在尝试创建一个 PHP 脚本以从 Android 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?
推荐答案
如果你在服务器上安装了 Android SDK,你可以使用 PHP 的 exec(或类似的)来执行 aapt
工具(在 $ANDROID_HOME/platforms/android-X/tools
中).
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 格式.APK zip 结构中的 AndroidManifest.xml
文件不是纯文本.
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.
这篇关于PHP:如何从 android .apk 文件中获取版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!