android - 无论如何在这里访问 java 代码中的 gradle ext 属性?

标签 android android-gradle-plugin

这是项目级gradle.build文件:

 buildscript {
    ext {
        server_test = 'http://192.618..'
        server_main = "https://68.5..."
        another_value = "test"
    }

    ext.kotlin_version = '1.3.41'

....
....

我在我的应用级 gradle.build 文件中使用这些值。

有没有办法在我的 Java 项目文件中也访问这些变量!。

最佳答案

如果您试图在 Java 代码中显式访问 gradle 扩展,答案是否定的:这是不可能的,请参见:Android - Read build.gradle properties inside class , 也看到这个 Is it possible to declare a variable in Gradle usable in Java?

关于android - 无论如何在这里访问 java 代码中的 gradle ext 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57069501/

相关文章:

android - 低分辨率和高分辨率的不同AndroidManifest.xml

android - 如何从 Google 云端硬盘中删除文件

Android Studio 和 NDK 集成问题

android - 用于 IntelliJ 中 Android 单元测试的instrumentTest 文件夹

android - Gradle 无法解析 androidx.appcompat :appcompat:1. 1.0-alpha01 和 com.google.android.gms :play-services-nearby:16. 0.0

android - 错误 :No resource found that matches the given name (at 'minHeight' with value '?attr/actionBarSize' )

java - 我的 Android 应用程序在模拟器上运行但无法在我的 Android 设备上运行

android - Teechart 在第一次加载时显示压缩,因为展开的键盘会缩小 View

java - 替换字符串中 a-z 0-9 和 , 旁边的所有字符

android - 错误 : Failed to find: com. android.support :support-v4:20. 0.+