java.lang.RuntimeException at android.app.ActivityThread.performLaunchActivity

自作多情 提交于 2020-01-11 18:04:27

问题


From Google Play Console, java.lang.RuntimeException occurs without "Caused by:"

The below log is copied from Google Play Console Crash log.
This is for: Android 8.0, Android 8.1, Android 7.0, Android 7.1

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2955)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3030)
  at android.app.ActivityThread.-wrap11 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1696)
  at android.os.Handler.dispatchMessage (Handler.java:105)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6938)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)

Please help me regarding this!


回答1:


ActivityThread.java says it's updatePendingConfiguration() or registerOnActivityPausedListener(), so it either fails with .onPause() or it fails to call the super() method with the correct arguments - or something is wrong with the Configuration being applied.

I'd glady explain how to solve the issue, but the question lacks the code which throws the exception. The best way to tackle this might be to employ something alike Firebase Crashlytics, so that one can see where exactly this is coming from and which devices are affected (in case this should be specific). I'd almost suspect that it might be caused by starting an Activity with the application's Context, while not setting flag Intent.FLAG_ACTIVITY_NEW_TASK (see: this answer).




回答2:


From analyzing the log following assumption can be made,

The exception is thrown in any of the external libraries used in the project

Explanation: Basically, the exception is thrown by ActivityThread.java, more specifically, the performLaunchActivity() method at line 2955 threw the exception. As the stack trace didn't include any of your application's internal class, we can assume that the exception is thrown in an external class that is shipped with a library you are using in your project.

If that is the case, following workarounds can be performed to sort this out -

  • Look into all the library dependencies and markdown suspected ones
  • If you are using a custom view (such as AdView) from an external library, that library is most likely to cause this crash
  • Upgrade all the 3rd party libraries to latest version since the crash is causing in the latest OSs
  • Look into the official documentation to correctly implement those libraries. Like, troubleshoot page of the SDK's website may have the solution to this exact issue. Like, Dynamsoft Camera SDK already addressed this issue here
  • Look into the issue tracker of the libraries for this issue. For example, Android-Permission library has a closed issue having exactly the same log.

  • If your project is react native, there is a long discussion about it here

Suggestion: I want to add few more lines with @Martin Zeitler's suggestion of using Crashlytics.

I recommend you to Customize your Firebase Crashlytics crash reports. Because, sometimes only stack trace is not enough to reproduce the crash.

By using the customization feature you will be able to get,

  • User's identity

  • State of the app

  • The Events that were performed before the crash

Which will surely help you regenerate the crash and fix it.




回答3:


Intro

For the people saying:

did you resolve this issue? It's a rising crash in my app as well – Bao Le Feb 6 at 8:36 
did anybody resolve this issue? – AwaisMajeed Feb 9 at 13:15 
Also happening to me. =( – masterlopau Feb 26 at 1:51
do this solved? – Vengat Jul 19 at 5:55 

Do YOU have the extra cause log ? It would help enormously.

This is your Crash log:

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2955)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3030)
  at android.app.ActivityThread.-wrap11 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1696)
  at android.os.Handler.dispatchMessage (Handler.java:105)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6938)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)

Compare with this Crash log (identical line numbers and code flow):

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2955)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3030)
  at android.app.ActivityThread.-wrap11 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1696)
  at android.os.Handler.dispatchMessage (Handler.java:105)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6938)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)

This line differs:

  at java.lang.reflect.Method.invoke (Method.java)

and:

  at java.lang.reflect.Constructor.newInstance0 (Native Method)

with the extra cause log:

Caused by: android.support.v4.app.i$b: 
  at android.support.v4.app.i.instantiate (Fragment.java:386)
  at android.support.v4.app.k.a (FragmentContainer.java:33)
  at android.support.v4.app.s.a (FragmentState.java:79)
  at android.support.v4.app.o.a (FragmentManager.java:3080)
  at android.support.v4.app.l.a (FragmentController.java:152)
  at android.support.v4.app.j.onCreate (FragmentActivity.java:330)
  at host.exp.exponent.experience.f.onCreate (ReactNativeActivity.java:140)
  at host.exp.exponent.experience.a.onCreate (BaseExperienceActivity.java:79)
  at host.exp.exponent.experience.ExperienceActivity.onCreate (ExperienceActivity.java:160)
  at host.exp.exponent.experience.ShellAppActivity.onCreate (ShellAppActivity.java:22)
  at android.app.Activity.performCreate (Activity.java:7174)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1220)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2908)
Caused by: java.lang.reflect.InvocationTargetException: 
  at java.lang.reflect.Constructor.newInstance0 (Native Method)
  at java.lang.reflect.Constructor.newInstance (Constructor.java:334)
  at android.support.v4.app.i.instantiate (Fragment.java:364)
