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 {
...
}
}
}
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.
I figured out this issue on AS 3.1.3.
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.
You may also need set signing key or solve proguard issues before running androidTest correctly, but the dependencies should be reachable now.
More detail can be tracked here: https://issuetracker.google.com/issues/36995546
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With