How to find support library resources using robolectric?

I am trying to use robolectric to scoff at my android apps. Unfortunately, after including an external library in my project, the tests crashed. Error information - about some library resource that was not found.

java.lang.RuntimeException: Could not find any resource  from reference ResName{com.company.app:style/Theme_AppCompat_Light_NoActionBar} from style StyleData{name='AppTheme_Base', parent='Theme_AppCompat_Light_NoActionBar'} with theme null

Does anyone have this problem?

+4
source share
2 answers

Libraries containing internal resources (AKA aar) should be displayed in project.properties files (in src / main). The contents of the file will be something like this (if you are using Android Studio):

android.library.reference.1=../app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.0

Take a look at the documentation .

+8
source

, Robolectric res. Custom Test Runner, res.

public class CustomTestRunner extends RobolectricTestRunner {

public CustomTestRunner(Class<?> testClass) throws InitializationError {
    super(testClass);
}

@Override
protected AndroidManifest getAppManifest(Config config) {
    final String BUILD_PATH = "src/main";
    final FileFsFile manifestFile = FileFsFile.from(BUILD_PATH, "AndroidManifest.xml");

    AndroidManifest appManifest = super.getAppManifest(config);
    return new AndroidManifest(manifestFile, appManifest.getResDirectory(), appManifest.getAssetsDirectory());
}
}

, :

@RunWith(RobolectricTestRunner.class) : RunWith(MyRobolectricTestRunner.class) Robolectric.

appManifest.getResDirectory() "build/intermediates/res/merged/debug".

-1

All Articles