Build Gradle Errors - API data issue - Kotlin - Android - 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
}

Related

What plugin versions for Android Project are not compatible

enter image description hereHere is my build graddle for project
buildscript {
ext {
compose_ui_version = '1.2.0'
}
}// 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.7.0' apply false
}
And here is my build graddle for app
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'com.google.devtools.ksp' version '1.8.0-1.0.8'
}
android {
namespace 'com.example.assignment1'
compileSdk 33
defaultConfig {
applicationId "com.example.assignment1"
minSdk 31
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_7
targetCompatibility JavaVersion.VERSION_1_7
}
kotlinOptions {
jvmTarget = '1.7'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.2.0'
}
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'
//noinspection GradleDependency
implementation "androidx.compose.ui:ui:$compose_ui_version"
//noinspection GradleDependency
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
implementation 'androidx.compose.material:material:1.3.1'
implementation 'androidx.core:core-ktx:1.9.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
//noinspection GradleDependency
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
//noinspection GradleDependency
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
//noinspection GradleDependency
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
def nav_version = "2.5.3"
implementation "androidx.navigation:navigation-compose:$nav_version"
def room_version = "2.5.0"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
// To use Kotlin annotation processing tool (kapt)
kapt "androidx.room:room-compiler:$room_version"
// To use Kotlin Symbol Processing (KSP)
ksp "androidx.room:room-compiler:$room_version"
}
I've been trying to use Room plugin. Required parts of plugin were visible in code and I could user them. But when I try to launch the project it fails and gives the error from image. I've launched the project several times before adding new plugins, but now it's unavailable

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
}

Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: ':app:debugRuntimeClasspath'

I am trying to upgrade to compose compiler 1.3.2 by upgrading to kotlin 1.7.20 but i keep getting error saying Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
I am using android studio dolphin
If i revert my compose compiler to 1.2.0 with kotlin 1.7.0 then it works fine.
Root gradle file.
buildscript {
ext {
compose_version = '1.3.2'
}
dependencies {
classpath "com.google.dagger:hilt-android-gradle-plugin:2.42"
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
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.7.20' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App level gradle file
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'dagger.hilt.android.plugin'
id 'kotlin-kapt'
}
android {
compileSdk 33
defaultConfig {
applicationId "com.affinidi.cealcompose"
minSdk 23
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_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
namespace 'com.affinidi.cealcompose'
}
dependencies {
implementation 'androidx.core:core-ktx:1.9.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.6.0'
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"
//Splash screen
implementation 'androidx.core:core-splashscreen:1.0.0'
//Leak Canary
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
//Compose Navigation
implementation("androidx.navigation:navigation-compose:2.5.2")
//Hilt
implementation("com.google.dagger:hilt-android:2.43")
kapt("com.google.dagger:hilt-compiler:2.43")
// implementation "androidx.fragment:fragment-ktx:1.5.1"
// implementation "androidx.activity:activity-ktx:1.5.1"
//Hilt Navigation
implementation("androidx.hilt:hilt-navigation:1.0.0")
//Accompanist
implementation("com.google.accompanist:accompanist-pager:0.25.0")
implementation("com.google.accompanist:accompanist-systemuicontroller:0.25.0")
}
Not sure what is going wrong. I am using the latest libs for all dependencies and plugins but keep getting the error
Compose compiler and the other compose dependencies have different releases. Currently:
compose_compiler = '1.3.2'
compose_version = '1.2.1'
In your build gradle files you are using the same version for all of them and some of them don't exist.
You can easily use different versions in your build.gradle script.
Something like:
buildscript {
ext {
compose_compiler = '1.3.2'. //compiler
compose_version = '1.2.1'. //stable compose dependencies
compose_material3 = '1.0.0-rc01' //M3 releases
}
//...
}
Then in your app/build.gradle file
composeOptions {
kotlinCompilerExtensionVersion compose_compiler
}
dependencies {
//stable releases
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui:$compose_version"
//...other dipendencies
//material3 releases
implementation "androidx.compose.material3:material3:$compose_material3"
}

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")
}

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