Jetpack Compose Preview not showing - android

I seem to be having trouble with Preview in compose, the layout panel doesn't appear when I annotate a compose method with #preview. I assume I'm missing a dependency, but I've copied and pasted the code from here https://developer.android.com/jetpack/compose/setup. Any suggestions? (tried the usual clear cache, reopen project etc) :)
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.0.0-alpha10'
kotlinCompilerVersion '1.4.21'
}
}
dependencies {
implementation 'androidx.compose.ui:ui:1.0.0-alpha10'
// Tooling support (Previews, etc.)
implementation 'androidx.compose.ui:ui-tooling:1.0.0-alpha10'
// Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
implementation 'androidx.compose.foundation:foundation:1.0.0-alpha10'
// Material Design
implementation 'androidx.compose.material:material:1.0.0-alpha10'
// Material design icons
implementation 'androidx.compose.material:material-icons-core:1.0.0-alpha10'
implementation 'androidx.compose.material:material-icons-extended:1.0.0-alpha10'
// Integration with observables
implementation 'androidx.compose.runtime:runtime-livedata:1.0.0-alpha10'
implementation 'androidx.compose.runtime:runtime-rxjava2:1.0.0-alpha10'
// UI Tests
androidTestImplementation 'androidx.compose.ui:ui-test-junit4:1.0.0-alpha10'
implementation 'com.google.android.material:material:1.2.1'
}
Here is my attempt at using preview (in AS it says Function "DefaultPreview" is never used)
import androidx.compose.ui.tooling.preview.Preview
.....
#Preview
#Composable
fun DefaultPreview() {
Text(text = "Hello!")
}

buildFeatures {
compose true
}
Write the above piece of code inside the Android block in the build.gradle file.
Your problem will then be solved.

For me it was some kind of mixture
Be sure you have latest Android Studio version
Within project/build.gradle be sure you have
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.20'
}
Within app/build.gradle be sure you have
android {
composeOptions {
kotlinCompilerExtensionVersion'1.1.1'
}
buildFeatures {
compose true
}
}
dependencies {
implementation("androidx.compose.ui:ui:1.1.1")
// Tooling support (Previews, etc.)
debugImplementation "androidx.compose.ui:ui-tooling:1.1.1"
implementation "androidx.compose.ui:ui-tooling-preview:1.1.1"
// Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
implementation("androidx.compose.foundation:foundation:1.1.1")
// Material Design
implementation("androidx.compose.material:material:1.1.1")
// Material design icons
implementation("androidx.compose.material:material-icons-core:1.1.1")
implementation("androidx.compose.material:material-icons-extended:1.1.1")
// Integration with observables
implementation("androidx.compose.runtime:runtime-livedata:1.1.1")
implementation("androidx.compose.runtime:runtime-rxjava2:1.1.1")
}
File -> Invalidate Ccaches and restart
Run project once
Very important:
check for correct #Preview import - should be:
import androidx.compose.ui.tooling.preview.Preview
Example:
#Composable
fun SimpleComposable() {
Text("Hello World")
}
#Preview
#Composable
fun ComposablePreview() {
SimpleComposable()
}
#Preview function should be without params.

I'm going to leave this up in case others run into the same issue as I did (it is user error, but I also think the documentation could be clearer).
There are two versions of Android Canary, beta and arctic fox (alpha). Make sure you are using arctic fox if you want to use the latest version of the compose libraries. I've found the compose library 'androidx.compose.ui:ui-tooling:1.0.0-alpha08' (and higher) doesn't work very well with the beta version of canary.

I think you can find something you want in configuration

For me, I missed one more dependency in my module's gradle
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
https://developer.android.com/jetpack/compose/tooling

Updating to the latest version of AS solved the error for me.
Try the latest version from here https://developer.android.com/studio/preview

The Jetpack Compose (rc01, rc02) has an issue with #Preview. You can solve it by adding the following code in your build.gradle file:
android {
...
}
configurations.all {
resolutionStrategy {
force("androidx.compose.ui:ui-tooling:1.0.0-beta09")
force("androidx.compose.ui:ui-tooling-data:1.0.0-beta09")
force("androidx.compose.ui:ui-tooling-preview:1.0.0-beta09")
}
}
dependencies {
...
}
Example: https://github.com/AlexZhukovich/ComposePlayground/blob/main/app/build.gradle

