Error message; Cannot access class 'androidx.compose.ui.Alignment.Horizontal'. Check your module classpath for missing or conflicting dependencies - android

I am making a QR Code Scanner app using Jetpack compose. But when I am trying to use Column, the composable function then the compiler is giving me this error:
Cannot access class 'androidx.compose.ui.Alignment.Horizontal'. Check your module classpath for missing or conflicting dependencies
Here is my app build.gradle module for the app:
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.plcoding.qrcodescannercompose"
minSdk 26
targetSdk 31
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'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.5.21'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation "androidx.compose.ui:ui:$compose_version"
// Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
implementation("androidx.compose.foundation:foundation:1.0.5")
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
implementation 'androidx.activity:activity-compose:1.4.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"
// Activity Compose
implementation "androidx.activity:activity-compose:1.4.0"
// CameraX
implementation "androidx.camera:camera-camera2:1.0.2"
implementation "androidx.camera:camera-lifecycle:1.0.2"
implementation "androidx.camera:camera-view:1.1.0-beta01"
// Zxing
implementation 'com.google.zxing:core:3.3.3'
}
Update: This is the code that is generating the error:
I don't know what this error message is saying and how to resolve this?

Make sure to upgrade your version of Compose to the latest stable version which is 1.1.0-rc03
If your project consists of multiple modules, make sure that all of them are using the same version of Compose.

Related

How to update Jetpack Compose version in a project?

