This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/flutter/troubleshooting/pspdfkit-widget-appcompat-activity-issue.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Viewer widget AppCompatActivity issue

The Nutrient viewer widgets for Flutter, NutrientDocumentView and the legacy NutrientView, require the activity in your Flutter Android project to extend AppCompatActivity. Stock Flutter Activity implementations don’t extend AppCompatActivity, so the viewer can crash when your app starts:

java.lang.ClassCastException: com.example.app.MainActivity cannot be cast to androidx.appcompat.app.AppCompatActivity

To fix this, point your launcher activity to NutrientFlutterActivity, which nutrient_flutter_android provides. For setup details, refer to the getting started guide.

Alternatively, make your activity extend the FlutterAppCompatActivity implementation. If your dependencies don’t include androidx.appcompat:appcompat, you might see compile errors. Add the following line under dependencies in android/app/build.gradle, and replace $appcompat_version with a real version:

implementation "androidx.appcompat:appcompat:$appcompat_version"

If your app’s theme isn’t based on AppCompat, FlutterAppCompatActivity can cause another error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.activitylifecycletest/com.example.activitylifecycletest.DialogActivity}:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

To fix this, change your Android project’s main theme parent to an AppCompat-based theme, such as PSPDFKit.Theme.Default. Open /android/app/src/main/res/values/styles.xml and make the following change:

<style name="NormalTheme" parent="@style/PSPDFKit.Theme.Default">
......
</style>

For dark mode support, set the parent theme in values-night/styles.xml, such as PSPDFKit.Theme.Dark. Open /android/app/src/main/res/values-night/styles.xml and make the following change:

<style name="NormalTheme" parent="@style/PSPDFKit.Theme.Dark">
......
</style>

If you don’t update the night mode theme, the app will crash on phones in dark mode. If your app doesn’t support dark mode, set the parent theme to PSPDFKit.Theme.Default for consistency.