I had to add
debugImplementation 'androidx.customview:customview-poolingcontainer:1.0.0-rc01'
debugImplementation 'androidx.customview:customview:1.1.0'
Source

This is what worked for me add these dependencies if missed any
In the new AS compose runtime is missing and probably moved to something else and added UI tooling from the top when these were added studio started working with preview.
implementation("androidx.compose.runtime:runtime:1.2.0")
implementation("androidx.compose.ui:ui-tooling:1.2.0")
all together
implementation("androidx.activity:activity-compose:1.5.1")
implementation("androidx.compose.ui:ui:1.2.0")
implementation("androidx.compose.runtime:runtime:1.2.0")
implementation("androidx.compose.ui:ui-tooling-preview:1.2.0")
implementation("androidx.compose.ui:ui-tooling:1.2.0")

For me I just didn't have the following in my gradle file:
composeOptions {
kotlinCompilerExtensionVersion '1.0.3'
}
and
buildFeatures {
compose true
}

in project's build.gradle specify:
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30"
}

I had the same issue, and also had some compiling problems. My conclusion is that you need a good "variable versions" schema, for example is important use the same version for some dependencies, for example the Kotlin version.
I did something like this project: Jetpack Compose Navigation
where they using a global definition of version variables like this:
buildscript {
ext {
// Sdk and tools
compileSdkVersion = 33
minSdkVersion = 21
targetSdkVersion = 32
// App dependencies
appCompatVersion = '1.5.1'
activityComposeVersion = '1.6.0'
composeCompilerVersion = "1.3.0"
composeVersion = '1.2.1'
coreTestingVersion = '2.1.0'
espressoVersion = '3.4.0'
gradleVersion = '7.2.2'
kotlinVersion = '1.7.10'
ktlintVersion = '0.45.2'
ktxVersion = '1.9.0'
materialVersion = '1.6.1'
navigationComposeVersion = '2.5.2'
}
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
classpath "com.android.tools.build:gradle:$gradleVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath 'com.google.gms:google-services:4.3.14'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
}
}
And then use it in your app build.gradle too:
dependencies {
implementation project(path: ':libtoolscommon')
implementation "androidx.appcompat:appcompat:$rootProject.appCompatVersion"
implementation "androidx.core:core-ktx:$rootProject.ktxVersion"
implementation "com.google.android.material:material:$rootProject.materialVersion"
implementation 'androidx.preference:preference-ktx:1.2.0'
// Compose
implementation "androidx.compose.runtime:runtime:$rootProject.composeVersion"
implementation "androidx.compose.ui:ui:$rootProject.composeVersion"
implementation "androidx.compose.foundation:foundation:$rootProject.composeVersion"
implementation "androidx.compose.material:material:$rootProject.composeVersion"
implementation "androidx.compose.material:material-icons-extended:$rootProject.composeVersion"
implementation "androidx.activity:activity-compose:$rootProject.activityComposeVersion"
implementation "androidx.navigation:navigation-compose:$rootProject.navigationComposeVersion"
debugImplementation "androidx.compose.ui:ui-tooling:$rootProject.composeVersion"
// Testing dependencies
androidTestImplementation "androidx.arch.core:core-testing:$rootProject.coreTestingVersion"
androidTestImplementation "androidx.test.espresso:espresso-contrib:$rootProject.espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$rootProject.espressoVersion"
// Compose testing dependencies
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$rootProject.composeVersion"
debugImplementation "androidx.compose.ui:ui-test-manifest:$rootProject.composeVersion"
implementation "androidx.compose.material3:material3:1.0.0-beta03"
implementation "androidx.compose.material3:material3-window-size-class:1.0.0-beta03"
implementation 'androidx.window:window:1.1.0-alpha03'
---
}
And also try to have the last version of this libraries.
If you have a whole project in Kotlin, it should be like this:
implementation(libs.androidx.core.ktx)
implementation(libs.kotlin.stdlib)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.androidx.compose.ui.tooling.preview)
debugImplementation(libs.androidx.compose.ui.tooling)
implementation(libs.androidx.compose.materialWindow)
implementation(libs.androidx.compose.material.iconsExtended)
implementation(libs.androidx.lifecycle.runtime)
implementation(libs.androidx.lifecycle.viewModelCompose)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.window)

