androidandroid-coordinatorlayoutandroid-collapsingtoolbarlayout

CollapsingToolbarLayout get crash on android 5.0 (Lollipop)


My application crash in this xml, What is wrong?

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        app:liftOnScroll="true"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentScrim="@android:color/holo_purple"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/expandedImage"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:scaleType="centerCrop"
                android:src="@drawable/mindorks_logo"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.7" />

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:title="Hello World" />

        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerLessons"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>


</androidx.coordinatorlayout.widget.CoordinatorLayout>

And it is my gradle:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-kapt'
    id 'kotlin-android'
    id 'kotlin-parcelize'
    id("dagger.hilt.android.plugin")
    id 'com.google.dagger.hilt.android'
}

android {
    compileSdk 33

    defaultConfig {
        applicationId "ir.mou.languageteaching"
        minSdk 21
        targetSdk 33
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
        multiDexEnabled true
        buildConfigField("String", "wstoken", wstoken)
        buildConfigField("String", "wsfunction", wsfunction)
        buildConfigField("String", "moodlewsrestformat", moodlewsrestformat)
        buildConfigField("String", "service", service)
    }

    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
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
    namespace 'ir.mou.languageteaching'
}

ext {
    lifecycle_version = "2.6.0-alpha03"
    nav_version = "2.5.3"
    paging_version = "3.1.1"
    roomVersion = "2.5.0-beta02"
    work_version = "2.7.1"
}

dependencies {

    ///Compose///
    implementation 'androidx.core:core-ktx:1.9.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.0-alpha03'

    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
    implementation 'com.google.android.material:material:1.7.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'

//    Futures
    implementation("androidx.concurrent:concurrent-futures-ktx:1.1.0")

//    Lifecycle components
    // ViewModel
    implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:${lifecycle_version}")

    // LiveData
    implementation("androidx.lifecycle:lifecycle-livedata-ktx:${lifecycle_version}")
    // Lifecycles only (without ViewModel or LiveData)
    implementation("androidx.lifecycle:lifecycle-runtime-ktx:${lifecycle_version}")

    // Saved state module for ViewModel
    implementation("androidx.lifecycle:lifecycle-viewmodel-savedstate:${lifecycle_version}")

    // optional - helpers for implementing LifecycleOwner in a Service
    implementation("androidx.lifecycle:lifecycle-service:${lifecycle_version}")

    // optional - ProcessLifecycleOwner provides a lifecycle for the whole application process
    implementation("androidx.lifecycle:lifecycle-process:${lifecycle_version}")

    // optional - ReactiveStreams support for LiveData
    implementation("androidx.lifecycle:lifecycle-reactivestreams-ktx:${lifecycle_version}")

//    Navigation
    // Kotlin
    implementation("androidx.navigation:navigation-fragment-ktx:${nav_version}")
    implementation("androidx.navigation:navigation-ui-ktx:${nav_version}")

    // Feature module Support
    implementation("androidx.navigation:navigation-dynamic-features-fragment:${nav_version}")

//    Paging
    implementation("androidx.paging:paging-runtime-ktx:${paging_version}")

    // alternatively - without Android dependencies for tests
    testImplementation("androidx.paging:paging-common-ktx:${paging_version}")

    // optional - RxJava2 support
    implementation("androidx.paging:paging-rxjava2-ktx:${paging_version}")

    // optional - RxJava3 support
    implementation("androidx.paging:paging-rxjava3:${paging_version}")

    // optional - Guava ListenableFuture support
    implementation("androidx.paging:paging-guava:${paging_version}")

//Room
    implementation("androidx.room:room-runtime:${roomVersion}")
    annotationProcessor("androidx.room:room-compiler:${roomVersion}")

    // To use Kotlin annotation processing tool (kapt)
    kapt("androidx.room:room-compiler:${roomVersion}")

    // optional - Kotlin Extensions and Coroutines support for Room
    implementation("androidx.room:room-ktx:${roomVersion}")

    // optional - RxJava2 support for Room
    implementation("androidx.room:room-rxjava2:${roomVersion}")

    // optional - RxJava3 support for Room
    implementation("androidx.room:room-rxjava3:${roomVersion}")

    // optional - Guava support for Room, including Optional and ListenableFuture
    implementation("androidx.room:room-guava:${roomVersion}")

    // optional - Paging 3 Integration
    implementation("androidx.room:room-paging:2.5.0-beta02")

//  WorkManager
    // Kotlin + coroutines
    implementation("androidx.work:work-runtime-ktx:${work_version}")

    // optional - RxJava2 support
    implementation("androidx.work:work-rxjava2:${work_version}")

    // optional - GCMNetworkManager support
    implementation("androidx.work:work-gcm:${work_version}")

    // optional - Multiprocess support
    implementation "androidx.work:work-multiprocess:${work_version}"

    //Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

    //Dagger
    implementation 'com.google.dagger:dagger:2.44.2'
    implementation 'com.google.dagger:dagger-android:2.44.2'
    kapt 'com.google.dagger:dagger-compiler:2.44.2'
    kapt 'com.google.dagger:dagger-android-processor:2.44.2'
    implementation('com.google.dagger:hilt-android:2.44.2')
    kapt('com.google.dagger:hilt-android-compiler:2.44.2')
    implementation 'androidx.recyclerview:recyclerview:1.2.1'
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")
    implementation 'com.github.bumptech.glide:glide:4.14.2'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'com.github.azhon:AppUpdate:4.1.1'
    implementation 'com.github.dhaval2404:imagepicker:2.1'
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

    // define a BOM and its version
    implementation(platform('com.squareup.okhttp3:okhttp-bom:5.0.0-alpha.10'))

    // define any required OkHttp artifacts without version
    implementation('com.squareup.okhttp3:okhttp:5.0.0-alpha.10')
    implementation('com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.10')

    implementation "androidx.datastore:datastore-preferences:1.0.0"
    implementation 'androidx.core:core-splashscreen:1.0.0'

    implementation 'androidx.multidex:multidex:2.0.1'
}

// Allow references to generated code
kapt {
    correctErrorTypes = true
}

Emulator android 5.0 don't show any message.


Solution

  • My problem was here.

    I think you have placed your image inside drawable-v24 instead of drawable. Goto Project Structure of your app to verify it or if you want just move files to drawable .