3

I know, usually you would tell me to check the logs (before the crash, and see if I missed something) . . Nothing, because the app crashes no matter what, when I try to start a new activity. The only two activities that works are SplashScreen and SignIn

For the sake of trying to find out the problem to this, I did something simple

public class SplashScreen extends AppCompatActivity{
private final static String TAG = SplashScreen.class.getSimpleName();
private final static int DELAY = 2000;

@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash_screen);

    startActivity(new Intent(this, Root.class));
    finish();
}

and Root.class

public class Root extends AppCompatActivity {
private final static String TAG = Root.class.getSimpleName();
private long backPressedTime = 0;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    Log.i(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    Log.i(TAG, "super.onCreate");
    setContentView(R.layout.trending);
    Log.i(TAG, "setContentView");
}

So I set up some logs and looks like I goes to the second log.. 3rd one setcontentView is not displayed in console. The problem is even more weird, because no matter what class I try to start, it happens the same.

Mentions:

  • checked logs, nothing there with an exception (a warning 03-13 13:52:33.302 23233-23233/com.example.codkom.shirtex W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable ...

  • worked on the app a couple of days and tested on my personal device (working without problems, even now it does) but not on any other devices..

  • if does count, I use multidex, I override my Application class and did Multidex.install(context); as per documentation (said this because I had a guess that might be cause by Multidex but tested on API 21+ without multidex and it was ok(since API 21+ handle multidex on it's own)

  • I have 7 activities in my project, problem occurs on 3 of them

I got to a point where I have no idea what else to do.. so that's why I came here with this question.

Requested: enter image description here

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- The main content view -->
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/cl_"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.design.widget.AppBarLayout
        android:background="@drawable/overlay"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            app:layout_scrollFlags="enterAlways|scroll"
            app:navigationIcon="@drawable/ic_hamburger_menu">

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/standard_15_dp"
        android:id="@+id/fab_"
        android:backgroundTint="@color/blue"
        app:fabSize="normal"
        android:src="@drawable/ic_plus"
        app:layout_anchor="@id/content_frame"
        app:layout_anchorGravity="center|bottom"
        app:layout_behavior="com.example.codkom.shirtex.ScrollAwareFABBehavior"/>

</android.support.design.widget.CoordinatorLayout>

<!-- The navigation drawer -->
<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start">

    <include layout="@layout/mainmenu_activity"/>

</android.support.design.widget.NavigationView>

In Manifest

<application
    android:name=".application.ShirTexApp"
    android:allowBackup="true"
    android:icon="@drawable/ic_app_logo"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat"
    android:fullBackupContent="true">
<activity android:name=".activities.Root" android:theme="@style/Theme.AppCompat.Light.NoActionBar" android:windowSoftInputMode="adjustPan"/>
</application>
Ionut J. Bejan
  • 734
  • 11
  • 28

1 Answers1

2

It's Seems, You are using vector Drawables for Images. Vector Drawables doesnot have support below 5.0. To make support vector drawables in below 5.0 and all devices follow the steps.

Step 1:

First you have to mention in gradle. provide the support library

implementation 'com.android.support:appcompat-v7:23.2.0'

enable Vecor Drawable Support

android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
   }  
}

Step 2:

In design XML, when directly using ImageViews should use srcCompat instead of src for Vector Drawables.

<ImageView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  app:srcCompat="@drawable/ic_add" />

When using it in supporting drawable of components like leftDrawable, rightDrawable of Views, you should wrap the vector in drawable.

ic_action_wrapped.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_action_search_vector"/>
</selector>

Step 3: When you're loading the vector image in runtime, you have to load the image like that.

AppCompatResources.getDrawable(mContext,R.drawable.ic_action_search_vector);

For Some Devices in Application class or your Activity.

static {
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    }

In Your Case Based on log, Toolbar or FloatingActionButton having vector image change and check that.

Google Documenation : official android docs

Stack Overflow also having many reference for vector drawables.

Hope it helps.

Keerthivasan
  • 1,651
  • 1
  • 21
  • 47
  • First of all, I was right about the problem.. Crash is on `setContentView()` but not on every class, just on those in which I had a `FloatingActionButton` inside activity's XML. More precisely, because of `android:backgroundTint="@color/blue"` – Ionut J. Bejan Mar 20 '18 at 07:20
  • @IonutJ.Bejan Yes, same as vector drawables.. backgroundTint also supported after 5.0. Whenever you have a problem with views. it will crash on setContentView – Keerthivasan Mar 20 '18 at 07:54
  • But my midSdkVersion is 21, shouldn't be that ok ? – Ionut J. Bejan Mar 20 '18 at 10:48
  • Anyway, I have given you the `bounty` for this nice and detailed answer. My Problem was fixed . Thanks a lot – Ionut J. Bejan Mar 20 '18 at 14:14