Expect it to show in the 'Split' or 'Design' mode after a build. (Not right over code like it seems in the tutorial.)

Related

Unable to compile jetpack compose in multi module app

I am trying to setup jetpack compose in my multi module application.But i am facing so many issues. Below is one of them.
Could not perform incremental compilation: Could not connect to Kotlin compile daemon
Could not connect to kotlin daemon. Using fallback strategy.
exception: java.io.EOFException
implementation 'androidx.activity:activity-compose:1.3.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.2.0'
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"
ext {
kotlin_version = '1.6.21'
compose_ui_version = '1.2.0'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.2.0'
}
Your versions are all pretty much out of date. Please have a look at how to set up Compose in the Quick Start page. Using composeBom (2023.01.00) will help you in making sure your versions are correct. There is also the Compose to Kotlin Compatibility Map.
In short:
composeOptions {
kotlinCompilerExtensionVersion = "1.4.0"
}
ext {
kotlin_version = '1.8.0'
compose_compiler_version = '1.4.0'
}

Upgrading compose/gradle

I copied project from GitHub and I want to modify it.
But I can't add LazyHorizontalGrid so I guess I need to update Jetpack Compose version or Gradle right?
What is proper way of doing that because if I do it with Project Structure as IDE suggest app crashes and I can't even build project.
I googled error and then next one and then next one and so on. But I think that it shouldn't be so hard to just update project.
LazyHorizontalGrid was added with 1.2.0 of the Compose Foundation dependency.
To update just change your build.gradle files.
In the root build.gradle file:
buildscript {
ext {
compose_version = '1.2.1'
}
//..
dependencies {
//...
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
}
}
In your app/build.gradle:
android {
compileSdk 33
//...
composeOptions {
kotlinCompilerExtensionVersion 1.3.1
}
}
dependencies {
implementation "androidx.compose.foundation:foundation:$compose_version"
//...all the other compose dependencies
}
Check also the compatibility map for Compose Compiler Version/Kotlin Version.

Dolphin IDE: This version (1.2.0-alpha05) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.6.21

