Chris
Chris

Reputation: 3698

How to user resValue in String resource file

I have defined a property in my ~/.gradle/gradle.properties and I want to access it in a string resources file.

Definition in ~/.gradle/gradle.properties
ServerIP="XXX.XXX.XX.XX"

Declaration in app/build.gradle

android {  
  buildTypes.each {  
    it.resValue "string", "ServerIP", "SERVER_IP"
  }
}

Usage in string/web_services.xml
<string name="serverIP">@string/SERVER_IP</string>

Error during build
Error:(4, 5) No resource found that matches the given name (at 'serverIP' with value '@string/SERVER_IP').

Is there any way to achieve this or it can't be done?

Upvotes: 0

Views: 733

Answers (1)

Alexander Mironov
Alexander Mironov

Reputation: 3102

The problem is with this line:

it.resValue "string", "ServerIP", "SERVER_IP"

The first argument is type, the second is name and the third is value. In your case name should be "SERVER_IP" and value should be ServerIP without quotes. So final piece in build.gradle:

android {  
  buildTypes.each {  
    it.resValue "string", "SERVER_IP", ServerIP
  }
}

Upvotes: 1

Related Questions