Javascript 错误:getApplication()在ReactNativeHost中具有受保护的访问权限
直到两天前我才发现这个错误:Javascript 错误:getApplication()在ReactNativeHost中具有受保护的访问权限,javascript,java,android,react-native,Javascript,Java,Android,React Native,直到两天前我才发现这个错误: > Task :app:compileDebugJavaWithJavac FAILED Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.
> Task :app:compileDebugJavaWithJavac FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.5/userguide/command_line_interface.html#sec:command_line_warnings
224 actionable tasks: 195 executed, 29 up-to-date
Note: /Users/yashatreya/Desktop/realyze/node_modules/@react-native-community/async-storage/android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStorage
Module.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/yashatreya/Desktop/realyze/node_modules/@react-native-community/datetimepicker/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDatePickerD
ialogFragment.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.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /Users/yashatreya/Desktop/realyze/node_modules/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.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.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/yashatreya/Desktop/realyze/node_modules/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NodesManager.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/yashatreya/Desktop/realyze/node_modules/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NodesManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /Users/yashatreya/Desktop/realyze/node_modules/react-native-sound/android/src/main/java/com/zmxv/RNSound/RNSoundModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/yashatreya/Desktop/realyze/node_modules/react-native-svg/android/src/main/java/com/horcrux/svg/TSpanView.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
/Users/yashatreya/Desktop/realyze/android/app/build/generated/rncli/src/main/java/debug/facebook/react/PackageList.java:90: error: getApplication() has protected access in ReactNativeHost
return this.reactNativeHost.getApplication();
^
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
这是我的MainApplication.java
包com.realyze;
导入android.app.Application;
导入android.content.Context;
导入com.facebook.react.PackageList;
导入com.facebook.react.react应用程序;
导入io.expo.EXPORATION.RNCAppearancePackage;
导入com.oblador.vectoricons.vectoricons包;
导入com.facebook.react.ReactNativeHost;
导入com.facebook.react.ReactPackage;
导入com.facebook.soloader.soloader;
导入java.lang.reflect.InvocationTargetException;
导入java.util.List;
//多重索引
导入androidx.multidex.multidex应用程序;
//RN推送通知
导入com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
公共类MainApplication扩展了多索引应用程序实现了该应用程序{
私有最终反应主机mReactNativeHost=
新的反应主机{
@凌驾
公共布尔getUseDeveloperSupport{
返回BuildConfig.DEBUG;
}
@凌驾
受保护的getPackages列表{
@抑制警告不必要的局部变量
List packages=new PackageListthis.getPackages;
//无法自动链接但可以在此处手动添加的包,例如:
//packages.addnew MyReactNativePackage;
新的反应推送通知包;
退货包裹;
}
@凌驾
受保护字符串getJSMainModuleName{
收益指数;
}
};
@凌驾
公共ReactNativeHost getReactNativeHost{
返回mReactNativeHost;
}
@凌驾
创建时的公共无效{
super.onCreate;
SoLoader.initthis,/*本机exopackage*/false;
initializeFlipperthis;//如果不想启用Flipper,请删除此行
}
/**
*在本机模板中加载翻转器。
*
*@param上下文
*/
私有静态void initializeFlipperContext上下文{
如果BuildConfig.DEBUG{
试一试{
/*
我们在这里使用反射来获取初始化Flipper的类,
因为Flipper库在发布模式下不可用
*/
Class aClass=Class.forNamecom.facebook.flipper.ReactNativeFlipper;
aClass.getMethodinitializeFlipper,Context.class.invokenull,Context;
}捕获类NotFounde异常{
e、 打印跟踪;
}捕获无此方法异常{
e、 打印跟踪;
}捕获非法访问异常e{
e、 打印跟踪;
}捕获调用targetException e{
e、 打印跟踪;
}
}
}
}
版本:
反应本机:0.61.4
安卓工作室:3.6.1
Gradle插件:3.4.2
我已尝试清除生成缓存,但仍会出现相同的错误
我是一个初学者,我不知道哪里出了问题
非常感谢您的帮助既然Gradle版本使用了大量缺陷功能,这似乎意味着我们应该检查它们
此时,gradle日志显示了哪些函数因Android studio中的设置而发生偏移,如下所示
Android Studio设置
Android studio>首选项SCMD+,>构建、执行、部署>
编译器>命令行选项>添加-警告模式=全部-堆栈跟踪
运行渐变构建
范例
检查日志后,修改并删除该部分。
MainApplication.java中的注释用于帮助和指导您如何添加无法自动链接的包;因此,如果不支持自动链接,则必须将其添加到软件包列表中,如下所示:
//RN-PushNotification
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
public class MainApplication extends MultiDexApplication 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:
// Add a new ReactNativePushNotificationPackage to the packages
// ONLY IF ReactNativePushNotificationPackage does not support auto-linking
packages.add(new ReactNativePushNotificationPackage());
return packages;
}
...
如果它确实支持自动链接,那么您必须删除/反转手动安装步骤,清理项目,并让React Native使用新的RN>=60自动链接系统处理本机链接
//RN-PushNotification
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
public class MainApplication extends MultiDexApplication 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:
// Add a new ReactNativePushNotificationPackage to the packages
// ONLY IF ReactNativePushNotificationPackage does not support auto-linking
packages.add(new ReactNativePushNotificationPackage());
return packages;
}
...