從Gradle 傳遞值
Gradle 提供了兩種從Gradle 傳遞值給Java 值的方法:
android { buildTypes { debug { buildConfigField "int", "FOO", "42" buildConfigField "String", "FOO_STRING", "\"foo\"" buildConfigField "boolean", "LOG", "true" } release { buildConfigField "int", "FOO", "52" buildConfigField "String", "FOO_STRING", "\"bar\"" buildConfigField "boolean", "LOG", "false" } } }
1.生成Java常數:
透過將buildConfigField 新增至build.gradle 檔案中的buildTypes 區塊,您可以建立可透過BuildConfig 類別存取的Java 常數:android { buildTypes { debug { resValue "string", "app_name", "My App Name Debug" } release { resValue "string", "app_name", "My App Name" } } }
以上是如何將值從 Gradle 傳遞到我的 Java 程式碼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!