• 6
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Read static Java class from build.gradle file

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

src/main/java/myProject/

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.

Thanks!

    • 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