Anael
Anael

Reputation: 470

Different sourceSet (build variants) broke my project

I have an Android project that was running perfectly on Java. This project has several source sets and build variants. For the sake of simplicity let's say I have 2 build variants "BuildA" and "BuildB", with 2 different source sets.

Here is how my build.gradle looked like in my java project: (notice the slight difference for the "res" folder)

sourceSets {
        buildA {
            java.srcDirs = ['src/main/java']
            res.srcDirs = ['src/main/res']
            assets.srcDirs = ['src/main/assets']
        }
        buildB {
            java.srcDirs = ['src/main/java']
            res.srcDirs = ['src/buildb/res']
            assets.srcDirs = ['src/main/assets']
        }

In my project, I have different source sets (mainly for the res (layout) folder) located as such: BuildA: src = app/src/main/java/... + res = app/src/main/res

BuildB: src = app/src/main/java/... + res = app/src/buildb/res

This used to work without any issue. Now that I switched my project to Kotlin and upgraded my gradle plugin etc... I have an error with my dataBinding. If I use buildA, everything works fine. If I switch to buildB (using build variant), the app doesn't compile and I get an error on my databinding: Unresolved reference: SplashScreenBinding

I assume that the problem comes from my source set not being recognised. In essence, this build variant is unable to locate my res folder, and hence to generate the databinding, at least that's what I get from it. Here's how my project build.gradle looks like in terms of version:

dependencies {
        classpath 'com.android.tools.build:gradle:8.1.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.21"
    }

And my gradle wrapper is:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip

Also something worth mentioning: If I remove all mention of my databinding I can compile and run the project, with the proper resources set. As soon as I use the Databinding class in it I get an error about an unresolved reference.

Any idea how can I make my sourcesets works with Kotlin? Most likely my syntax is outdated and not recognised, but I do not get any error around that. Or maybe I am missing something else?

Upvotes: 0

Views: 96

Answers (1)

Anael
Anael

Reputation: 470

Alright, after some time debugging I found out about why this was happening: In my alternative res files (xml layout), I forgot to add the tag on the top level of the xml file, preventing it from being generated. This is utterly stupid and Android needs to display a better error than this...

Upvotes: 0

Related Questions