Caused by: java.lang.IllegalStateException: 
  at abi30_0_0.host.exp.exponent.modules.api.screens.Screen$ScreenFragment.<init> (Screen.java:19)

NOTE the at android.support.v4.app lines.

See Android standalone app randomly crashes on app open

Fixes

android.support class packages, or have a *Compat suffix

(1) AndroidX

(i) This problem has a miriad of causes from my internet search. A common cause seems to be the use of android.support class packages, or having a *Compat suffix. Review you build.gradle files for android.support.v4 etc...

(ii) Because sometimes it does not occur in testing, only deployment I guess the android.support.v4 etc... use's a problematic device library on some devices or API's.

  • Note: With the release of Android 9.0 (API level 28) there is a new version of the support library called AndroidX which is part of Jetpack. The AndroidX library contains the existing support library and also includes the latest Jetpack components.

  • You can continue to use the support library. Historical artifacts (those versioned 27 and earlier, and packaged as android.support.*) will remain available on Google Maven. However, all new library development will occur in the AndroidX library.

  • We recommend using the AndroidX libraries in all new projects. You should also consider migrating existing projects to AndroidX as well. Support Library Setup

  • The support libraries are now available through Google's Maven repository. We no longer support downloading the libraries through the SDK Manager, and that functionality will be removed soon..

  • Note: After including the Support Library in your application project, we strongly recommend that you shrink, obfuscate, and optimize your app for release. In addition to protecting your source code with obfuscation, shrinking removes unused classes from any libraries you include in your application, which keeps the download size of your application as small as possible.

  • Note: If you are including several support libraries, the minimum SDK version must be the highest version required by any of the specified libraries. For example, if your app includes both the v14 Preference Support library and the v17 Leanback library, your minimum SDK version must be 17 or higher.

See also:

Support Library Packages

features

(2) react-native-screens

It is related to react-native-screens and they have workaround for this issue, please have a look at:

Android crashes nondeterministically when restoring from background - veedeo.




回答4:


This crash could happen from literally anything. I had the same issue and the root cause was an IllegalArgumentException thrown by an incorrectly implemented Comparator within an overridden Fragment#onViewCreated. The fragment itself was added during AppCompatActivity#onCreate via FragmentManager.

2020-01-03 15:38:33.001 7860-7860/com.example.app E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.app, PID: 7860
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/MyActivity}: android.view.InflateException: Binary XML file line #9 in com.example.app:layout/my_activity: Binary XML file line #9 in com.example.app:layout/my_activity: Error inflating class fragment
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: android.view.InflateException: Binary XML file line #9 in com.example.app:layout/my_activity: Binary XML file line #9 in com.example.app:layout/my_activity: Error inflating class fragment
     Caused by: android.view.InflateException: Binary XML file line #9 in com.example.app:layout/my_activity: Error inflating class fragment
     Caused by: java.lang.IllegalArgumentException: Comparison method violates its general contract!
        at java.util.TimSort.mergeLo(TimSort.java:777)
        at java.util.TimSort.mergeAt(TimSort.java:514)
        at java.util.TimSort.mergeCollapse(TimSort.java:441)
        at java.util.TimSort.sort(TimSort.java:245)
        at java.util.Arrays.sort(Arrays.java:1492)
        at java.util.ArrayList.sort(ArrayList.java:1470)
        at java.util.Collections.sort(Collections.java:206)
        at com.example.app.MyFragment.onViewCreated(MyFragment.java:188)
        at androidx.fragment.app.FragmentManagerImpl.ensureInflatedFragmentView(FragmentManagerImpl.java:1144)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:851)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1133)
        at androidx.fragment.app.FragmentManagerImpl.addFragment(FragmentManagerImpl.java:1393)
        at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManagerImpl.java:3205)
        at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:134)
        at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:357)
        at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:336)
        at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1069)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:656)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
2020-01-03 15:38:33.003 7860-7860/com.example.app E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)

Of course, it's almost impossible to find the root cause if you just have the crash report from Google Play Console. I had the luck to have a customer incident, giving me insights on where to look and how to reproduce the crash. You might also switch to a custom crash reporting tool like HockeyApp or Firebase to see the whole stacktrace.




回答5:


I was getting the same error. I solved it, maybe it helps some people:

The problem was in my land/tooldbar.xml. I have migrated to Androidx library. I solved my problem changing problematic xml files.

Do not use:

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


</android.support.v4.widget.DrawerLayout>

Instead use:

<androidx.drawerlayout.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">
....
....


</androidx.drawerlayout.widget.DrawerLayout>


来源:https://stackoverflow.com/questions/53987118/java-lang-runtimeexception-at-android-app-activitythread-performlaunchactivity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!