androidsharedpreferencesprotocol-buffersdatastoreandroid-jetpack-datastore

Android Proto Datastore: Could not get unknown property 'source' for generate-proto-generateProductionDebugProto of type ...DefaultSourceDirectorySet


As per Proto DataStore codelab get exception while building the project

Android studio giraffe 2022.3.1

FAILURE: Build failed with an exception.

Could not get unknown property 'source' for generate-proto-generateProductionDebugProto of type org.gradle.api.internal.file.DefaultSourceDirectorySet.


Solution

  • update to the following code

    plugins {
       ...
       id "com.google.protobuf" version "0.9.4"
    }
    

    And dependencies

    dependencies {
        ...
        implementation  "androidx.datastore:datastore:1.0.0"
        implementation  "com.google.protobuf:protobuf-javalite:3.18.0"
    }
    

    And

    protobuf {
        protoc {
            artifact = 'com.google.protobuf:protoc:3.8.0'
        }
        generateProtoTasks {
            all().configureEach { task ->
                task.builtins {
                    java {
                        option "lite"
                    }
                }
            }
        }
    }