I want to read few properties from a static java class file as below

class MyClass {
      public static final class MyStaticClass {
         public static final String PROPERTY_A = "myStringA";
         public static final String PROPERTY_B = "myStringB";

This would be in MyClass.java file under


I need to read PROPERTY_A, and PROPERTY_B in my app build.gradle inside android{} block.

Note that these need to be read from java file for a specific reason, and are not general properties. Hence, I am not reading them from gradle.properties files.

I went through How do I call a static Java method from Gradle

but the article wasn't super clear.

I also tried gradle docs, but couldn't find a super clear answer.

I am bit new to groovy, so any suggestions here would be super helpful.


    • curious.. why do this? Why not just have a property file and then pull those values from there into build.gradle? I think information is supposed to flow from the build config into the application, not the other way around.

Find out when in the lifecycle that the code in the android {} gets executed. Worst case this will be early, so you may have to compile that class before anything else. Then write some groovy code in your gradle script to get the properties.

  • 1
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions