1

(You don't need to know android to help solve this question)

I am using a third party library in my android app. Call it libX. libX has a class named Constants in which they keep a number of constants. One such constant is used all over inside the library. But I need the value of that constant to be different from what it is. How do I change the value of that constant?

As illustration: I want to change the value of badConstant from “I am too bad” to “I am good”.

class Constants{
  public static final String badConstant = “I am too bad”;
}

I am open to any sort of creative solution. The thing is if I had a setter/constructor for the value all would be well. But right now there is no setter.

Also this library is obtained as a gradle dependency (if you care)

Nouvel Travay
  • 6,292
  • 13
  • 40
  • 65
  • Do you have access to the original code? Then change it there and compile it yourself. – TimoStaudinger May 25 '16 at 00:13
  • This might be worth looking into: http://stackoverflow.com/questions/3301635/change-private-static-final-field-using-java-reflection – Michael Markidis May 25 '16 at 00:25
  • @TimoSta, no I don't. it's a grade dependency that I just pull in using `compile` – Nouvel Travay May 25 '16 at 00:34
  • @NouvelTravay, can you find it in [MavenCentral](http://search.maven.org/)? – Daniel May 25 '16 at 01:04
  • No it's a private vendor provided binary jar, I am thinking of the option of simply replacing the single class and then re create the jar. The problem is that each time I upgrade I would have to remember to exchange that single file. – Nouvel Travay May 25 '16 at 01:14
  • This is, generally speaking, a bad idea. You have no guarantees about how this field is being used and your mucking around with it could result in unexpected behavior from this library. I would suggest communicating with the owner of the library and finding some other solution, which may or may not involve the library owner making some new API to support your needs. – Karakuri May 25 '16 at 02:25

0 Answers0