在不生成签名 APK 的情况下调试发布构建类型 [英] Debugging The Release Build Type Without Generating a Signed APK

查看:31
本文介绍了在不生成签名 APK 的情况下调试发布构建类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目设置有两种构建类型:debugrelease.

I have a project setup with two build types: debug and release.

在我的应用模块中,我有三个不同的目录:debugreleasemain.

In my app module I have three different directories: debug, release and main.

我想要做的是测试 release 目录中的代码,但我似乎能做到的唯一方法是生成一个签名的 apk 并以这种方式将其加载到模拟器上.这意味着我无法正确调试它.

What I want to do is test the code in the release directory but the only way I can seem to do that is to generate a signed apk and load it onto an emulator that way. This means I can't debug it correctly.

当我将 app 模块的构建变体更改为 release 时,我在编辑配置"弹出窗口中收到以下错误.

When I change my app module's build variant to release I get the following error in the "Edit Configuration" popup.

错误:您当前选择的变体的 apk(app-release-unsigned.apk_ 未签名.请指定签名此变体的配置(发布).

Error: The apk for your currently selected variant (app-release-unsigned.apk_ is not signed. Please specify a signing configuration for this variant (release).

我希望做的是使用 build.gradle 文件中的 debugRelease 扩展 release 构建变体>app 模块,它将继承 release 目录中的代码,但我可以在 IDE 中运行它.

What I was hoping to do was extend the release build variant with one called debugRelease in the build.gradle file of the app module which would then inherit the code in the release directory but I would be able to run it from within the IDE.

我可能以错误的方式看待这个问题,我很高兴听到任何其他技术.

I may be looking at this the wrong way and I would be glad to hear any other techniques.

我可以做我想做的事吗?如果不是,最好的解决方案是什么?

Can I do what I'm trying to do? If not what is the best solution for this?

推荐答案

经过大量研究后,我决定继续我的 debugRelease 想法,它似乎运行良好.

After a lot of research I decided to go ahead with my debugRelease idea and it seems to be working well.

我在 app/src 下创建了一个名为 debugRelease/java 的新目录.在那里,当我生成签名的 apk 或发布版本时,我放了我想要不同的任何代码.

I create a new directory under app/src called debugRelease/java. In there I put any code that I wanted to be different when I generated a signed apk or release version.

这样做使我能够测试代码工作并能够对其进行调试.当然,这并不经常进行,它只是崩溃报告和记录差异,但是,如果我需要修复错误或其他问题,我可以.

Doing so enables me to test the code works and be able to debug it. Granted this isn't done very often and it's only crash reporting and logging differences but, on the off chance I need to fix a bug or something, I can.

在我的 build.gradle 文件中,我有以下设置.

In my build.gradle file, I have the following setup.

buildTypes {
    release {

    }

    debug {

    }

    debugRelease {
        signingConfig signingConfigs.debug
    }
}

sourceSets { 
    debugRelease {
        res.srcDirs = ['src/debug/res'] // this uses the debug's res directory which contains a "debug" icon
    }

    release {
        java.srcDirs = ['src/debugRelease/java'] // this avoids copying across code from the debugRelease java directory
    }
}

所以现在当我想测试发布代码时,我只需将我的构建变体更改为 debugRelease.

So now when I want to test the release code, I just change my build variant to debugRelease.

这篇关于在不生成签名 APK 的情况下调试发布构建类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