Is it possible to declare a variable in Gradle usable in Java?

后端 未结 9 1482
春和景丽
春和景丽 2020-11-22 09:11

Is it possible to declare a variable in Gradle usable in Java ? Basically I would like to declare some vars in the build.gradle and then getting it (obviously) at build time

9条回答
  •  星月不相逢
    2020-11-22 09:31

    I'm using this code and working very fine.

    def baseUrl = '\"http://patelwala.com/myapi/"'
    def googleServerKey = '\"87171841097-opu71rk2ps35ibv96ud57g3ktto6ioio.apps.googleusercontent.com"'
    android {
      buildTypes {
      release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField 'String', 'BASE_URL', baseUrl
            buildConfigField 'String', 'web_client_id', googleServerKey
        }
        releasedebug {
            initWith debug
            buildConfigField 'String', 'BASE_URL', baseUrl
            buildConfigField 'String', 'web_client_id' ,googleServerKey
        }
        debug {
    
            buildConfigField 'String', 'BASE_URL', baseUrl
            buildConfigField 'String', 'web_client_id', googleServerKey
        }
     }
    }
    

    }

提交回复
热议问题