我需要得到一个Android APK的包名。我已经尝试解压缩APK和读取AndroidManifest.xml文件的内容,但它似乎不是一个文本文件。
如何提取APK的包名?
我需要得到一个Android APK的包名。我已经尝试解压缩APK和读取AndroidManifest.xml文件的内容,但它似乎不是一个文本文件。
如何提取APK的包名?
当前回答
由于在Android文档中提到AAPT已被弃用,在Linux中使用AAPT2命令获取包名如下:
./aapt2 dump packagename <path_to_apk> ./aapt2 dump
因为我使用的是旧版本的Gradle构建,所以我不得不下载一个更新版本的AAPT2,就像这里提到的:
从谷歌Maven下载AAPT2
使用构建工具在我的sdk - 25.0.3, 26.0.1和27.0.3,执行aapt2命令显示一个错误:无法打开'packagename':没有这样的文件或目录。这就是我选择更新版本的AAPT2的原因。
对于linux,我使用3.3.0-5013011。
其他回答
如果你使用MS Notepad打开AndroidManifest.xml,搜索短语包,你会发现以下内容:
package manifest $xxx.xxxxxxx.xxxxxxx |
其中xxx.xxxxxxx.xxxxxxx是您的包名,只是在每个字符后面加上一个空格。
当您没有安装任何特定的工具时,这是一种有用的方法。
对于Windows,以下对我来说是有效的:
:: // Initializing variables
SET adb="C:\Users\<User name>\AppData\Local\Android\Sdk\platform-tools\adb"
SET aapt="C:\Users\<User name>\AppData\Local\Android\Sdk\build-tools\22.0.0\aapt"
SET APKPath=C:\Users\<User name>\Desktop\APK\Instant_Instal\
CD %APKPath%
:: // Searching for apk file and storing it
FOR /F "delims=" %%f IN ('dir /S /B *.apk') DO SET "APKFullPath=%%f"
SET apk=%APKFullPath%
:: // Command adb install apk, run apk
%adb% install %apk%
:: // Fetching package name from apk
%aapt% dump badging %APKFullPath% | FIND "package: name=" > temp.txt
FOR /F "tokens=2 delims='" %%s IN (temp.txt) DO SET pkgName=%%s
del temp.txt
:: // Launching apk
%adb% shell monkey -p %pkgName% -c android.intent.category.LAUNCHER 1
pause
Note
请根据adb、aapt路径和apk在系统中的位置,编辑adb、aapt、APKPath路径。
工作:
Here I have added the apk in a folder on Desktop "\Desktop\APK\Instant_Instal\". The command %adb% install %apk% installs the application if the device is connected. This %aapt% dump badging %APKFullPath% | FIND "package: name=" > temp.txt fetches package name and a few other details like version etc. of the apk and stores in a temp.txt file in same location as that of the apk. FOR /F "tokens=2 delims='" %%s IN (temp.txt) DO SET pkgName=%%sextracts the package name and assigns topkgName` variable Finally %adb% shell monkey -p %pkgName% -c android.intent.category.LAUNCHER 1 launches the app.
从本质上讲,上面的代码将apk从桌面“desktop \ apk \ instant_install \”中的给定位置安装到设备并启动应用程序。
另一个解决方案是使用aapt列表,并使用sed来解析它:
aapt list -a $PATH_TO_YOUR_APK | sed -n "/^包组[^s]/s/.*name=//p"
如果你正在看谷歌播放,想知道它的包名,那么你可以看看url或地址栏。您将得到包名称。这里com.landshark.yaum是包名
https://play.google.com/store/apps/details?id=com.landshark.yaum&feature=search_result#?t=W251bGwsMSwyLDEsImNvbS5sYW5kc2hhcmsueWF1bSJd
有一个非常简单的方法,如果你的智能手机上已经准备好了APK。只要使用这些应用程序之一:
包名称查看器应用程序