androidandroid-build-type

No resource found with custom buildType from main project with library support


So, I have the following project structure:

I have my main project which holds some nice layouts. I also have my library project, which has some colors, dimens values and so on.

main project

library project

Everything was working perfect before adding custom buildTypes: the main project had the layouts, where I used the res/drawables/colors from the library project.

After I added my custom buildTypes to my main project gradle I can't build the project anymore, saying no resource found with that name. Important, this only happens if I choose other then debug buildType. With debug it still works, but than I can't change between endspoints.

Could someone tell me, why the library project is failing to provide the resources (using debug configuration)?

Any possible solution?

What I would like to have: final APK == any custom buildType + library debug buildType

What I am able to do now: final APK == debug buildType + debug BuildType

please find the code from my main project's gradle:

`debug{
  

debuggable true;

testCoverageEnabled true;


//default values

resValue "string", "app_name", "MyApp S1"

buildConfigField "String", "applicationName", '"MyApp S1"'

buildConfigField "String", "applicationVersion", '"4.0"'

}


ENV2 {

initWith(buildTypes.debug)

 applicationIdSuffix ‘.envtwo’

versionNameSuffix “_ENV 2"

resValue "string", "app_name", “MyApp ENV2”

buildConfigField "String", "applicationName", '"MyApp ENV2”’

}
`

error message:

/app/src/main/res/layout/failover_tutorial.xml

Error:(1) No resource found that matches the given name (at 'background' with value '@color/manual_bg_color’).

where failover_tutorial.xml sits in the main project and the @color should come from the library.


Solution

  • So, I found the solution which was the following:

    1. click on the app module and go to module settings
    2. on the left module list select 'app' and go to 'Dependencies' tab
    3. look for your library project as a dependency
    4. make sure the 'Scope' is NOT 'Debug compile', if it is then set to 'Compile'

    By doing this, it will be compile with all of your buildTypes.