Android应用程序崩溃并显示SIG 9错误

3

我知道,通常你会让我检查日志(在崩溃之前,看看是否有遗漏的内容)。但是无论如何,当我尝试启动新活动时,应用程序都会崩溃。唯一有效的两个活动是SplashScreenSignIn

为了找出问题,我做了一些简单的尝试。

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();
}

以及 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");
}

我设置了一些日志,看起来我跳到了第二个日志..第三个日志里的setcontentView在控制台上没有显示。问题更加奇怪的是,无论我尝试启动什么类,都会出现相同的问题。

提及:

  • 检查了日志,没有任何异常(一个警告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 ...

  • 我花了几天时间在我的个人设备上开发应用并进行了测试(没有任何问题,即使现在也没有),但是在其他设备上却不能正常运行。

  • 如果算的话,我使用multidex,我重写了我的Application类,并根据文档执行了Multidex.install(context);(之所以这么说是因为我猜测可能是由Multidex引起的,但在API 21+上进行了测试,没有使用multidex,结果还好(因为API 21+自己处理multidex)。

  • 我的项目中有7个活动,在其中3个活动中出现问题。

我已经不知道还能做什么了..所以这就是我为什么来这里提出这个问题的原因。

要求: 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>

在清单文件中

<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>

从屏幕截图来看,您是通过意图启动应用程序的。如果您通过在设备上点击应用程序图标来“正常”启动它会发生什么? - TDG
问题在于我没有更多与此相关的信息。但肯定是发生在“onCreate()”中,但并不是每个活动类都会出现这种情况,只有其中一些。我想也许与主题有关,但似乎找不到崩溃活动之间的联系。 - Ionut J. Bejan
1
请勿在有文本可用时发布图像,这会使阅读和搜索文本片段更加困难。 - Jon Goodwin
这是一个小的文本片段,我认为检查它不难。 - Ionut J. Bejan
你想发布 R.layout.trending 吗? - Rahul
显示剩余6条评论
1个回答

2
看起来,您正在使用矢量图形来制作图片。矢量图形在 Android 5.0 以下的版本中不受支持。要使矢量图形在 Android 5.0 以下的设备上得到支持,请按照以下步骤进行操作。
第一步:
首先,在 gradle 中声明。提供支持库。
implementation 'com.android.support:appcompat-v7:23.2.0'

启用矢量图形支持。
android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
   }  
}

步骤2:
在设计XML中,当直接使用ImageViews时,应该使用“srcCompat”而不是“src”来使用矢量图形。
<ImageView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  app:srcCompat="@drawable/ic_add" />

在支持组件的drawable中使用它,如Views的leftDrawable、rightDrawable,应该将向量包装在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>

步骤3: 当您在运行时加载矢量图像时,必须以此方式加载图像。
AppCompatResources.getDrawable(mContext,R.drawable.ic_action_search_vector);

在应用程序类或您的活动中,对于某些设备。
static {
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    }

针对您的情况,根据日志检查工具栏或悬浮按钮中矢量图像的更改。
谷歌文档:官方安卓文档 Stack Overflow 上也有很多关于矢量可绘制对象的参考资料。
希望这可以帮到您。

首先,我对问题的判断是正确的。崩溃是在 setContentView() 上发生的,但并非在每个类中都有,只在那些在活动的 XML 中有 FloatingActionButton 的类中出现。更确切地说,是因为 android:backgroundTint="@color/blue" - Ionut J. Bejan
@IonutJ.Bejan 是的,与矢量可绘制对象相同。 backgroundTint 在5.0之后也得到支持。每当您在视图上遇到问题时,它都会在setContentView上崩溃。 - Keerthivasan
但是我的 midSdkVersion 是 21,这应该没问题吧? - Ionut J. Bejan
无论如何,我已经为您提供了这个漂亮而详细的答案的“赏金”。我的问题已经解决。非常感谢。 - Ionut J. Bejan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接