Closed yuya-h-29 closed 2 months ago
@yuya-h-29
Hi, can you show us your complete build.gradle.kts
? Specifically, I'd like to see how you configure the sourcesets.
@yshrsmz Thank you for the quick response. Here is my build.gradle.kts
in the shared module.
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
id("co.touchlab.skie") version "0.6.1"
kotlin("plugin.serialization") version "1.9.20"
id("com.codingfeline.buildkonfig") version "0.15.1"
}
kotlin {
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach {
it.binaries.framework {
baseName = "shared"
isStatic = true
}
}
sourceSets {
commonMain.dependencies {
//put your multiplatform dependencies here
implementation(libs.kotlinx.coroutines.core)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.content.negotiation)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.kotlinx.datetime)
}
androidMain.dependencies {
implementation(libs.androidx.lifecycle.viewmodel.ktx)
implementation(libs.ktor.client.android)
}
iosMain.dependencies {
implementation(libs.ktor.client.darwin)
}
commonTest.dependencies {
implementation(libs.kotlin.test)
}
}
}
buildkonfig {
packageName = "com.example.myApp"
defaultConfigs {
val apiKey: String = gradleLocalProperties(rootDir).getProperty("API_KEY")
buildConfigField(STRING, "API_KEY", apiKey)
}
}
android {
namespace = "com.example.myApp"
compileSdk = 34
defaultConfig {
minSdk = 24
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
Now I figured @yshrsmz documented run generateBuildKonfig task.
Could you tell me what and how should I run generateBuildKonfig task
please? (I haven't done this in my project, so this might be the reason why I get Unresolved reference error.)
can you try adding this to top of your code and rebuild your project?
import com.example.myApp.BuildKonfig
BuildKonfig file is created at compile time, not gradle configure time, and maybe problem comes from here...
IntelliJ provided Gradle sync task won't run generateBuildKonfig
task.
Could you tell me what and how should I run generateBuildKonfig task please? (I haven't done this in my project, so this might be the reason why I get Unresolved reference error.)
Basically, you don't need to call it manually, as it should be hooked to the main compile tasks.
Once you build the project, BuildKonfig objects should be populated automatically.
Feel free to re-open the issue if you still have some issue/update
Hello, @yshrsmz. I'm new to Kotlin Multiplatform and Android development, and I'm trying to use BuildKonfig in my project. However, I'm having trouble importing it.
I've already posted my question on my stack overflow (here is the link), but I wanted to ask if there are any additional steps I'm missing when using BuildKonfig in my project.
Here are the steps I've taken:
plugins { alias(libs.plugins.kotlinMultiplatform) alias(libs.plugins.androidLibrary) id("co.touchlab.skie") version "0.6.1" kotlin("plugin.serialization") version "1.9.20" id("com.codingfeline.buildkonfig") version "0.15.1" }
buildkonfig { packageName = "com.example.myapp"
}
package com.example.myapp
import io.ktor.client.HttpClient import io.ktor.client.call.body import io.ktor.client.request.get
class ArticlesService(private val httpClient: HttpClient) {
}