未通过AndroidBenchmarkRunner使用IsolationActivity

问题描述 投票:1回答:1

我正在尝试试用Android的Jetpack Benchmark库,似乎无法克服此错误。尝试了所有我能想到的东西,将不胜感激任何使此简单示例起作用的帮助。

java.lang.AssertionError: ERRORS (not suppressed): ACTIVITY-MISSING
(Suppressed errors: DEBUGGABLE EMULATOR UNLOCKED)

WARNING: Not using IsolationActivity via AndroidBenchmarkRunner
AndroidBenchmarkRunner should be used to isolate benchmarks from interference
from other visible apps. To fix this, add the following to your module-level
build.gradle:
android.defaultConfig.testInstrumentationRunner
= "androidx.benchmark.junit4.AndroidBenchmarkRunner"

我遵循示例指南here,并且我的defaultConfig包含:

testInstrumentationRunner 'androidx.benchmark.junit4.AndroidBenchmarkRunner'
// Suppressing errors I can ignore while I'm testing. Unfortunately, suppressing 
// the ACTIVITY-MISSING error causes runtime crashes
testInstrumentationRunnerArgument 'androidx.benchmark.suppressErrors', 'EMULATOR,DEBUGGABLE,UNLOCKED'

并且我的依赖项包含:

    androidTestImplementation 'androidx.annotation:annotation:1.1.0'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test:core:1.2.0'
    androidTestImplementation 'androidx.test:rules:1.2.0'
    androidTestImplementation 'org.hamcrest:hamcrest-library:1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.benchmark:benchmark-junit4:1.0.0'

我的基准代码如下:

import android.util.Log;

import androidx.benchmark.BenchmarkState;
import androidx.benchmark.junit4.BenchmarkRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class BenchmarkTest {

    @Rule
    public BenchmarkRule benchmarkRule = new BenchmarkRule();

    @Test
    public void log() {
        final BenchmarkState state = benchmarkRule.getState();
        while (state.keepRunning()) {
            Log.d("LogBenchmark", "the cost of writing this log method will be measured");
        }
    }
}
java android benchmarking
1个回答
0
投票

我也遇到了同样的问题,只有在检查了他们的示例应用程序之后才能解决。看来他们忘了提及职业后卫规则。不幸的是,这种事情经常发生,因此请检查示例应用程序。

我相信,如果您丢失此信息,则可能是导致该错误的原因:

-keepattributes *Annotation*
-keepclasseswithmembers @org.junit.runner.RunWith public class *

我看到的另一个有趣的事情是,他们在项目中没有使用仪器运行器。

testInstrumentationRunner "androidx.benchmark.junit4.AndroidBenchmarkRunner"

https://github.com/android/performance-samples/blob/master/BenchmarkSample/benchmark/benchmark-proguard-rules.pro

© www.soinside.com 2019 - 2024. All rights reserved.