Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"
}
like image 370
Rafael Souza Avatar asked Jul 27 '21 23:07

Rafael Souza


People also ask

What is the latest version of jetpack compose?

Today, we're releasing version 1.2 of Jetpack Compose, Android's modern, native UI toolkit, continuing to build out our roadmap.

Why jetpack compose is better than XML?

Compose allows you to do more with less code compared to XML. Compose is Intuitive. This means that you just need to tell Compose what you want to show the user. Compose is compatible with all your existing code: you can call Compose code from Views and Views from Compose.

Can I add jetpack compose to existing project?

If you want to use Jetpack Compose in an existing project, you'll need to configure your project with required settings and dependencies.

Should I migrate compose?

If you're building a new app, the best option might be to implement your entire UI with Compose. But if you're modifying an existing app, you might not want to fully migrate your app all at once. Instead, you can combine Compose with your existing UI design implementation.


2 Answers

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

like image 164
MARSK Avatar answered Oct 20 '22 08:10

MARSK


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.

like image 34
Gabriele Mariotti Avatar answered Oct 20 '22 07:10

Gabriele Mariotti