我添加了
@react-native-firebase/perf
按照以下步骤打包到我的react native应用程序:
perf/installation
监视我的应用程序的性能
按照以下步骤在简单函数中创建简单跟踪:
perf/usage
然后我注意到控制台中有一个错误,告诉我:
Error: You attempted to use a firebase module that's not installed on your Android project by calling firebase.perf().
Ensure you have:
1) imported the 'io.invertase.firebase.perf.ReactNativeFirebasePerfPackage' module in your 'MainApplication.java' file.
2) Added the 'new ReactNativeFirebasePerfPackage()' line inside of the RN 'getPackages()' method list.
我添加了它要求我添加的内容,在google上搜索了一些内容,但没有成功,而且在firebase控制台上,我在性能选项卡下看不到我的性能(我看到的是欢迎屏幕/添加SDK)
下面是我想的所有相关文件,Idk我缺少的东西我对android开发没有真正的经验
"dependencies": {
...
"@react-native-firebase/perf": "^14.8.0",
}
const appPerformanceRef = async () => {
const trace = await perf().startTrace('TEST_TRACE');
trace.putAttribute('test trace', 'looping a bunch of times');
trace.putMetric('metric', 25);
await trace.start();
for (let i = 0; i < 100000; i++) {}
console.log(trace.getMetrics());
await trace.stop();
};
appPerformanceRef();
import io.invertase.firebase.perf.ReactNativeFirebasePerfPackage;
和内部
MainApplication
班
...
private final ReactNativeHost mReactNativeHost =
new ReactNativeHostWrapper(this, new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
// this part
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
protected List<ReactPackage> getPackages() {
return Arrays.asList(
new MainReactPackage(),
new ReactNativeFirebasePerfPackage(),
}
@Override
protected String getJSMainModuleName() {
return "index";
}
@Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
});
apply plugin: 'com.google.firebase.firebase-perf'
dependencies {
...
classpath('com.google.firebase:perf-plugin:1.4.1')
}
include ':@react-native-firebase_perf'
project(':@react-native-firebase_perf').projectDir = new File(rootProject.projectDir, './../node_modules/@react-native-firebase/perf/android')