Gorets
Gorets

Reputation: 2442

Kotlin config for few flavors

I got the problem with configuration of my project for few flavors. I have 2 env-s, for staging and production one. Its config set into flavor-stage/Env.java and flavor-prod/Env.java and it works as expected when you work with java code and visible from Kotlin classes too, but it crashes during compiling with

Error:(19, 23) Unresolved reference: Env

It seems Kotlin can resolve classes from another flavor' folder. Please help to config it. My gradle.build is:

sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
}

buildscript {
    ext.kotlin_version = '1.0.4'
    repositories {
        jcenter()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.0.6"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
    }
}

Upvotes: 1

Views: 745

Answers (1)

Vyacheslav Gerasimov
Vyacheslav Gerasimov

Reputation: 1354

I suggest using the latest Kotlin version which is 1.1.0. Tested this case and it worked for me. Here is a sample project, hope it helps. https://github.com/4u7/android-flavor-demo

And check your directory structure. For my Env files I used:

/src/prod/java/com/myapp/flavor/EnvKotlin.kt /src/stage/java/com/myapp/flavor/EnvKotlin.kt

Upvotes: 1

Related Questions