一、先讲Ubuntu16下aapt命令行读取apk信息
1.将appt放到文件夹下。比如/www/appt
2.cd 到 /www/appt 运行appt读取apk信息命令。“/www/util/upload/apk/592184.apk” 是apk所在的路径
./aapt dump badging /www/util/upload/apk/592184.apk
3.可能会报错
./aapt: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
4.解决报错
报错:
No such file or directory
sudo apt-get install lib32stdc++6
报错:
error while loading shared libraries: libz.so
sudo apt-get install lib32z1 lib32z1-dev
5.运行
./aapt dump badging /www/util/upload/apk/592184.apk
6.输出的apk信息
package: name='com.gamecenter' versionCode='20' versionName='2.5'
sdkVersion:'14'
targetSdkVersion:'21'
uses-permission:'android.permission.INTERNET'
uses-permission:'android.permission.WRITE_EXTERNAL_STORAGE'
uses-permission:'android.permission.READ_EXTERNAL_STORAGE'
uses-permission:'android.permission.MOUNT_UNMOUNT_FILESYSTEMS'
uses-permission:'android.permission.ACCESS_WIFI_STATE'
......
二、PHP 获取apk信息
$apptDir = '/www/appt/';
$apkDir = '/www/util/upload/apk/592184.apk';
//shell_exec 执行命令,$outPut(类型是字符串) 为apk的信息
$outPut = shell_exec( $apptDir . "aapt dump badging ".$apkDir);
//使用正则可匹配出特定的apk信息。(此处正则比较随意,可以写得更完善)
preg_match('/package: name=\'([^\'\"]+)\'/', $output, $package);
preg_match('/versionName=\'([^\'\"]+)\'/', $output, $version);
preg_match('/application: label=\'([^\'\"]+)\'/', $output, $name);