Failed to resolve: androidx.compose.ui:ui-tooling and other modules - kotlin

While building gradle I encounter a warning: Failed to resolve: androidx.compose.ui:ui-tooling
and recommends adding Google maven repository but this is already specified in settings.gradle. I tried different versions for compose_ui_version and kotlin compiler extension version. How can I resolve this issue?
buildscript {
ext {
compose_ui_version = "1.4.0-alpha05"
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
}
and app's build.gradle:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.example.bettehomes'
compileSdk 33
defaultConfig {
applicationId "com.example.bettehomes"
minSdk 25
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 {
kotlinCompilerVersion "1.7.20"
kotlinCompilerExtensionVersion "1.4.0-beta05"
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
def composeBom = platform("androidx.compose.compose-bom:2022.12.00")
implementation composeBom
androidTestImplementation composeBom
implementation 'com.google.maps.android:maps-compose'
implementation 'com.google.android.gms:play-services-maps'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose'
implementation "androidx.compose.ui:ui-tooling"
implementation "androidx.compose.ui:ui-tooling-preview"
implementation 'androidx.compose.material3:material3'
// Android Studio Preview Support
debugImplementation "androidx.compose.ui:ui-tooling"
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"
debugImplementation "androidx.compose.ui:ui-test-manifest"
}

Have you tried adding the following into the buildscript section inside your project level gradle file?
repositories {
mavenCentral()
}

I was having the same problem.
Eventually I tried to add the version explicitly like this:
implementation "androidx.compose.ui:ui-tooling-preview:1.3.2"
Notice that 1.3.2 is the version imported by the BOM version you are using.
Obviously it was still not working but at least now I got a more descriptive error message.
It turned out I need compileSdkVersion 33 (I was using 31).
Since I don't want to increment yet my compileSdkVersion, I will have to downgrade ui-tooling-preview to explicitly use version 1.1.1
I can see you are already using compileSdkVersion 33, however adding explicitly the version might help you get a more descriptive error message.

Related

Duplicate Class Error in kotlin gradle implementation

I get duplicate class errors as gradle implementation app's build.gradle file. But I don't know which implementation is actually a duplicate. How can i resolve this? Is there a better way like using bom for the dependencies?
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.example.bettehomes'
compileSdk 33
defaultConfig {
applicationId "com.example.bettehomes"
minSdk 25
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}'
}
}
}
dependencies {
// Import the Compose BOM
implementation 'com.google.android.gms:play-services-maps:18.1.0'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.7.0-alpha04'
implementation "androidx.compose.ui:ui-tooling:1.3.3"
implementation "androidx.compose.ui:ui-tooling-preview:1.3.3"
implementation 'androidx.compose.material3:material3:1.1.0-alpha04'
// Android Studio Preview Support
debugImplementation "androidx.compose.ui:ui-tooling:1.3.3"
//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:1.4.0-alpha05"
debugImplementation "androidx.compose.ui:ui-test-manifest:1.3.3"
}
I had this issue today and used gradle dependencies to figure out the dependency tree
I figured out that a lib used a latest version of appcompat which used kotlin 1.8.0, a version that has this issue.
In my case the fix was to add the kotlinVersion manually:
buildscript {
ext {
buildToolsVersion = "32.0.0"
minSdkVersion = 21
compileSdkVersion = 33
targetSdkVersion = 32
androidXBrowser = "1.4.0"
kotlinVersion = "1.8.0"
}
...
}
For more information check this issue: https://github.com/proyecto26/react-native-inappbrowser/issues/398

The binary version of its metadata is 1.8.0, expected version is 1.6.0. Module was compiled with an incompatible version of Kotlin

