Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robolectric 3.0 - Resource not resolved when using applicationIdSuffix

I have been sucessfully using this code to load resources both in an app and its unit tests with Robolectric 2.4:

getContext().getResources().getIdentifier(resName, "string", getContext().getPackageName());

where Context would be MyApplication in the App and TestMyApplication in Robolectric tests.

With Robolectric 3.0 this no longer works when an applicationIdSuffix is added to the build file, the call returns 0.

Is this a known issue? This is on com.android.tools.build:gradle:1.2.0-beta1 and org.robolectric:robolectric:3.0-rc2

Update https://github.com/robolectric/robolectric/issues/1623

like image 691
Philipp E. Avatar asked Mar 17 '23 11:03

Philipp E.


2 Answers

There is actually a simple fix for this now, just add @Config(constants = BuildConfig.class, packageName = com.your.package)

See https://github.com/robolectric/robolectric-samples/tree/master/android-flavors

like image 151
Philipp E. Avatar answered Apr 25 '23 13:04

Philipp E.


As workaround I created another build flavour jenkins where I removed suffix editing. Unfortunately it is not proper solution if you want to test something specific/customised for flavour.

like image 27
Eugen Martynov Avatar answered Apr 25 '23 11:04

Eugen Martynov