Android Studio build error - unable to preview UI in preview window - android

Frankly speaking, I don't have the knowledge to understand and debug this error. So please inform me if I miss something.
How am I getting to this error:
I wanted to work with compose and see the preview in preview window
I created a new android studio project with empty compose activity
The build was successful but the preview isn't loading. It is just showing "build and refresh" button there.
When I click on the "build and refresh" button android studio starts the build process again and fails with the following message:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details
on seeing the logs, it still doesn't give me any concrete idea of the problem:
Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
/Users/user1/.gradle/caches/transforms-3/ece73d8c62f06068285ab9f622839930/transformed/jetified-kotlin-stdlib-jdk8-1.5.30.jar (version 1.5)
/Users/user1/.gradle/caches/transforms-3/eb2652034b57731d1f9e2d78d329ace4/transformed/jetified-kotlin-stdlib-jdk7-1.5.30.jar (version 1.5)
/Users/user1/.gradle/caches/transforms-3/201581d8ae804b86784bd93bdadbd711/transformed/jetified-kotlin-stdlib-1.6.10.jar (version 1.6)
/Users/user1/.gradle/caches/transforms-3/b9df9c1454100a3c8c23b28a1d48a919/transformed/jetified-kotlin-stdlib-common-1.6.10.jar (version 1.6)
My app level build.gradle file:
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.composebasics"
minSdk 23
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
}
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"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
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"
and my project level build.gradle file is:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
compose_version = '1.1.0'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I don't know how much and how relevant is the information above, but I can add more if required.

In project level gradle change kotlin version for compatibility with compose 1.1.0
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
Check this version compatibility

Related

I want to use LazyVerticalGrid

