0

when I execute the following code in debug (ADB via USB) it works, but when I install a generated release .apk, it crashes. More precisely the following code crashes.

.replace(R.id.settings, new SettingsFragment())

Here is the full version of the code.

public class SettingsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings_activity);
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.settings, new SettingsFragment())
                .commit();
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    }

    static class SettingsFragment extends PreferenceFragmentCompat {
        @Override
        public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
            setPreferencesFromResource(R.xml.root_preferences, rootKey);
        }
    }
}

I found the error from the Google Play which says it throws an IllegalStateExcetion. I do not know any other way of retrieving error messages since it works perfectly fine in debug mode.

This is the corresponding XML file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/settings"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>
Taseer
  • 3,432
  • 3
  • 16
  • 35
fuxibut
  • 3
  • 2

2 Answers2

0

I believe disabling Instant run may resolve this. Take a look at this thread:

Android App Crashes on Real Device If apk is manually installed

mperic
  • 118
  • 9
0

Had to make SettingsFragment public, now it looks like it works.

fuxibut
  • 3
  • 2