java.lang.IllegalArgumentException:尝试删除从未添加的OnFrameMetricsAvailableListener

时间:2018-10-23 09:30:37

标签: java android firebase android-studio

该应用在Android 8上崩溃。

当我尝试打开mainActivity中的任何活动时,然后按回到主要活动并尝试打开任何其他活动使应用程序崩溃

它说该应用程序无法停止主要活动!

这是日志

2018-10-23 12:19:33.963 20358-20358/global.medicount.healthpass.dev E/AndroidRuntime: FATAL EXCEPTION: main
Process: global.medicount.healthpass.dev, PID: 20358
java.lang.RuntimeException: Unable to stop activity {global.medicount.healthpass.dev/global.medicount.healthpass.ui.main.MainActivity}: java.lang.IllegalArgumentException: attempt to remove OnFrameMetricsAvailableListener that was never added
    at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:4038)
    at android.app.ActivityThread.handleStopActivity(ActivityThread.java:4087)
    at android.app.ActivityThread.-wrap24(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1625)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6518)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
 Caused by: java.lang.IllegalArgumentException: attempt to remove OnFrameMetricsAvailableListener that was never added
    at android.view.View.removeFrameMetricsListener(View.java:6252)
    at android.view.Window.removeOnFrameMetricsAvailableListener(Window.java:889)
    at android.support.v4.app.FrameMetricsAggregator$FrameMetricsApi24Impl.remove(FrameMetricsAggregator.java:436)
    at android.support.v4.app.FrameMetricsAggregator.remove(FrameMetricsAggregator.java:246)
    at com.google.android.gms.internal.firebase-perf.zze.onActivityStopped(Unknown Source:60)
    at android.app.Application.dispatchActivityStopped(Application.java:234)
    at android.app.Activity.onStop(Activity.java:1862)
    at android.support.v4.app.FragmentActivity.onStop(FragmentActivity.java:636)
    at android.support.v7.app.AppCompatActivity.onStop(AppCompatActivity.java:184)
    at global.medicount.healthpass.ui.base.BaseActivity.onStop(BaseActivity.java:388)
    at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1376)
    at android.app.Activity.performStop(Activity.java:7205)
    at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:4035)
    at android.app.ActivityThread.handleStopActivity(ActivityThread.java:4087) 
    at android.app.ActivityThread.-wrap24(Unknown Source:0) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1625) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loop(Looper.java:164) 
    at android.app.ActivityThread.main(ActivityThread.java:6518) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 

成绩:

dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.0.1'
        classpath 'com.google.firebase:firebase-plugins:1.1.5'
        classpath 'io.fabric.tools:gradle:1.25.4'
    }

依赖项:

    implementation "com.google.firebase:firebase-core:16.0.4"
    implementation "com.google.firebase:firebase-messaging:17.3.4"
    implementation 'com.google.firebase:firebase-perf:16.1.2'

我已经在旧的android版本(6)上测试了此问题,但该问题没有发生。该应用程序运行良好。 我已经看到了一些降级firebase-pref的解决方案,但这并不能解决我的问题。而且我不知道该怎么办。

2 个答案:

答案 0 :(得分:2)

尝试从android:hardwareAccelerated="false"标签下的AndroidManifest.xml中删除application

这解决了我的问题,而没有降级任何库。

答案 1 :(得分:0)

这是解决我的问题以使我的项目编译并成功运行的解决方案。

分级项目

buildscript {

    repositories {
        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.0.1'
        classpath 'com.google.firebase:firebase-plugins:1.1.5'
        classpath 'io.fabric.tools:gradle:1.25.4'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com" // Google's Maven repository
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

ext {
    // Sdk and tools
    minSdkVersion = 19
    targetSdkVersion = 28
    compileSdkVersion = 28
    buildToolsVersion = '28.0.0'
    versionCode = 18
    versionName = '3.6.0'

    // App dependencies
    supportLibraryVersion = '28.0.0'
    ....
}

这是AppGradle的依赖项

implementation "com.google.firebase:firebase-core:16.0.4"
implementation "com.google.firebase:firebase-messaging:17.3.4"
implementation "com.google.firebase:firebase-perf:16.1.2"

此外,我在Async任务中遇到了一个问题,因此它说Async可以执行一次,因此解决方案是

uploadUserIdProofTask.cancel(true);
uploadUserIdProofTask = new UploadUserIdProof();
uploadUserIdProofTask.execute(objects);

这些行帮助了我,我不知道它与日志之间是什么关系,但是它对我有用。