Wow! This is my first question in stackoverflow. And my english is not good yet.
I want to use LazyVerticalGrid. So I try to change compose_version to '1.1.1'.
e: This version (1.1.1) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.5.31 which is not known to be compatible. Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).
But I use Kotlin 1.7.0. Oh, tool is Android studio. I already checked android studio Kotlin version.
I changed
build.gradle(:app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
minSdk 30
targetSdk 32
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.6.4"
kotlinCompilerExtensionVersion '1.1.1'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation "androidx.compose.compiler:compiler:1.1.1"
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.4.1'
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"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}
build.gradle(app)
buildscript {
ext {
compose_version = '1.1.1'
kotlin_verison='1.6.4'
}
}// 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
id 'org.jetbrains.kotlin.android' version '1.5.31' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
common to all sub-projects/modules.
second error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details
some scripts told me you have to changed dependencies. but how?...
Is there a secret to adding a dependencies that fits the error?
buildscript {
ext {
compose_version = '1.1.1'
kotlin_verison='1.6.4' >>>> Typo
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
you have a typo on kotlin_version
And on the first error, it tells you to use minimum kotlin version 1.6.10.
you just need to change this line from version '1.5.31' to 1.6.10 or the newest version of it.
id 'org.jetbrains.kotlin.android' version '1.5.31' apply false

Gradle can not find firebase auth ktx library in android

As you can see below, I have encounter this error when I try to download missing files inside firebase auth.ktx library otherwise I can not reach any document written about classes, methods or properties.
Executing tasks: [DownloadSources] in project C:\Users\legol\AndroidStudioProjects\LoginSignUpCompose
Task :app:DownloadSources FAILED
1 actionable task: 1 executed
FAILURE: Build failed with an exception.
Where:
Initialization script 'C:\Users\legol\AppData\Local\Temp\ijmiscinit7.gradle' line: 25
What went wrong:
Execution failed for task ':app:DownloadSources'.
Could not resolve all files for configuration ':app:downloadSources_5a704857-f630-4789-a501-06f173a810ef'.
Could not find com.google.firebase:firebase-auth-ktx:21.0.2#aar.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-auth-ktx/21.0.2#aar/firebase-auth-ktx-21.0.2#aar.pom
- https://repo.maven.apache.org/maven2/com/google/firebase/firebase-auth-ktx/21.0.2#aar/firebase-auth-ktx-21.0.2#aar.pom
Required by:
project :app
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 1s
this is my Project built file
buildscript {
ext.kotlin_version = '1.6.0'
ext {
compose_version = '1.2.0-alpha05'
}
dependencies {
classpath 'com.google.gms:google-services:4.3.10' // Google Services plugin
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and that one is Model built file
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
id 'dagger.hilt.android.plugin'
id 'kotlin-kapt'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.loginsignupcompose"
minSdk 21
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 {
freeCompilerArgs = ['-Xjvm-default=compatibility']
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
def nav_version = "2.4.1"
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.4.1'
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"
//Hilt DI
implementation("com.google.dagger:hilt-android:2.40.4")
kapt "com.google.dagger:hilt-android-compiler:2.40.4"
//Hilt Navigation integration with compose
implementation("androidx.hilt:hilt-navigation-compose:1.0.0")
// Navigation Implementation
implementation "androidx.navigation:navigation-compose:$nav_version"
//Accompanist Permissions
implementation "com.google.accompanist:accompanist-permissions:0.24.3-alpha"
//Coil image Library
implementation "io.coil-kt:coil-compose:2.0.0-rc01"
// Material Icons
implementation "androidx.compose.material:material-icons-extended:1.2.0-alpha05"
// ViewModel Compose
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.5.0-alpha04"
// kotlin coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0"
// Source: https://github.com/Kotlin/kotlinx.coroutines/tree/master/integration/kotlinx-coroutines-play-services
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.6.0'
//implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2"
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:29.2.1')
// Declare the dependency for the Cloud Firestore library
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-firestore-ktx'
// Auth library
implementation "com.google.firebase:firebase-auth-ktx:21.0.2"
implementation "androidx.core:core-ktx:1.7.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
The correct download URL is https://maven.google.com/com/google/firebase/firebase-auth-ktx/21.0.2/firebase-auth-ktx-21.0.2.aar
I assume you are getting the wrong URLs because you missed to add the Google repository to your project. Add in your top-level build file build.gradle the following section:
allprojects {
repositories {
google()
mavenCentral()
}
}

some kotlin library attached to the project where compile with newer kotlin compiler and it can't be read... No update found

Hi here I am try a payment project using Amazon Payment Services Android SDK. Here I am successfully done the payment functionality and it's works well. After implementing into main projects I got following issue.
some kotlin library attached to the project where compile with newer kotlin compiler and it can't be read... No update found
In My Gradle
buildscript {
ext.kotlin_version = "1.6.0"
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
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
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://android-sdk.payfort.com" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
In Module
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 31
defaultConfig {
applicationId "com.android.paymentdemoapp"
minSdkVersion 23
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'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
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.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation("com.amazon:fortpayment:+:release#aar"){
transitive = true
}
}
I'm modifying the kotlin version(1.6.10 to 1.4.32) and 'build:gradle:4.1.0' to 4.1.2 clean and rebuild the project I got the following issue...
e: /Users/raja/.gradle/caches/transforms-2/files-2.1/2a57ced0732a783c670dc97c999acc46/jetified-core-ktx-1.8.0-alpha03-api.jar!/META-INF/core-ktx_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
I'm tried to configure the kotlin version and Gradle build version different way but there is no use. Anyone please help me to fix this issue. Thanks in advance.

Android Studio 4.2 error building new project [duplicate]

This question already has answers here:
Can't create new Kotlin project after updating to Android Studio 4.2
(15 answers)
Closed 1 year ago.
Seriously, everytime I update the Android Studio the huge errors came up.
it is super annoying
1.
Could not resolve all artifacts for configuration ':classpath'.
> Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0-release-764.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.5.0-release-764/kotlin-gradle-plugin-1.5.0-release-764.pom
- https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.5.0-release-764/kotlin-gradle-plugin-1.5.0-release-764.pom
Required by:
project :
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
2.in Flutter project, can not resolve constraintlayout (dependency is perfectly done)
Anyone could solve these problems?
-------UPDATE--------
this is my project and module build.gradle
have a look
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.cccc.ffffffffffff"
minSdkVersion 24
targetSdkVersion 30
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 "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.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
buildscript {
ext.kotlin_version = "1.5.0-release-764"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.0"
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
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I got this when I created the project at first time.
I think this is all because of new Android Studio version I guess.
---------SECOND UPDATE
the first error is solved
anyone knows about second error?
Try This
Can't New Project Kotlin After Update Android Studio 4.2

In Android Studio 4.0.0 Java 8+ APIs available through desugaring is not working

I downloaded Android Studio 4 and tried to test using Java 8's Streams and so on based on our application settings. Our Sdk version is 17. I updated build.gradle based on this Android Studio 4 release notes and Java 8 Support for android.
But I haven't access to Java 8 features as Stream, StreamSupport or Collections.stream().
I wonder what I am missing here.
I have created a basic project with Android Studio template. The Project's build gradle looks like this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and the modules build.gradle looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 17
compileOptions {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 17
targetSdkVersion 17
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'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.1.0'
implementation 'androidx.navigation:navigation-ui:2.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.5'
}
And this is the gradle.properties:
android.useAndroidX=true
org.gradle.jvmargs=-Xmx2048m
android.enableJetifier=true

Categories

Resources