This is implemented, but currently only in Android Studio. That's because in Studio I could leverage a lot of IntelliJ support for flow analysis and external annotations.
This went into Android Studio 0.5.5; see the description in the release notes: http://tools.android.com/recent/androidstudio055released The data is there now, so we can eventually add the same analysis from lint, it just hasn't been done yet. In addition, one of the most recent versions of the Android plugin (0.10 or maybe 0.10.1) added a new extract annotations task, so your android-libraries, if they depend on and use the support annotations, will automatically package an external annotations file with your AAR, which clients of the library can then use for analysis. On Thu, May 15, 2014 at 3:15 PM, Özcan Kaymak <[email protected]> wrote: > The support-annotations library now supports annotation for @StringRes > (and a lot more). > I was hoping this issue would be fixed now, but it is still possible to > add a int value to a setText method. > > Also checked by using these annotations, and in Android Studio you get a > nice message: *Expexted resource of type string* > > Does this mean we can expect a solution shortly? > > > On Thursday, March 7, 2013 4:36:43 AM UTC+1, Tor Norbye wrote: > >> Thanks for the idea! >> >> I've filed the following issue to track this request: >> https://code.google.com/p/android/issues/detail?id=52906 >> >> It won't be trivial to implement, but should be useful. If you have >> examples of how you ran into this bug, can you add it here or better yet >> attach it to that issue? I'd like to make sure that if there are particular >> patterns that people easily accidentally call, that the flow analysis will >> catch those. >> >> We already look for accidental color usages, like this one: >> textView.setTextColor(android.R.color.red) >> which is simple to make, since R.color.red is an int and it looks like >> the method should accept it. >> >> What are the scenarios you run into this with strings? >> >> -- Tor >> >> >> >> On Tue, Feb 26, 2013 at 6:42 AM, Richard Critten <richard...@googlemail. >> com> wrote: >> >>> Unless, for example, getSomeValueFromSomewhere() was returning a string >>> id as the result of a case statement - so the text could be dynamically set. >>> >>> >>> On Tuesday, February 26, 2013 1:39:48 PM UTC, Özcan Kaymak wrote: >>>> >>>> After making this error twice today, it seemed to me it would be a >>>> useful new lint check. >>>> On a TextView (a Button also) there is a method setText, where you >>>> normally use a string or a string-resource. >>>> A string-resource is actually an int, so this error is easily made: >>>> >>>> TextView textView = (TextView)findViewByID(R.id.textview); >>>> textView.setText(getSomeValueFromSomewhere()); >>>> >>>> This will compile, but will most likely crash on runtime if >>>> getSomeValueFromSomewhere() returns an int. >>>> >>>> It would be nice if Lint could check for this error by checking if the >>>> int-value corresponds to a R.string.-field. >>>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "adt-dev" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >>> >>> >> >> -- > You received this message because you are subscribed to the Google Groups > "adt-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "adt-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
