android - 如何通过 Playstore APK 安装调试 ApK

标签 android android-studio debugging testing adb

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

最佳答案

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

将此添加到您的app 级别 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" 当您构建 debug apk 并从 android studio 安装它时,它将附加 .debug 在您现有的包名

例如

  • PlayStore 包名称:com.example.myapp

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

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


编辑 1

如果您使用带有 google-services.json 的 Google 服务,您可能会遇到以下错误

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

这是因为 google-services.json 需要匹配包名称,如果你想拥有多个应用程序风格,如 Debug,你需要有多个 google-services.json发布

根据Google Documentation

The google-services.json file is generally placed in the app/ directory (at the root of the Android Studio app module). As of version 2.2.0 the plugin supports build type and product flavor specific JSON files. All of the following directory structures are valid:

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

关于android - 如何通过 Playstore APK 安装调试 ApK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51435437/

相关文章:

android - 在运行时以编程方式在 android 中更改自定义进度轮中的颜色

android - 如何在另一个自定义 View 中添加自定义 View ?

android - 在 Android Studio 中运行参数化单元测试时,没有找到给定的测试包括错误

c++ - 调试多线程程序

android - 我们是否需要 API key 才能在 Android 的 YouTube Player API 中播放视频?

android - 在 Android Studio 中导入 Gradle Android 项目时出错

java - 图像处理使用 ARCore 和 Android Studio 使用 ArFragment 将 3D 模型放置在图像上

visual-studio-2008 - 您可以使用 VS2008 调试器在特定位置忽略来自第 3 方 dll 的异常吗?

debugging - 无法使用 PhantomJS 远程调试器在断点处访问 casper 实例方法

c# - 我可以在从这个 c# 到 android 设备的一次传输中接收更多字节吗?