C:/Users/LENOVO/.gradle/caches/transforms-2/files-2.1/2bcd0a6b95744b6f0ee26f9336bd22eb/jetified-annotation-jvm-1.6.0-beta01.jar!/META-INF/annotation.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.
buildscript {
ext.kotlin_version = '1.4.32'
ext.anko_version='0.10.8'
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
classpath 'com.google.gms:google-services:4.3.3'
classpath 'org.greenrobot:greendao-gradle-plugin:3.2.1'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
// Add the dependency for the Performance Monitoring plugin
classpath 'com.google.firebase:perf-plugin:1.4.1'
}
}
This project contains a few incompatible or even dangerous things, that also lead you to the problem you're having:
jcenter() is not in service anymore, so it should be replaced by mavenCentral() or your dependencies will not be correctly resolved.
You specify both Kotlin 1.4.32 (no longer maintained) and 1.6.10 (no longer ideal, but still usable) and the classes will definitely not be compatible between them.
Some of your other dependencies might be even newer and use Kotlin 1.8.0, so your older runtimes won't be able to read their metadata.
Recently, I faced a similar issue on creating a new project in Android studio with Compose Material3 template.
So I upgraded below libraries/plugins solve my issue. I also attached my gradle files for reference.
kotlin version to 1.8.0
kotlinCompilerExtensionVersion '1.4.0'
compose_version to 1.3.1
build.gradle(app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.hometech.anatomymuscles'
compileSdk 33
defaultConfig {
applicationId "com.hometech.anatomymuscles"
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_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_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.compose.material3:material3:1.1.0-alpha05'
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_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}
build.gradle(project)
buildscript {
ext {
compose_version = '1.3.3'
}
}// 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.8.0' apply false
}

import com.firebase.ui.auth.AuthUI not working

ive being trying to write a loggin with google , phone and email activity, but the app is not importing : com.firebase.ui.auth.AuthUI
this is my app build gradle
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.stockmng"
minSdk 22
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
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
implementation 'com.google.firebase:firebase-auth:21.1.0'
implementation 'com.google.firebase:firebase-firestore:24.4.1'
implementation 'com.google.firebase:firebase-database:20.1.0'
implementation 'com.firebaseui:firebase-ui-auth:6.2.1'
implementation 'com.google.firebase:firebase-core:21.1.1'
implementation 'com.google.android.gms:play-services-auth:20.4.0'
//apply plugin: 'com.android.application'
implementation 'com.github,MrNouri:DynamicSizes:1.0'
}
and my project gradle
buildscript {
repositories{
google()
mavenCentral()
gradlePluginPortal()
maven { url 'https://jitpack.io'}
}
dependencies {
classpath 'com.google.gms:google-services:4.3.14'
}
}// 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
}
i tried adding, changing updating the implentations in app build gradle,
i have permission.internet and ACCES_NETWORK_STATE added to the manifest.
a configured the api keys,and oAuth updated,
also adding in google maven and maven central in repository en the project gradel,
nothing works.

Duplicate class androidx.lifecycle.ViewModelLazy found in modules lifecycle-viewmodel-2.5.0-runtime

