Android Could not find method protobuf() for arguments - android

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'
}

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

Related

How to use Hilt in Jetpack Compose?

I'm trying to create a school project with Jetpack Compose and I try to use Hilt. These are the dependencies I'm using:
dependencies {
implementation platform("androidx.compose:compose-bom:2023.01.00")
implementation "androidx.compose.material:material"
implementation "com.google.dagger:hilt-android:2.45"
kapt "com.google.dagger:hilt-android-compiler:2.45"
}
But when I try to compile the app I get:
Unresolved reference: compose
I read here, that I should implement androidx.hilt:hilt-navigation-compose why? I'm not using any navigation. It's a simple app with one activity that contains a LazyColumn with three names. How to solve that?
Make sure that your added these dependencies in your app level build.gradle file:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.dagger.hilt.android'
id 'kotlin-kapt'
}
android {
namespace 'garousi.dev.stackoverflow'
compileSdk 33
defaultConfig {
applicationId "garousi.dev.stackoverflow"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.4.2'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.6.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
def composeBom = platform('androidx.compose:compose-bom:2023.01.00')
implementation composeBom
androidTestImplementation composeBom
implementation "androidx.compose.ui:ui"
implementation "androidx.compose.ui:ui-tooling-preview"
implementation 'androidx.compose.material:material'
debugImplementation "androidx.compose.ui:ui-tooling"
androidTestImplementation "androidx.compose.ui:ui-test-junit4"
debugImplementation "androidx.compose.ui:ui-test-manifest"
implementation 'com.google.dagger:hilt-android:2.45'
kapt 'com.google.dagger:hilt-compiler:2.45'
implementation "androidx.navigation:navigation-compose:2.5.3"
}
kapt {
correctErrorTypes true
}
your project level build.gradle file:
buildscript {
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.0' apply false
id 'com.android.library' version '7.4.0' apply false
id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
id 'com.google.dagger.hilt.android' version '2.45' apply false
}

where to write the Navigation Component safeArgs dependencies in gradle

I started to learn navigation component library but I cannot figure out where to add the safeargs dependencies. I should add these dependencies in https://developer.android.com/jetpack/androidx/releases/navigation. I tried many scenarios but none of them worked.here is my app gradle file:
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.yusufemirbektas.bottomnavfrags"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildscript {
repositories {
google()
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
}
dependencies {
def nav_version = "2.5.2"
// Java language implementation
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
// Testing Navigation
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
// Jetpack Compose Integration
implementation "androidx.navigation:navigation-compose:$nav_version"
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
and here is my project gradle file:
// Top-level build file where you can add configuration options common to all sub-
projects/modules.
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
In your project level build.gradle file:
buildscript {
...
dependencies {
...
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
}
}
And then your app build.gradle file:
plugins {
...
id("androidx.navigation.safeargs.kotlin")
}
...
dependencies {
...
// ... Navigation
implementation("androidx.navigation:navigation-fragment-ktx:$nav_version")
implementation("androidx.navigation:navigation-ui-ktx:$nav_version")
}

Build Gradle Errors - API data issue - Kotlin - Android

Please help!
defaultConfig, buildTypes, and composeOptions are throwing these errors:
public open val defaultConfig: [Error type: Unresolved type for DefaultConfig]
public open val buildTypes: [Error type: Unresolved type for NamedDomainObjectContainer ]<[Error type: Unresolved type for
BuildType]>
public open val composeOptions: [Error type: Unresolved type for ComposeOptions]
I upgraded from android chipmunk to dolphin and I noticed this. I am not getting any errors in my application but it takes forever for the api data to load. It wasn't doing this before.
Also, in the Logcat this warning is thrown repeatedly until the api data is loaded.
-> presentDisplay display has no layers to compose, flushing client target buffer.
I have tried to find info on this, but nothing I have found has helped my situation. Any help or advice you may have is welcomed and appreciated.
Module build.gradle:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
android {
compileSdk 33
defaultConfig {
applicationId "com.samm.brewerysearch"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
namespace 'com.samm.brewerysearch'
}
dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.5.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
implementation 'com.google.android.material:material:1.6.1'
//Navigation
implementation "androidx.hilt:hilt-navigation-compose:1.0.0"
// retrofit
implementation "com.squareup.retrofit2:retrofit:2.9.0"
// GSON
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
// coroutine
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
// hilt
implementation "com.google.dagger:hilt-android:2.42"
kapt "com.google.dagger:hilt-compiler:2.42"
}
Project build.gradle:
buildscript {
ext {
compose_version = '1.2.0-beta01'
}
dependencies {
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.42'
classpath 'com.android.tools.build:gradle:7.3.0'
}
}
plugins {
id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
id 'com.google.dagger.hilt.android' version '2.41' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}

android - Failed to add navigation dependency

I am trying to add navigation library in android studio but fails to add here is my build.gradle(app)
plugins {
id 'com.android.application'
}
android {
compileSdk 33
defaultConfig {
applicationId "com.example.practice_8"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
implementation 'androidx.navigation:navigation-fragment:2.5.1'
implementation 'androidx.navigation:navigation-ui:2.5.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Try this
In your app/gradle, add
plugins {
id 'com.android.application'
id 'androidx.navigation.safeargs'
}
def nav_version = "2.5.1"
inside dependency{ } add
// Kotlin
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
in project/gradle add
buildscript {
repositories {
google()
}
dependencies {
def nav_version = "2.5.1"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
}
and sync your gradle
Here is reference
Android Nav

Databinding in recyclerview using kotlin causing issue

Here is my app-level gradle file
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.app.myapplication"
minSdkVersion 19
targetSdkVersion 31
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
dataBinding = true
}
}
kapt {
generateStubs = true
correctErrorTypes = true
}
sourceSets {
main {
java {
srcDir "${buildDir}/generated/source/kapt/main"
}
}
test {
java {
srcDir 'src/test/java'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
kapt "com.android.databinding:compiler:3.2.0-alpha10"
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.8.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'
//glide
implementation 'com.github.bumptech.glide:glide:4.11.0'
kapt 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation 'android.arch.paging:runtime:1.0.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
this is my main gradle file
buildscript {
ext.kotlin_version = "1.4.10"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
I am trying to implement databinding in recyclerview using kotlin. But it is giving me runtime error
Execution failed for task ':app:kaptDebugKotlin'.
A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
java.lang.reflect.InvocationTargetException (no error message)
Anyone has faced the same error? I have searched and gone through many links related to this error but all states the use of room library which I am not using and still getting this error.
Any help is much appreicated.
Thanks
Instead of
buildFeatures {
dataBinding = true
}
Try this
buildFeatures {
dataBinding true //<--- for binding the data
viewBinding true //<-- for binding the view
}
I solved this error after updating my
Android studio to
Android Studio Arctic Fox 2020.3.1 Patch 3
and also updated
gradle version to 7.0.3
and
kotlin plugin update to 1.5.20.
Basically I updated all my resources and the error was solved.
Updated gradle files
app-level gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.app.navigationdemoapp"
minSdkVersion 19
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "androidx.navigation:navigation-fragment-ktx:2.4.0-beta02"
implementation "androidx.navigation:navigation-ui-ktx:2.4.0-beta02"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
project level gradle
buildscript {
ext.kotlin_version = "1.5.20"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Categories

Resources