Reputation: 543
I am adding plugin & dependency for protobuf but getting this error on gradle sync.
Note: Protobuf classpath is added in project level build.gradle file
Could not find method protobuf() for arguments [build_8w4hvjkk8z81pgbpl03zqpq9b$_run_closure2@373b3e24] on project ':grpc'
module level -> build.gradle
apply plugin: 'com.android.dynamic-feature'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.protobuf'
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileSdkVersion project.ext.compile_sdk_version
defaultConfig {
minSdkVersion project.ext.min_sdk_version
targetSdkVersion project.ext.target_sdk_version
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
debuggable false
minifyEnabled false
useProguard false
proguardFile 'proguard-rules.pro'
}
}
configurations {
implementation.exclude module:'protobuf-lite'
}
}
protobuf {
protoc { artifact = 'com.google.protobuf:protoc:3.12.0' }
plugins {
grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.36.0'
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
java { option 'lite' }
}
task.plugins {
grpc {
option 'lite' }
}
}
}
}
dependencies {
implementation project(":app")
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.annotation:annotation:1.1.0'
implementation 'io.grpc:grpc-okhttp:1.36.0'
implementation 'io.grpc:grpc-protobuf-lite:1.36.0'
implementation 'io.grpc:grpc-stub:1.36.0'
}
Upvotes: 1
Views: 4691
Reputation: 48
You show only your app build.gradle. In you project build.gradle you must add
dependencies { .... classpath "com.google.protobuf:protobuf-gradle-plugin:" }
ref: https://grpc.io/blog/kotlin-gradle-projects
Upvotes: 1