Rafael Souza
Rafael Souza

Reputation: 1351

Error migrating to new jetpack compose version

I'm trying to update my app to a new compose version but it gave me an error that I don't know how to fix. when I run the error persists in my run. my old project works normally but mine what I want is to change versions follow my error if anyone can help me i would appreciate it a lot

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.quitanda, PID: 10390
    java.lang.AbstractMethodError: abstract method "void androidx.lifecycle.DefaultLifecycleObserver.onCreate(androidx.lifecycle.LifecycleOwner)"
        at androidx.lifecycle.FullLifecycleObserverAdapter.onStateChanged(FullLifecycleObserverAdapter.java:36)
        at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
        at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:196)
        at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.android.kt:808)
        at android.view.View.dispatchAttachedToWindow(View.java:18355)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3399)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3406)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3406)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3406)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3406)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1796)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1494)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7288)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
        at android.view.Choreographer.doCallbacks(Choreographer.java:761)
        at android.view.Choreographer.doFrame(Choreographer.java:696)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6923)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)

build.gradle(Project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

task clean(type: Delete) {
    delete rootProject.buildDir
}

buildscript {
    ext {
        compose_version = '1.0.0-rc01'
    }
}

build.gradle(Module)

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

apply plugin:'kotlin-parcelize'

android {
    compileSdk 30

    defaultConfig {
        applicationId "com.example.quitanda"
        minSdk 21
        targetSdk 30
        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
    }
}

dependencies {
    def appcompat_version = "1.3.0"

    implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-alpha02'

    implementation 'androidx.core:core-ktx:1.6.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.0-rc01'

    implementation "androidx.appcompat:appcompat:$appcompat_version"
    // For loading and tinting drawables on older versions of the platform
    implementation "androidx.appcompat:appcompat-resources:$appcompat_version"

    testImplementation 'junit:junit:4.+'
    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"


   // implementation "com.google.accompanist:accompanist-coil:0.7.1"
    implementation "io.coil-kt:coil-compose:1.3.0"
    implementation "androidx.navigation:navigation-compose:2.4.0-alpha05"
    implementation "com.google.accompanist:accompanist-swiperefresh:0.8.0"
    implementation "com.google.accompanist:accompanist-pager:0.8.1"

    implementation "com.squareup.retrofit2:retrofit:2.9.0"
    implementation "com.squareup.retrofit2:converter-moshi:2.9.0"
    implementation "androidx.paging:paging-compose:1.0.0-alpha08"
}

Upvotes: 5

Views: 1206

Answers (2)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 365038

As described in the documentation:

If you are using Android Studio Bumblebee Canary 4 or AGP 7.1.0-alpha04/7.1.0-alpha05, you may hit the following crash:

  java.lang.AbstractMethodError: abstract method "void androidx.lifecycle.DefaultLifecycleObserver.onCreate(androidx.lifecycle.LifecycleOwner)"

To fix, temporarily increase your minSdkVersion to 24+ in your build.gradle file. This issue will be fixed in the next version of Android Studio Bumblebee and AGP 7.1.

Upvotes: 3

Richard Onslow Roper
Richard Onslow Roper

Reputation: 6863

It is an error with the AGP. Change the minSDKVersion to 24 for now

Upvotes: 5

Related Questions