The error goes on to say "Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!)."
It is not obvious to me how to "fix" the configuration. I added the suggested flag, but it does not resolve and fails on its own.
The IDE is Dolphin Android Studio Dolphin | 2021.3.1
The project sets the Kotlin version:
buildscript {
ext.kotlin_version = '1.6.10'
I previously set the project to use Kotlin 1.7.10 here, but downgraded in the vain hope it would solve the issue, but it does not.
I tried adding an explicit dependency on androidx.compose.compiler:compiler which appears to be silently ignored.
I do not see where Kotlin 1.6.21 and Compose Compiler 1.2.0-alpha05 are being set, as neither is set in the build files.
I'm familiar with Android, but not Compose. I am using the current stable IDE and dependency statements taken directly from the Compose documentation, and yet the project fails to build.
I suspect there is some magic combination of dependency versions needed to use Compose in Dolphin, but I have not been able to find it.
I tried Compose at v1.0 but had to back out again as there were so many issues, and it seems it is still challenging to work with, but perhaps some kind soul will point out my error and then I will happily apologise to our friends at Google. :-)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'androidx.navigation.safeargs'
apply plugin: 'com.google.firebase.crashlytics'
android {
namespace "com.blah"
compileSdk 33
defaultConfig {
applicationId "com.blah"
minSdk 21
targetSdk 33
versionCode 123
versionName "1.2.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "environment"
productFlavors {
staging {
dimension "environment"
applicationIdSuffix ".staging"
}
production {
dimension "environment"
}
}
applicationVariants.all { variant ->
variant.outputs.all { output ->
outputFileName = "MyApp-${variant.versionName}-${variant.name}.apk"
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
buildFeatures {
dataBinding true
compose true
}
lint {
disable 'RtlHardcoded'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.2'
// Android X Jetpack
implementation "androidx.appcompat:appcompat:1.5.1"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"
implementation 'androidx.core:core-ktx:1.9.0'
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation "androidx.recyclerview:recyclerview:1.2.1"
implementation "androidx.fragment:fragment-ktx:1.5.2"
implementation "androidx.collection:collection-ktx:1.2.0"
implementation "androidx.window:window:1.0.0"
// Jetpack Compose
implementation("androidx.compose.ui:ui:1.2.1")
implementation("androidx.compose.ui:ui-tooling:1.2.1")
// Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
implementation("androidx.compose.foundation:foundation:1.2.1")
implementation("androidx.compose.material:material:1.2.1")
implementation("androidx.compose.material:material-icons-core:1.2.1")
implementation("androidx.compose.material:material-icons-extended:1.2.1")
// Integration with observables
implementation("androidx.compose.runtime:runtime-livedata:1.2.1")
implementation("androidx.compose.runtime:runtime-rxjava2:1.2.1")
// Google
implementation "com.google.android.material:material:1.6.1"
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.2.0'
// Navigation Component
implementation "androidx.navigation:navigation-fragment-ktx:2.5.2"
implementation "androidx.navigation:navigation-ui-ktx:2.5.2"
// Firebase & Crashlytics
implementation "com.google.firebase:firebase-core:21.1.1"
implementation "com.google.firebase:firebase-analytics:21.1.1"
implementation "com.google.firebase:firebase-crashlytics:18.2.13"
implementation "com.google.firebase:firebase-messaging:21.0.1"
// Urban Airship push messaging
implementation "com.urbanairship.android:urbanairship-fcm:13.3.5"
// Twilio (video calling)
implementation "com.twilio:video-android-ktx:7.1.1"
implementation "com.twilio:audioswitch:1.1.4"
// ExoPlayer
implementation "com.google.android.exoplayer:exoplayer-core:2.18.1"
implementation "com.google.android.exoplayer:exoplayer-ui:2.18.1"
// Third-party
implementation "com.jakewharton.timber:timber:5.0.1"
implementation "com.jakewharton.threetenabp:threetenabp:1.4.0"
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-moshi:2.9.0"
implementation "com.squareup.picasso:picasso:2.71828"
implementation "net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.3.0"
// https://github.com/square/okhttp/blob/master/CHANGELOG.md
implementation "com.squareup.okhttp3:okhttp:4.9.3"
implementation "com.squareup.okhttp3:logging-interceptor:4.9.3"
// Open Source Licence List
implementation "com.github.franmontiel:AttributionPresenter:1.0.1"
// Shake to Send Feedback
implementation "com.linkedin.shaky:shaky:3.0.4"
implementation "com.jraska:falcon:2.2.0"
// Page Indicator View
implementation 'com.github.romandanylyk:PageIndicatorView:v.1.0.3'
// Testing
implementation "androidx.legacy:legacy-support-v4:1.0.0"
testImplementation "junit:junit:4.13.2"
testImplementation "androidx.test:core:1.4.0"
testImplementation "org.mockito:mockito-core:4.6.0"
androidTestImplementation "androidx.test:runner:1.4.0"
androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0"
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.2.1")
apply plugin: 'com.google.gms.google-services'
}
Module build file:
apply plugin: "com.github.ben-manes.versions"
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.5.2"
classpath "com.google.firebase:firebase-crashlytics-gradle:2.9.2"
classpath "com.google.gms:google-services:4.3.14"
classpath "com.github.ben-manes:gradle-versions-plugin:0.42.0"
}
}
allprojects {
repositories {
google()
maven { url "https://jitpack.io" }
mavenCentral()
jcenter() {
content {
includeModule("com.google.android", "flexbox")
}
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
In your app/build.gradle file in the android block add:
android {
//..
composeOptions {
kotlinCompilerExtensionVersion "1.3.1"
}
}
According to the compatibility map use kotlin 1.7.10

Problem with updating compose version to 1.3.0-alpha01

I have an Android Studio project that works fine when I'm using Kotlin version 1.6.21 and compose version 1.2.0-rc01. The problem arises when I want to update both dependencies to the latest versions, which are 1.7.10 for Kotlin and 1.3.0-alpha01 for compose. The error that I get is:
Could not resolve all files for configuration ':app:kotlin-extension'.
Could not find androidx.compose.compiler:compiler:1.3.0-alpha01.
Searched in the following locations:
https://dl.google.com/dl/android/maven2/androidx/compose/compiler/compiler/1.3.0-alpha01/compiler-1.3.0-alpha01.pom
https://repo.maven.apache.org/maven2/androidx/compose/compiler/compiler/1.3.0-alpha01/compiler-1.3.0-alpha01.pom
Required by:
project :app
Any help?
Edit:
Now I'm using these versions:
kotlinCompilerExtensionVersion '1.7.10'
implementation "androidx.compose.ui:ui:1.3.0-alpha01"
implementation "androidx.compose.material:material:1.3.0-alpha01"
implementation "androidx.compose.compiler:compiler:1.2.0"
Compose compiler and the other compose dependencies have different releases.
Currently the latest version of compose.compiler is 1.3.1.
You easily use different versions in your build.gradle script:
buildscript {
ext {
compose_compiler = '1.3.1'. //compiler
compose_version = '1.2.0'. //stable compose dependencies
compose_alpha = '1.3.0-alpha01' //alpha releases
}
//...
}
And then:
composeOptions {
kotlinCompilerExtensionVersion compose_compiler
}
dependencies {
//stable releases
implementation "androidx.compose.material:material:$compose_version"
//alpha releases
implementation "androidx.compose.ui:ui:$compose_alpha"
implementation "androidx.compose.material3:material3:$compose_alpha"
}
An alternate Compose compiler version can be defined with composeOptions:
android {
composeOptions {
kotlinCompilerExtensionVersion "1.2.0"
}
}
There's no need to add it as an implementation, which it definitely isn't.
runtimeOnly might eventually work, but it won't make it into the package.
There is a compatibility map for "Compose Compiler Version" compatible with "Compatible Kotlin Version" it can be found here:
so if you want to update to today's latest compose you specify:
...
composeOptions {
kotlinCompilerExtensionVersion "1.3.0"
}
...
and then in the map you find the compatible kotlin version which is 1.7.10
and set that in the other gradle file:
plugins {
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
...
}
I am using compose_version is 1.3.0-beta01 which is working fine for me. You may use like below:
Step1: Project build.gadle is look like below:
build script {
ext {
compose_version = '1.3.0-beta01'
}
}
plugins {
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}
Step2: module build.gadle looks like
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.5.21'
}

Failed to resolve variable '${animal.sniffer.version}' when migrate to AndroidX

I'm using Android Studio 3.2 Beta5 to migrate my project to AndroidX. When I rebuild my app I got these errors:
ERROR: [TAG] Failed to resolve variable '${animal.sniffer.version}'
ERROR: [TAG] Failed to resolve variable '${junit.version}'
Full clean & rebuild did not work! Anyone know how to fix this?
gradle.properties
android.enableJetifier=true
android.useAndroidX=true
build.gradle
buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-beta05'
classpath 'com.google.gms:google-services:4.0.1'
classpath "io.realm:realm-gradle-plugin:5.3.1"
classpath 'io.fabric.tools:gradle:1.25.4'
classpath 'com.google.firebase:firebase-plugins:1.1.5'
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app/build.gradle
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'io.fabric'
apply plugin: 'com.google.firebase.firebase-perf'
android {
compileSdkVersion 28
buildToolsVersion "28.0.0"
defaultConfig {
applicationId "com.iceteaviet.fastfoodfinder"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
}
}
aaptOptions {
cruncherEnabled = false
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
implementation 'com.jakewharton:butterknife:9.0.0-SNAPSHOT'
implementation 'androidx.appcompat:appcompat:1.0.0-rc01'
implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-rc01'
implementation 'androidx.cardview:cardview:1.0.0-rc01'
implementation 'com.google.maps.android:android-maps-utils:0.5'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.github.bumptech.glide:glide:4.7.1'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'org.greenrobot:eventbus:3.1.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'io.realm:realm-android-library:5.3.1'
implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'io.reactivex.rxjava2:rxjava:2.0.2'
implementation 'androidx.multidex:multidex:2.0.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.4'
implementation 'com.google.firebase:firebase-perf:16.0.0'
implementation 'com.jakewharton.timber:timber:4.7.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
}
apply plugin: 'com.google.gms.google-services'
I fix this with two steps
1) File -> Invalidate Caches / restart...
2) Build -> Clean project
I got the same error after updating my build.gradle file with AndroidX Test dependencies. Turns out I forgot to remove the old junit dependency. So for me, the fix was simply to remove the following dependency:
dependencies {
...
testImplementation 'junit:junit:4.12'
}
Adding Java 8 support to build.gradle file fixed issue for me
android {
...
//Add the following configuration in order to target Java 8.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
It seems to be Glide the problem.
I had the same error and I just updated the Glide's dependencies to 4.8 and there is no build errors.
Kotlin :
// Glide
def glide_version = "4.8.0"
implementation "com.github.bumptech.glide:glide:$glide_version"
kapt "com.github.bumptech.glide:compiler:$glide_version"
Java :
// Glide
def glide_version = "4.8.0"
implementation "com.github.bumptech.glide:glide:$glide_version"
annotationProcessor "com.github.bumptech.glide:compiler:$glide_version"
Be sure to have enabled in your gradle.properties :
android.useAndroidX=true
android.enableJetifier=true
Source : https://github.com/bumptech/glide/issues/3124
Hope this will help you!
Fixed it by going to the main directory and typing flutter clean
Removing the testInstrumentationRunner worked for me:
defaultConfig {
...
...
// testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
If you're using Kotlin, the issue will popup if don't use the kapt version for any annotation processor you use in the project.
As #Vince mentioned the case with Glide, this could happen with Dagger2, Butterknife, etc.
If you're using both Java and Kotlin you'll need to keep both dependencies, as follows (were $glideVersion is a predefined version of Glide):
implementation "com.github.bumptech.glide:glide:$glideVersion"
kapt "com.github.bumptech.glide:compiler:$glideVersion"
If you're on a Kotlin only project, the kapt dependency should work alone.
EDIT
Another thing you should have in mind is if you're already using Androidx. Androidx is a great refactor but when migrating it can cause some of your dependencies to collapse. Mainstream libraries are already updated to Androidx, however, some of them are not and even won't.
If the issue doesn't go away with my provided solution above this edit, you can take a look at your dependencies and make sure they use Androidx as well.
EDIT 2
As #Ted mentioned, I researched back and he's right kapt does handle java files as well. kapt alone will do the trick, no need to keep both kapt and annotationProcessor dependencies.
Try removing this line:
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
from the buildscript / repositories section of your build.gradle file.
When I added that line, I got the error you described. When I removed it, no longer. That line should only be in the allprojects / repositories section.
Try set android.enableJetifier=false in gradle.properties. Then Invalidate Caches / Restart ... in Android Studio
The fix is in 4.2.0, use the higher version of google gms jar.
Try changing:
classpath 'com.google.gms:google-services:4.0.1'
by this version:
classpath 'com.google.gms:google-services:4.2.0'
Hope this works...
If you are using dagger or butterknife, please make sure to update it to the latest version. Or, if you have another injection library used in your project, you can try to check it if it support androidx or no.
I've found same error, the problem is on my dagger and butterknife. Have fixed it by updating it to newest version.
Android version: 4.10.2
I solved this issue with three simple steps:
First i added below this in pubspec.yml:
(with two spaces of identation)
module:
androidX: true
Adding this two lines below in gradle.properties, i have this in android/gradle.properties, in the project folder.
android.useAndroidX=true
android.enableJetifier=true
And after this i wrote with the terminal:
flutter clean
Maybe you will have to stop the device and run again.
I fixed this by updating the firebase dependencies to the latest.
I faced this error after adding butterknife to my project.
In order to resolve this error you should use Java8.
I would recommend this answer.
How I resolved it:
1.add following code in build.gradle (module: app)
android {
...
// Configure only for each module that uses Java 8
// language features (either in its source code or
// through dependencies).
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
clean prject and run.
I fixed it by refreshing the cahche (Instead of invalidating it - which also clears the local history):
in gradle.properties file, comment the line org.gradle.caching=true.
Clean, Rebuild.
in gradle.properties file, un-comment the line
org.gradle.caching=true.
Clean, Rebuild.
Thats it!
Go to file and click on Invalidate caches and restart.
After it restarts then you increase the minimum SDK version in your app's build.gradle file.

Categories

Resources