android testBuildType不起作用 [英] android testBuildType not working

查看:223
本文介绍了android testBuildType不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

android {
  ...
  testBuildType "deviceTest"
  buildTypes {
    debug {
      // Using 10.0.2.2 (the desktop's localhost), as the app normally runs on an Emulator
      // in debug mode.
      buildConfigField "String", "BACKEND_URL", '"http://10.0.2.2"'
      buildConfigField "Integer", "PORT", "8080"
      applicationIdSuffix ".debug"
    }
    // Use local host for testing, for MockWebServer
    deviceTest {
      initWith debug
      buildConfigField "String", "BACKEND_URL", '"http://localhost"'
    }
    release {
      ...
    }
  }
}

与Google文档完全一样,此处.但是,这导致单元测试无法访问测试依赖项(如JUnit),因此测试无法运行.

Exactly like Google doc implies here. However, this causes test dependencies (like JUnit) to be unreachable from unit tests, and so the test cannot run.

推荐答案

我在AS 3.1.3上发现了此问题.

I figured out this issue on AS 3.1.3.

问题是Build Variant和testBuildType不匹配.因此,将testBuildType添加到gradle文件后,转到构建->选择构建变体",然后为您的应用选择相同的变体.

The problem is Build Variant and testBuildType doesn't match. So after adding testBuildType to your gradle file, go to 'Build -> Select Build Variant' and select the same variant for your app.

在正确运行androidTest之前,您可能还需要设置签名密钥或解决proguard问题,但是依赖项现在应该可以访问.

You may also need set signing key or solve proguard issues before running androidTest correctly, but the dependencies should be reachable now.

可以在此处跟踪更多详细信息: https://issuetracker.google.com/issues/36995546

More detail can be tracked here: https://issuetracker.google.com/issues/36995546

这篇关于android testBuildType不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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