【问题标题】:Android app crashes with SIG 9Android 应用程序因 SIG 9 崩溃
【发布时间】:2018-03-13 12:10:21
【问题描述】:

我知道,通常你会告诉我检查日志(在崩溃之前,看看我是否遗漏了什么)。 .什么都没有,因为当我尝试开始一个新活动时,应用程序无论如何都会崩溃。唯一有效的两个活动是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 ...

  • 在应用程序上工作了几天,并在我的个人设备上进行了测试(工作没有问题,即使现在也是如此),但在任何其他设备上都没有..

  • 1234563 multidex 没问题(因为 API 21+ 自己处理 multidex)
  • 我的项目中有 7 个活动,其中 3 个出现问题

我已经到了不知道还能做什么的地步。这就是为什么我带着这个问题来到这里的原因。

请求:

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

【问题讨论】:

  • 从屏幕截图中可以看出,您是带着意图启动应用程序的。如果您通过点击设备上的应用图标“正常”启动它会发生什么?
  • 问题是我没有更多与此相关的信息。但可以肯定它发生在onCreate(),但不是每个活动类,只是其中一些。我在想可能是主题相关,但似乎没有找到崩溃活动之间的联系..
  • 请不要在有文字的情况下发布图片。它使阅读和搜索文本段变得更加困难。
  • 是一小段文字,我觉得不难查
  • 你想发帖R.layout.trending

标签: android process kill-process


【解决方案1】:

看来,您正在为图像使用矢量可绘制对象。 Vector Drawables 不支持 5.0 以下。要在 5.0 以下和所有设备上制作支持向量可绘制对象,请按照以下步骤操作。

第 1 步:

首先你必须在 gradle 中提及。 提供支持库

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

启用 Vecor 可绘制支持

android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
   }  
}

第 2 步:

在设计 XML 中,当直接使用 ImageViews 时,应使用 srcCompat 而不是 src 用于 Vector Drawables。

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

当使用它来支持组件的drawable,如views的leftDrawable,rightDrawable时,你应该将vector包裹在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);
    }

在你的情况下 根据日志、Toolbar 或 FloatingActionButton 有矢量图像变化并检查。

谷歌文档:official android docs

Stack Overflow 也有很多矢量绘图参考。

希望对你有帮助。

【讨论】:

  • 首先,我对问题的看法是正确的。崩溃发生在setContentView(),但不是在每个课程上,只是在我在活动的XML 中有FloatingActionButton 的课程上。更准确地说,因为android:backgroundTint="@color/blue"
  • @IonutJ.Bejan 是的,与矢量绘图相同。5.0 之后也支持 backgroundTint。每当您遇到视图问题时。它会在 setContentView 上崩溃
  • 但是我的 midSdkVersion 是 21,应该没问题吧?
  • 无论如何,我已经给了你bounty这个不错的详细答案。我的问题已解决。非常感谢
猜你喜欢
  • 2014-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-30
相关资源
最近更新 更多