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

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

问题描述

我有一个具有两种构建类型的项目设置: debug release .

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

在我的应用程序模块中,我有三个不同的目录: debug release main .

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天全站免登陆