我需要得到一个Android APK的包名。我已经尝试解压缩APK和读取AndroidManifest.xml文件的内容,但它似乎不是一个文本文件。
如何提取APK的包名?
我需要得到一个Android APK的包名。我已经尝试解压缩APK和读取AndroidManifest.xml文件的内容,但它似乎不是一个文本文件。
如何提取APK的包名?
当前回答
我也尝试了反编译的东西,它的工作,但最近我发现了最简单的方法:
从Appium网站下载安装Appium 打开Appium->Android设置,选择目标apk文件。然后你得到你想要的一切,包信息,活动信息。
其他回答
如果你使用MS Notepad打开AndroidManifest.xml,搜索短语包,你会发现以下内容:
package manifest $xxx.xxxxxxx.xxxxxxx |
其中xxx.xxxxxxx.xxxxxxx是您的包名,只是在每个字符后面加上一个空格。
当您没有安装任何特定的工具时,这是一种有用的方法。
在Android设备上安装apk。然后
您可以启动adb shell并执行PM list packages -f,这将显示每个已安装apk的包名称。
这是从 找到包名称为Android应用程序使用意图启动市场应用程序从网络。
你可以通过以下方式获取包名:
packageManager.getPackageArchiveInfo(apkFilePath, 0)?.packageName
对于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 \”中的给定位置安装到设备并启动应用程序。
要在批处理脚本中使用它,让脚本只返回包名是很方便的(例如,当你有APK时卸载应用程序)。
下面是我使用的脚本:
# extract the android package id from a built apk file
# usage ./getPackageName.sh <path-to-apk>
line=`aapt dump badging "$1" | grep package:\ name`
# above returns:
# package: name='com.calvium.myapp' versionCode='1' versionName='1.0'
if [[ $line =~ name=\'(.+)\'\ versionCode ]]; then
echo ${BASH_REMATCH[1]}
else
echo "Failed to find package name"
exit 1
fi
可参考要旨
你可以这样写:
adb卸载`./getPackageName.sh file.apk`