Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Resources converting to string TypedValue warning

Ok I'm looking right past something here..

Every time I'm in my app and I change activities, logcat reports series of warnings:

02-04 14:42:36.524: WARN/Resources(1832): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f08002b} 02-04 14:42:36.524: WARN/Resources(1832): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f08002c} 02-04 14:42:36.524: WARN/Resources(1832): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f08002d} 

Other apps are not showing such warnings. Is this a pre-release/aapt compression thing?

like image 749
DJC Avatar asked Feb 04 '11 23:02

DJC


2 Answers

These warnings only occurred when a certain developer option was enabled.

Device Settings > Developer options > Disable 'Enable view attribute inspection'

like image 143
Tobrun Avatar answered Nov 02 '22 18:11

Tobrun


You are using a bool resource where a string is expected.

You can find which resource is being used incorrectly by opening your generated R.java file and searching for the resource IDs from the logcat message:

0x7f08002b 0x7f08002c 0x7f08002d 

All three should be from your bool.xml file (the "t=0x12" in the warning message means the resources are TYPE_INT_BOOLEAN).

Then, find where those resource IDs are being used in your project (probably a layout xml, but could be anywhere) and make sure the types match.

Here's an example of a TextView that would generate that log message. If in my res/values/bool.xml I have:

<resources>     <bool name="foo_flag">false</bool> </resources> 

I can incorrectly refer to it from a a layout xml file:

<TextView android:id="@+id/foo"           android:layout_width="wrap_content"           android:layout_height="wrap_content"           android:text="@bool/foo_flag"></TextView> 

When I run that app, I'll get the warning message since "text" expects a string resource, not a bool (my app appears as expected though since the flag is converted to the string "false").

Updated for Android Gradle 4.X:

As of sometime by version 4.0.1 of the Android grade plugin this has changed. An R.java file is no longer generated. Instead An R.txt file is generated located somewhere like:

    build/intermediates/runtime_symbol_list/{variant}/R.txt 
like image 32
Mike Avatar answered Nov 02 '22 18:11

Mike