我需要得到一个Android APK的包名。我已经尝试解压缩APK和读取AndroidManifest.xml文件的内容,但它似乎不是一个文本文件。

如何提取APK的包名?


当前回答

一个非常简单的方法是使用apkanalyzer。

apkanalyzer manifest application-id "${_path_to_apk}"

其他回答

你可以使用分析APK…在Android Studio的Build菜单中,它将在新窗口的顶部显示包的名称。

如果你使用MS Notepad打开AndroidManifest.xml,搜索短语包,你会发现以下内容:

package manifest $xxx.xxxxxxx.xxxxxxx |

其中xxx.xxxxxxx.xxxxxxx是您的包名,只是在每个字符后面加上一个空格。

当您没有安装任何特定的工具时,这是一种有用的方法。

要在批处理脚本中使用它,让脚本只返回包名是很方便的(例如,当你有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`

如果你正在看谷歌播放,想知道它的包名,那么你可以看看url或地址栏。您将得到包名称。这里com.landshark.yaum是包名

 https://play.google.com/store/apps/details?id=com.landshark.yaum&feature=search_result#?t=W251bGwsMSwyLDEsImNvbS5sYW5kc2hhcmsueWF1bSJd

如果你没有安装Android SDK,就像在一些测试场景中一样,你可以使用下面的bash方法获取包的名称:

getAppIdFromApk() {
  local apk_path="$1"

  # regular expression (required)
  local re="^\"L.*/MainActivity;"
  # sed substitute expression
  local se="s:^\"L\(.*\)/MainActivity;:\1:p"
  # tr expression
  local te=' / .';

  local app_id="$(unzip -p $apk_path classes.dex | strings | grep -Eo $re | sed -n -e $se | tr $te)"

  echo "$app_id"
}

在mac上测试。'strings'和'unzip'在大多数linux上是标准的,所以也应该在linux上工作。