yshrsmz / BuildKonfig

BuildConfig for Kotlin Multiplatform Project
Apache License 2.0
729 stars 33 forks source link

ios configuration and environment variables #107

Closed estivensh closed 10 months ago

estivensh commented 10 months ago

for someone who has the doubt of how to call the variables generated from ios it would be as follows since I did not see practically no example that explained it:

in Kotlin

buildkonfig {
  packageName = "com.example.app"
  exposeObjectWithName = "BuildKonfigPublic"
}

in SwiftUI

import shared

BuildKonfigPublic().accessKey

for the second contribution I have about the environment variables because in some examples it is also confusing and the official documentation suggests to place it in the gradle.properties if you want to place it in the local.properties file from the shared module will not recognize the variable so I did the following:

import java.util.Properties

val localProperties = Properties()
localProperties.load(rootProject.file("local.properties").reader())

buildkonfig {  
   packageName = "com.example.app"
   exposeObjectWithName = "BuildKonfigPublic"
   defaultConfigs {
      buildConfigField(STRING, "accessKey", localProperties.getProperty("value"))
   }
}