1

Within my resources (res/) folder, I have the following files among others.

├── values
│   ├── dimens.xml
│   ├── strings.xml
│   └── values.xml
├── values-en
│   └── strings.xml
├── values-de
│   └── strings.xml

In values/values.xml I define a boolean which is needed in my application:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <bool name="myboolean">false</bool>
</resources>

When I run my application on a device where the language is set to English however I find that an exception is thrown at runtime while referencing myboolean:

android.content.res.Resources$NotFoundException: Resource ID #0x7f020001 type #0x3 is not valid.

Strangely, if I copy the values.xml file into the localized folders, the boolean is read just fine and there is no runtime exception. I.e.:

├── values
│   ├── dimens.xml
│   ├── strings.xml
│   └── values.xml
├── values-en
│   ├── strings.xml
│   └── values.xml
├── values-de
│   ├── strings.xml
│   └── values.xml

Why does this value need to be defined in the localized folders? Shouldn't the default values folder suffice?

Of note, this only appears to happen to my application on specific FireOS devices and may be a bug specific the FireOS build on those devices. The FireOS build is based on Android API level 23.

Collin
  • 1,777
  • 4
  • 26
  • 42
  • "Shouldn't the default values folder suffice?" -- yes, it should. Given your description, I would assume some sort of FireOS bug. Out of curiosity, do you also have problems with `dimens.xml`? I assume those resources are also only in the default `res/values/` directory. – CommonsWare Jan 13 '22 at 01:10
  • No, there is no issue with `dimens.xml` interestingly. It sounds like I may need to file a bug with the FireOS platform team. – Collin Jan 13 '22 at 01:19
  • My guess is that what you describe here as `myboolean` is something "real" that your app is using. You might try an experiment: add another boolean resource, only to `res/values/values.xml`, and see if it works, particularly from some vanilla location (e.g., `onCreate()` of your launcher activity). If it works, then your problem probably is something specific to `myboolean`, and perhaps there is something that you're missing about where and how you are using it. If OTOH the new boolean resource fails in the same way, then I'm back to a FireOS problem. – CommonsWare Jan 13 '22 at 01:31
  • So I had actually tried that. Created other variables only in `res/values/values.xml` and oddly the problem didn't occur with strings or other types -- only booleans which I referenced from my Application class using `this.getResources().getBoolean(R.bool.whatever)`. The original problem that I was setting out to solve was that `WorkManager` wasn't initializing properly due to the boolean `workmanager_test_configuration` not being found. So then I tried to see if my application could read _any_ booleans from resources and found it could not unless defined in the localized folder. – Collin Jan 13 '22 at 01:49
  • So to me it seems that FireOS is doing something strange and erasing all unlocalized booleans. Very odd. – Collin Jan 13 '22 at 01:52
  • Agreed, both on where the problem is coming from and the "very odd" bit. – CommonsWare Jan 13 '22 at 12:12

0 Answers0