gpt4 book ai didi

java - React Native : error: cannot find symbol > new AppCenterReactNativeAnalyticsPackage(MainApplication. 这个

转载 作者:行者123 更新时间:2023-11-30 12:04:24 33 4
gpt4 key购买 nike

在我添加这些之前,我在 React Native 中使用 android 成功构建:

"appcenter-analytics": "2.1.0",
"appcenter-crashes": "2.1.0",

我在:

"react": "16.8.6",
"react-native": "0.60.4",

错误是:

Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081 Note: /Users/danale/Projects/NFIBEngage/node_modules/react-native-sentry/android/src/main/java/io/sentry/RNSentryModule.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. /Users/danale/Projects/NFIBEngage/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:60: error: cannot find symbol new AppCenterReactNativeAnalyticsPackage(MainApplication.this, getResources().getString(R.string.appCenterAnalytics_whenToEnableAnalytics)), ^ symbol: class MainApplication location: class PackageList /Users/danale/Projects/NFIBEngage/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:60: error: cannot find symbol new AppCenterReactNativeAnalyticsPackage(MainApplication.this, getResources().getString(R.string.appCenterAnalytics_whenToEnableAnalytics)), ^ symbol: variable appCenterAnalytics_whenToEnableAnalytics
location: class string /Users/danale/Projects/NFIBEngage/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:61: error: cannot find symbol new AppCenterReactNativeCrashesPackage(MainApplication.this, getResources().getString(R.string.appCenterCrashes_whenToSendCrashes)), ^ symbol: class MainApplication location: class PackageList /Users/danale/Projects/NFIBEngage/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:61: error: cannot find symbol new AppCenterReactNativeCrashesPackage(MainApplication.this, getResources().getString(R.string.appCenterCrashes_whenToSendCrashes)), ^ symbol: variable appCenterCrashes_whenToSendCrashes location: class string 4 errors

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.

    Compilation failed; see the compiler error output for details.

显然,这个 android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java 文件在旧版本中不存在应用:

package com.facebook.react;

import android.app.Application;
import android.content.Context;
import android.content.res.Resources;

import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import java.util.Arrays;
import java.util.ArrayList;

import com.nfibengage.BuildConfig;
import com.nfibengage.R;

// @react-native-community/async-storage
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
// appcenter-analytics
import com.microsoft.appcenter.reactnative.analytics.AppCenterReactNativeAnalyticsPackage;
// appcenter-crashes
import com.microsoft.appcenter.reactnative.crashes.AppCenterReactNativeCrashesPackage;
// react-native-sentry
import io.sentry.RNSentryPackage;
// react-native-splash-screen
import org.devio.rn.splashscreen.SplashScreenReactPackage;

public class PackageList {
private Application application;
private ReactNativeHost reactNativeHost;
public PackageList(ReactNativeHost reactNativeHost) {
this.reactNativeHost = reactNativeHost;
}

public PackageList(Application application) {
this.reactNativeHost = null;
this.application = application;
}

private ReactNativeHost getReactNativeHost() {
return this.reactNativeHost;
}

private Resources getResources() {
return this.getApplication().getResources();
}

private Application getApplication() {
if (this.reactNativeHost == null) return this.application;
return this.reactNativeHost.getApplication();
}

private Context getApplicationContext() {
return this.getApplication().getApplicationContext();
}

public ArrayList<ReactPackage> getPackages() {
return new ArrayList<>(Arrays.<ReactPackage>asList(
new MainReactPackage(),
new AsyncStoragePackage(),
new AppCenterReactNativeAnalyticsPackage(MainApplication.this, getResources().getString(R.string.appCenterAnalytics_whenToEnableAnalytics)),
new AppCenterReactNativeCrashesPackage(MainApplication.this, getResources().getString(R.string.appCenterCrashes_whenToSendCrashes)),
new RNSentryPackage(),
new SplashScreenReactPackage()
));
}
}

MainApplication.java 文件位于 android/main/java/com/nfibengage/MainApplication.java 中:

package com.nfibengage;

import android.app.Application;
import android.util.Log;

import com.facebook.react.PackageList;
import com.facebook.hermes.reactexecutor.HermesExecutorFactory;
import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;

import java.util.List;

public class MainApplication extends Application implements ReactApplication {

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}

@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
return packages;
}

@Override
protected String getJSMainModuleName() {
return "index";
}
};

@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}

@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}

我尝试将它导入到 PackageList.java 中,如下所示:

import com.nfibengage.MainApplication;

但我继续得到同样的错误。如果有人能告诉我这个 PackageList.java 文件是从哪里来的,我如何才能让它再次工作,而不是完全删除 appcenter-analyticsappcenter -崩溃

最佳答案

请确保您的安装顺序与以下相同。

添加 App Center SDK 模块

npm install appcenter appcenter-analytics appcenter-crashes --save-exact

yarn add appcenter appcenter-analytics appcenter-crashes --exact

自动集成SDK

react-native link appcenter
react-native link appcenter-analytics
react-native link appcenter-crashes

App Center SDK 不会在链接过程中自动为 App Center 模块设置模拟。如果您在应用程序中使用 Jest 测试框架,并且在使用 Jest 运行测试时遇到由 App Center SDK 引起的错误,请将以下内容添加到 的 jest 部分package.json 文件(仅包含正在使用的模块):

"setupFiles": [
"<rootDir>/node_modules/appcenter/test/AppCenterMock.js",
"<rootDir>/node_modules/appcenter-analytics/test/AppCenterAnalyticsMock.js",
"<rootDir>/node_modules/appcenter-crashes/test/AppCenterCrashesMock.js",
"<rootDir>/node_modules/appcenter-push/test/AppCenterPushMock.js"
]

编辑项目的 android/app/src/main/assets/appcenter-config.json 并将 YOUR_APP_SECRET 占位符值替换为您的 App Center 项目的应用程序 secret 。

关于java - React Native : error: cannot find symbol > new AppCenterReactNativeAnalyticsPackage(MainApplication. 这个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57152499/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com