OiO.lk Blog Android Proto DataStore Fails to Generate Files Due to AndroidSourceSet Conflict in Gradle
Android

Proto DataStore Fails to Generate Files Due to AndroidSourceSet Conflict in Gradle


I’m trying to implement Proto DataStore in my Android project, but the library fails to generate any files from the .proto file and throws the following exception:

A problem occurred configuring project ':core:datastoreproto'.> org.gradle.api.InvalidUserDataException: Cannot add an AndroidSourceSet with name 'debug' as an AndroidSourceSet with that name already exists.

You can see below how I implemented it

versions

dataStore = "1.1.1"
protobuf = "4.26.1"
protobufPlugin = "0.9.4"

Below is my build.gradle.kts file for the :core:datastoreproto module:

plugins {
    alias(libs.plugins.medicineai.android.library)
    alias(libs.plugins.jetbrains.kotlin.android)
    alias(libs.plugins.protobuf)
}

android {
    namespace = "com.medicineai.core.datastoreproto"
}

// Setup protobuf configuration, generating lite Java and Kotlin classes
protobuf {
    protoc {
        artifact = libs.protobuf.protoc.get().toString()
    }
    generateProtoTasks {
        all().forEach { task ->
            task.builtins {
                register("java") {
                    option("lite")
                }
                register("kotlin") {
                    option("lite")
                }
            }
        }
    }
}

androidComponents.beforeVariants {
    android.sourceSets.register(it.name) {
        val buildDir = layout.buildDirectory.get().asFile
        java.srcDir(buildDir.resolve("generated/source/proto/${it.name}/java"))
        kotlin.srcDir(buildDir.resolve("generated/source/proto/${it.name}/kotlin"))
    }
}

dependencies {
    api(libs.protobuf.kotlin.lite)
}

Here’s my .proto file (auth_info.proto):

syntax = "proto3";

option java_package = "com.medicineai.core.datastoreproto";

message AuthInfo {
  string accessToken = 1;
  string refreshToken = 2;
  string userId = 3;
}

I’m not sure what is causing the AndroidSourceSet conflict. Has anyone else faced this issue or found a solution?

This may help also



You need to sign in to view this answers

Exit mobile version