CodexBloom - Programming Q&A Platform

App Crash When Opening a DialogFragment with Custom Animation on Android 14

👀 Views: 82 💬 Answers: 1 📅 Created: 2025-06-05
android dialogfragment animation android-14 Kotlin

I'm experiencing a crash in my Android app when I try to open a `DialogFragment` that uses a custom animation. The animation works perfectly on earlier versions of Android, but on Android 14, I get a `java.lang.IllegalArgumentException: Animation must not be null` behavior. I've checked that the animation resource is available, and it’s defined correctly in my `res/anim` folder. Here’s how I’m attempting to open the `DialogFragment`: ```kotlin class MyDialogFragment : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val dialog = super.onCreateDialog(savedInstanceState) dialog.window?.setWindowAnimations(R.style.CustomDialogAnimation) return dialog } } ``` And here’s the animation defined in `res/anim/custom_dialog_animation.xml`: ```xml <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:fromXScale="0.8" android:toXScale="1.0" android:fromYScale="0.8" android:toYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:duration="300" /> </set> ``` I’ve tried changing the animation resource to a simple fade animation, and that works without crashing, which leads me to believe it’s something specific about how custom animations are handled in Android 14. I also ensured that the animation resource ID is valid by logging it before setting it, and it returns the expected value. Any ideas on what might be causing this scenario or how I can work around it?