I'm using Android Studio Chipmunk | 2021.2.1 Patch 2.
I get the following error when I use the implementation 'androidx.appcompat:appcompat:1.5.0' version.
Duplicate class androidx.lifecycle.ViewModelLazy found in modules
lifecycle-viewmodel-2.5.0-runtime
(androidx.lifecycle:lifecycle-viewmodel:2.5.0) and
lifecycle-viewmodel-ktx-2.3.1-runtime
(androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1) Duplicate class
androidx.lifecycle.ViewTreeViewModelKt found in modules
lifecycle-viewmodel-2.5.0-runtime
(androidx.lifecycle:lifecycle-viewmodel:2.5.0) and
lifecycle-viewmodel-ktx-2.3.1-runtime
(androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1)
It works fine after rolling back to the previous implementation 'androidx.appcompat:appcompat:1.4.2' version.
build.gradle:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.halil.ozel.darkmode"
minSdk 28
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'
}
buildFeatures {
dataBinding true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
// Preference
implementation "androidx.preference:preference-ktx:1.2.0"
}
Can anyone help with similar error?
Thanks.
I had the same problem and I solved it by adding only one line of code
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
I had this problem too. Apparently it's a bug specifically for version 1.5.0 having an explicit dependency on Lifecycle 2.3.1 and a transitive dependency on Lifecycle 2.5.0 via Activity 1.5.0.
It will be fixed with 1.5.1
Here is the issue tracker reference: https://issuetracker.google.com/issues/242384116
Just roll back to 1.4.2 until it will be fixed.
In my case, solved by add this :
api "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"
source : https://issuetracker.google.com/issues/238425626
This works well for me :D
configurations {
all {
exclude group: 'androidx.lifecycle', module: 'lifecycle-runtime-ktx'
exclude group: 'androidx.lifecycle', module: 'lifecycle-viewmodel-ktx'
}
}
Finally, This problem was solved.
build.gradle(project):
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(app):
...
android {
compileSdkVersion 33
defaultConfig {
applicationId "com.halil.ozel.catchthefruits"
minSdkVersion 21
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
dataBinding true
}
}
...
implementation 'androidx.appcompat:appcompat:1.5.1'
...
For more details:
https://developer.android.com/jetpack/androidx/releases/appcompat
This bug is fixed in AppCompat 1.6.0.
(and if you need androidx.lifecycle:lifecycle-viewmodel-ktx, use 2.5.1 or above)
implementation "androidx.appcompat:appcompat:1.6.0"
The issue description is here: https://issuetracker.google.com/issues/242384116.
Issue description excerpt:
This was caused by AppCompat 1.5.0 having an explicit dependency on
Lifecycle 2.3.1 and a transitive dependency on Lifecycle 2.5.0 via
Activity 1.5.0.
Since AppCompat 1.6.0-beta01, it now depends explicitly on Lifecycle 2.5.1 so this is no longer an issue. We can backport these
bumps into an AppCompat 1.5.1 as well.
Note:
Using kotlin version '1.7.20'
This works for me ->
kotlin_version = '1.7.22
appcompat_version = "1.6.0-beta01"
lifecycle_version = "2.5.1"
I have also this implementation 'androidx.appcompat:appcompat:1.5.0' version
In my case, solved by doing this
First I updated it to version implementation 'androidx.appcompat:appcompat:1.6.0'
Also updated targetSdk and minSdk version to 33

how do i correctly implement safeargs?

I am trying to follow a tutorial in order to implement and use a room database YouTube-link.
My problem is that my gradle files look so different compared to what is shown in the video that I have no idea where to put the id "navigation.safeargs.kotlin" and the
classpath "androidx.navigation-safe-args-gradle-plugin:2.3.0-rc01"
or anything else that I might need. I have tried a bunch of places but it never works and I couldn't really find an answer, so if anyone knows, pls help me out.
build.gradle(Project:...):
plugins {
id 'com.android.application' version '7.2.0' apply false
id 'com.android.library' version '7.2.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(Module:...):
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example. ..."
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'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.exifinterface:exifinterface:1.3.3'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation fileTree(dir: "libs", include: ["*.jar"])
// Room components
implementation "androidx.room:room-runtime:2.4.2"
kapt "androidx.room:room-compiler:2.4.2"
implementation "androidx.room:room-ktx:2.4.2"
androidTestImplementation "androidx.room:room-testing:2.4.2"
// Lifecycle components
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-common-java8:2.4.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1"
// Kotlin components
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.21"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2"
}
settings.gradle(...):
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "..."
include ':app'
Go straight to the source IMO
Top-level build.gradle:
buildscript {
repositories {
google()
}
dependencies {
val nav_version = "2.4.2"
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
}
}
App/module build.gradle:
plugins {
id("androidx.navigation.safeargs")
// or for Kotlin-only projects
id("androidx.navigation.safeargs.kotlin")
}
So in your top-level file, you need google() in your repositories block, and the classpath in your dependencies block. If you don't have one of those blocks, just create it - they go inside the buildscript block, see? The nav_version val is just a variable so you can make all your Navigation components use the same version by referring to that, and the actual version number is only set in one place. You can just write the number in the dependency statement if you like - make sure all the Navigation components are using the same version though!
Stick the id("androidx.navigation.safeargs") line in your module's build file's plugins block. The order sometimes matters for some of these, so try it at the bottom. The syntax is a little different from how they look in your current file, but it's just another way of writing it - either's fine, you can mix and match
Use this one:
id 'androidx.navigation.safeargs.kotlin' version '2.4.0' apply false
In your build.gradle (project level) try adding:
plugins {
id 'com.android.application' version '7.1.3' apply false
id 'com.android.library' version '7.1.3' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
id 'androidx.navigation.safeargs.kotlin' version '2.5.1' apply false
}
and in the build.gradle (module level) add:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs.kotlin'
}