Search code examples
androidandroid-support-libraryandroid-6.0-marshmallowandroid-9.0-pie

How to debug what part of my app is causing it to force close (backward compatibility problem)


This is my first venture into writing any kind of code, let alone an android app. I created the project with the compileSdkVersion of 28, targetSdkVersion of 28 and minSdkVersion of 23. The app will only run on Android Pie and crashes on any previous version I have tried to install it on.

Everything compiles properly and works wonderfully on the emulator and my personal phone (both on Pie). I have read a lot about using the Android Support Library, however, I have not seen any information on how to understand which parts of your code need to use things from the support library versus the framework. Android Studio may have given me warnings along the way about using things from the support library, but being new at this, I did not know what it meant or what my proper choice should be. Now that I understand, I don't know how to attack going back and finding (and then fixing) anything that needs to use the support libraries.

I imported com.android.support:appcompat-v7 and have used AppCompatActivity instead of Activity. In a nutshell, I use textViews, editTexts, spinners and a TabHost (with two tabs). I think that the ActionBar might be a problem as well, but do not know how to see if that is the problem and how to fix it.

The rest of the code is mathematical calculations with a bunch of if/then/else statements and some switch statements.

The app force closes when it is opened after being installed on any OS prior to Android Pie.

Snippet from content_main.xml (layout):

<Spinner
    android:id="@+id/spnFromPool"
    android:layout_width="176dp"
    android:layout_height="34dp"
    android:layout_gravity="start"
    android:layout_weight="0.3"
    android:background="@drawable/bg_spinner"
    android:entries="@array/pool_type_array" />

bg_spinner.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/swimToolPrimary"/>
            <corners android:radius="10dp" />
            <stroke android:color="#000000" android:width="1dp" />
        </shape>
    </item>
    <item android:gravity="center_vertical|right" android:right="8dp">
        <layer-list>
            <item android:width="12dp" android:height="12dp"  android:gravity="center" android:bottom="10dp"
                tools:targetApi="m">
                <rotate
                    android:fromDegrees="45"
                    android:toDegrees="45">
                    <shape android:shape="rectangle">
                        <solid android:color="@color/swimToolSecondary" />
                        <stroke android:color="@color/swimToolSecondary" android:width="1dp"/>
                    </shape>
                </rotate>
            </item>
            <item android:width="20dp" android:height="10dp" android:bottom="21dp" android:gravity="center"
                tools:targetApi="m">
                <shape android:shape="rectangle">
                    <solid android:color="@color/swimToolPrimary"/>
                </shape>
            </item>
        </layer-list>
    </item>
</layer-list>

Solution

  • You can check the problem in log of android studio by selecting "No Filters" in top-right corner in logcat and for filtering the data you can add package name of your app in search bar.