AndroidStudio disable "Expected resource of type string"
Asked Answered
S

5

28

I've just tried to generate signed apk for one of my projects (I already did this before), but (maybe since updating Android Studio) I'm getting

Error:Error: Expected resource of type string [ResourceType]

This is because I'm using Butterknife's @BindString, that is generated into something like that

target.settings = res.getString(2131230792);

How can I make studio not detect this as error? I've tried searching in settings, but without success.

Sting answered 26/1, 2016 at 8:44 Comment(2)
I've been using butterknife for a while now, and this didn't appear until I started messing with product flavors in my gradle file.Umlaut
Android Studio never runs out of stuff that cause developer headachesPhenoxide
H
8

This is reported on the GitHub project. It will be fixed in the next version of ButterKnife.

The workaround is indicated there, and is to add a lint.xml file on the app module with the following content to ignore that errors on *$$ViewBinder classes (the ones that ButterKnife generates):

<issue id="ResourceType">
    <!-- Remove this when this is fixed: https://github.com/JakeWharton/butterknife/issues/338 -->
    <ignore path="**/*$$ViewBinder.java" />
</issue>
Heins answered 23/3, 2016 at 20:16 Comment(1)
The accepted answer blindly turns off all ResourceType lint checks for your module, exposing your codebase to potentially more bugs, while this answer specifically targets the generated classes that cause the issue. This is why I prefer this answer.Neat
S
66

Answer to this is: disable lint rule in your build.gradle

android {
  lintOptions {
    disable "ResourceType"
  }
}

Edit: This may happen particularly when migrating from Eclipse to Android Studio.

Sting answered 26/1, 2016 at 11:31 Comment(0)
H
8

This is reported on the GitHub project. It will be fixed in the next version of ButterKnife.

The workaround is indicated there, and is to add a lint.xml file on the app module with the following content to ignore that errors on *$$ViewBinder classes (the ones that ButterKnife generates):

<issue id="ResourceType">
    <!-- Remove this when this is fixed: https://github.com/JakeWharton/butterknife/issues/338 -->
    <ignore path="**/*$$ViewBinder.java" />
</issue>
Heins answered 23/3, 2016 at 20:16 Comment(1)
The accepted answer blindly turns off all ResourceType lint checks for your module, exposing your codebase to potentially more bugs, while this answer specifically targets the generated classes that cause the issue. This is why I prefer this answer.Neat
P
6

Maybe a better solution is to temporary disable error/warning by using @SuppressLint("ResourceType") just before the method definition.

Preoccupancy answered 12/12, 2016 at 21:52 Comment(1)
Welcome to StackOverflow! Check How to Answer for tips on giving good answers to questions here. Specifically there are ways to format code snips so they show as code rather than plain text. Also, in general it's best to focus on newer questions without well accepted answers.Sarmatia
S
1

I has a similar problem. with a getString method. Turned out i was trying to get the string value not from strings.xml but from ids.xml, because i was getting it with getString(R.id.MYSTRING), when it should be R.string.MYSTRING

Stanleystanly answered 1/10, 2016 at 19:21 Comment(0)
B
-1

this is for some Views by same id and u try to change some property for one of them. When try to generate apk android find some confilict about resours id

To solve that

better way find the code and try solve that from another way to your purpose

GoodLuck

Biel answered 5/4, 2017 at 6:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.