首页 > 解决方案 > 如何通过 Playstore APK 安装调试 ApK

问题描述

我的手机上安装了 Playstore 应用程序!我想用同一个项目的调试 APK 来调试那个移动应用程序。有什么方法可以调试该应用程序?我不想卸载现有的数据应用程序。现在,当我尝试通过 Playstore APK 安装调试 APK 时出现签名错误。

标签: androidandroid-studiodebuggingtestingadb

解决方案


如果您需要在设备上同时安装PlayStore apk 和调试Apk,您可以使用构建类型applicationIdSuffix,如下所示

将此添加到您的应用级别build.gradle

android {

    ...

    buildTypes {
        debug {
            applicationIdSuffix ".debug"
        }
        release {
            // Change to true if you want to apply ProGuard minify
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    ...
}

applicationIdSuffix ".debug"当您构建调试 apk并从 android studio 安装它时使用它,它将附加.debug在您现有的包名称上

例如

  • PlayStore 包名称:com.example.myapp

  • 调试包名称:com.example.myapp.debug

通过这种方式,您可以将两个版本的 apk 保留在设备上,并根据需要调试您的 apk。


编辑 1

如果您将 Google 服务与google-services.json一起使用,您可能会遇到以下错误

  • 错误:任务“:app:processDebugGoogleServices”执行失败。-解决方案
  • 找不到与包名称匹配的客户端 -解决方案

这是因为 google-services.json 需要匹配包名称,并且如果您想拥有多个应用程序风格(例如DebugRelease ),则需要拥有多个 google-services.json

所以根据谷歌文档

google-services.json 文件一般放在 app/ 目录下(Android Studio 应用模块的根目录)。从 2.2.0 版开始,插件支持构建类型和产品风味特定的 JSON 文件。以下所有目录结构均有效:

// dogfood and release are build types.
app/
    google-services.json
    src/dogfood/google-services.json
    src/release/google-services.json
    ...

推荐阅读