I want to update dependencies to latest version of Jetpack Compose. I tried to change version texts in gradle files but build error. Also I can't find what is the latest version of Jetpack Compose.
build.gradle (Project)
buildscript {
ext {
compose_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.1' apply false
id 'com.android.library' version '7.4.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
}
build.gradle (Module:app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.example.android'
compileSdk 33
defaultConfig {
applicationId "com.example.android"
minSdk 24
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.2.0'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.compose.material3:material3:1.0.0-alpha11'
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"
}
I tried and searched on internet for two days but always build error.I'm very noob at this jobs, so it didn't work.
Jetpack compose has switched to using a bill of materials (BOM) to combine compatible library versions.
Check out the documentation:
dependencies {
// Import the Compose BOM
implementation platform('androidx.compose:compose-bom:2023.01.00')
// Import other Compose libraries without version numbers
implementation 'androidx.compose.foundation:foundation'
}
You can find the latest BOM version here.
If you are still getting build errors then you most likely need to update your kotlin plugin version.

Animations in Compose not working after dependency updates

After updating Compose to be able to use Modifier.blur, I got errors which were resolved after updating other dependencies. But now two animations I use (AnimateDpAsState and AnimatedVisibility) does not work.
I get the following error while building in release mode and it still builds successfully. No errors on debug mode.
lifecycle-runtime-ktx_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
I am pretty sure the problem lies in the gradle files so please take a look.
module build.grade
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.dagger.hilt.android'
id "org.jetbrains.kotlin.kapt"
}
android {
namespace 'com.example.app'
compileSdk 33
defaultConfig {
applicationId "com.example.app"
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.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'
implementation "androidx.compose.ui:ui:$compose_ui_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
implementation 'androidx.compose.material:material:1.3.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
// Compose
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.0-alpha05"
implementation "androidx.navigation:navigation-compose:2.6.0-alpha04"
implementation "androidx.compose.material:material-icons-extended:1.3.1"
implementation "androidx.hilt:hilt-navigation-compose:1.1.0-alpha01"
//Dagger - Hilt
implementation 'com.google.dagger:hilt-android:2.44.2'
kapt 'com.google.dagger:hilt-android-compiler:2.44.2'
// Room
implementation "androidx.room:room-runtime:2.5.0"
kapt "androidx.room:room-compiler:2.5.0"
// Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
// Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:2.5.0"
}
project build.gradle
buildscript {
ext {
compose_ui_version = '1.3.3'
}
}
plugins {
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.4.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
id 'com.google.dagger.hilt.android' version '2.44.2' apply false
id "org.jetbrains.kotlin.kapt" version "1.8.0" apply false
}
I updated dependencies highlighted by Android Studio and Compose and was expecting it to work as it was with the new versions. No extra dependencies were added nor was the code modified.

Glide error adding glide's dependency to project : could not resolve all files for configuration 'app:debugRuntimeClasspath'

I want to use Glide library in my project but after adding glide's dependencies i got this error when i run the app and gradle offline mode is off :
error image
and this is my app build.geadle :
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
}
android {
namespace 'com.example.tempapplication'
compileSdk 32
defaultConfig {
applicationId "com.example.tempapplication"
minSdk 26
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
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
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'
implementation 'com.github.bumptech.glide:glide:4.14.2'
kapt 'com.github.bumptech.glide:compiler:4.14.2'
}
when i remove the glide's dependencies it work properly.
The problem was my vpn and Gradle could not download dependencies.
if it occur to you check that you connection is available or not.

How to downgrade Api Level (32 -> 28) Android?

I've benn programming my school proyect for several months and now im done. I used to compile my app directly to my phone (Android 12) but I need it to be at least API 28. I tried to change the Build Gradle target version from 31 to 28 but I'm having errors with the dependencies versions.
There is any safe and quick way to know which version exactly I need for each dependency?
Im currently using theese.
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
//Hilt
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.kdapp.estudiapp"
minSdk 24
targetSdk 31
versionCode 1
versionName "1.1"
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}'
}
}
}
apply plugin: 'com.google.gms.google-services'
dependencies {
implementation 'androidx.core:core-ktx:1.7.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.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation 'com.google.firebase:firebase-auth-ktx:21.0.6'
implementation 'com.google.firebase:firebase-firestore-ktx:24.2.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"
//Firebase
implementation platform('com.google.firebase:firebase-bom:30.2.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-auth:21.0.6'
implementation 'com.google.android.gms:play-services-auth:20.2.0'
//Firebase -> Storage
implementation 'com.google.firebase:firebase-storage'
//Navigation
implementation 'androidx.navigation:navigation-compose:2.5.0'
// Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.3.5"
// Hilt DI
def hilt_lifecycle_viewmodel = "1.0.0-alpha03"
def hilt_navigation = "1.0.0-alpha03"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hilt_lifecycle_viewmodel"
implementation "androidx.hilt:hilt-navigation-compose:$hilt_navigation"
//GSON
implementation 'com.google.code.gson:gsoenter code heren:2.9.0'
}
Any external dependencies require version checks specified on their official GitHub repo, or their website, if it isn't open-source. Now, as of a quick way to downgrade minSdk, just press Ctrl+Alt+Shift+S within Android Studio, and it'll open the project structure dialog. Find a field that says minSdk, and set it to whatever you require. I recommend setting the targetSdk and compileSdk to the maximum value available, they won't affect your app's deployment on lower api devices. There's also a suggestions pane in the dialog, which can help you update dependency versions studio deems to be out-dated. After having set everything, click Apply/Ok.

building AAR in Android Studio

It's my first time building AAR
The official site says that All I hate to do is build APK and AAR will be assembled
Here's the quote:
But when I choose "Build Apk(s)" nothing happens.
Another tutorial says I have to choose Gradle-> library name -> tasks-> build-> :assembleRelease.
But there is no such thing :
How can I assemble library as AAR?
here's my gradle :
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'kotlin-kapt'
}
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
minSdkVersion 17
targetSdkVersion 29
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 "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
def room_version = "2.2.3"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:$room_version"
implementation "androidx.room:room-rxjava2:$room_version"
implementation 'com.google.code.gson:gson:2.8.2'
}
Just click assemble or add buildTypes.debug. While you don't have buildTypes.debug defined, it won't generate the tasks you are looking for (as there only is one configuration present there and so there is nothing to tell apart).

Categories

Resources