react-native-gesture-handler无法安装并显示编译错误

问题描述

我最初尝试将react-native-elements用于图标和其他组件。我按照文档进行了设置,但是图标显示为矩形的十字形。在此期间,我通过运行“ react-native link react-native-vector-icons”链接了矢量图标,并且还在项目的android文件夹中的setting.gradle中添加了以下内容

rootProject.name = 'Vida'

apply from: '../node_modules/react-native-unimodules/gradle.groovy'
includeUnimodulesProjects()

apply from: file("../node_modules/@react-native-community/cli-platform- 

android / native_modules.gradle“); applyNativeModulesSettingsGradle(settings)

include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new 
File(rootProject.projectDir,'../node_modules/react-native-vector-icons/android')

mainApplication.java文件也需要更改,因此我将其更改为以下内容

@Override
  protected List<ReactPackage> getPackages() {
  List<ReactPackage> packages = new PackageList(this).getPackages();
  packages.add(new ModuleRegistryAdapter(mModuleRegistryProvider));
  package.add(new RNGestureHandlerPackage()); // THis is the change I made for handling gestures.
    

   return Arrays.<ReactPackage>asList(
  new MainReactPackage(),new VectorIconsPackage() // THis is the change for vector Icons
);
}

我还添加

implementation project(':react-native-vector-icons')
implementation project(':react-native-gesture-handler')

生成build.gradle文件

在我首先通过“ react-native start”和“ react-native run-android”重新启动应用程序后,遇到了“ null不是对象(评估'RNGestureHandlerModule.default.Direction')”的问题之后,我尝试在线搜索解决方案,然后说一些不费吹灰之力并重新安装react-native-gesture-handlers即可解决该问题,因此我尝试卸载并重新安装了手势处理程序,并尝试重新启动流星服务器并运行“ react-native run-android”。而是,我遇到了一个错误,说:

C:\Vida\VidaApp@20\VidaArchive\android\app\src\main\java\blah\com\MainActivity.java:8: 
com.swmansion.gesturehandler.react does not exist
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
                                     ^
C:\Vida\VidaApp@20\VidaArchive\android\app\src\main\java\blah\com\MainActivity.java:37:
find symbol 
return new RNGestureHandlerEnabledRootView(MainActivity.this);
                       ^
symbol: class RNGestureHandlerEnabledRootView
2 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.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option  output. Run 
with --scan to get full insights.

* Get more help at https://help.gradle.org
eact does not exist
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;;
                                     ^                               ivity.java:37:
C:\Vida\VidaApp@20\VidaArchive\android\app\src\main\java\blah\com\MainActivity.java:37: error: cannot 
find symbol                                 his);
    return new RNGestureHandlerEnabledRootView(MainActivity.this);
                       ^
symbol: class RNGestureHandlerEnabledRootView
2 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.
                                                                     -debug option 
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more 
log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD Failed in 38s
                                                                     t-native-commu
at checkExecSyncError (child_process.js:635:11)
at execFileSync (child_process.js:653:15)                            tive-community
at runOnAllDevices (C:\Vida\VidaApp@20\VidaArchive\node_modules\@react-native-community\cli-platform- 
android\build\commands\runAndroid\runOnAly\cli-platformlDevices.js:94:39)
at buildAndRun (C:\Vida\VidaApp@20\VidaArchive\node_modules\@react-native-community\cli-platform- 
android\build\commands\runAndroid\index.js:17dules\react-na9:41)
at C:\Vida\VidaApp@20\VidaArchive\node_modules\@react-native-community\cli-platform- 
android\build\commands\runAndroid\index.js:133:12
at processticksAndRejections (internal/process/task_queues.js:97:5)  
at async Command.handleAction (C:\Vida\VidaApp@20\VidaArchive\node_modules\react- 
native\node_modules\@react-native-community\cli\build\index.js:182:9)

另外,当我尝试卸载手势处理程序时,Visual Studio崩溃了,我不得不再次打开,在启动Vscode之后,我重新安装了手势处理程序,它显示了以下错误

$ ...include ':react-native-gesture-handler'
bash: ...include: command not found

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: file-uri-to-path@1.0.0 (node_modules\file-uri-to- 
path):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory,rename 
'C:\Vida\VidaApp@20\VidaArchive\node_modules\file-uri-to-path' -> 
'C:\Vida\VidaApp@20\VidaArchive\node_modules\.file-uri-to-path.DELETE'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: nan@2.14.2 (node_modules\nan):
 npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory,rename 
'C:\Vida\VidaApp@20\VidaArchive\node_modules\nan' 
-> 'C:\Vida\VidaApp@20\VidaArchive\node_modules\.nan.DELETE'

npm ERR! code ENOENT
npm ERR! syscall rename
npm ERR! path C:\Vida\VidaApp@20\VidaArchive\node_modules\@egjs\hammerjs
npm ERR! dest C:\Vida\VidaApp@20\VidaArchive\node_modules\@egjs\.hammerjs.DELETE
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory,rename 
'C:\Vida\VidaApp@20\VidaArchive\node_modules\@egjs\hammerjs' -> 
'C:\Vida\VidaApp@20\VidaArchive\node_modules\@egjs\.hammerjs.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Shiri\AppData\Roaming\npm-cache\_logs\2020-10-31T07_52_44_306Z-debug.log

当前,我的package.json文件如下:

{
  "scripts": {
    "start": "react-native start","android": "react-native run-android","ios": "react-native run-ios","web": "expo start --web"
  },"dependencies": {
    "@react-native-community/masked-view": "^0.1.10","@react-native-community/netinfo": "^5.8.1","@redux-offline/redux-offline": "^2.6.0-expo.0","bootstrap": "^4.5.2","expo": "~37.0.3","expo-linear-gradient": "~8.1.0","expo-screen-orientation": "^1.0.0","expo-splash-screen": "^0.2.3","expo-updates": "~0.2.0","pusher-js": "^7.0.0","react": "~16.9.0","react-bootstrap": "^1.3.0","react-dom": "~16.9.0","react-native": "~0.61.5","react-native-agora": "^2.9.1-alpha.7","react-native-banner-carousel": "^1.0.3","react-native-country-list": "^1.0.10","react-native-elements": "^3.0.0-alpha.1","react-native-gesture-handler": "~1.6.0","react-native-material-dropdown": "^0.11.1","react-native-material-textfield": "^0.16.1","react-native-reanimated": "~1.7.0","react-native-rename": "^2.4.1","react-native-safe-area-context": "^1.0.0","react-native-screens": "^2.7.0","react-native-snap-carousel": "^3.9.0","react-native-svg": "11.0.1","react-native-unimodules": "~0.9.0","react-native-vector-icons": "^7.0.0","react-native-web": "~0.11.7","react-navigation": "^4.3.9","react-navigation-stack": "^2.5.1","react-redux": "^7.2.0","redux": "^4.0.5","redux-logger": "^3.0.6","redux-thunk": "^2.3.0","socket.io-client": "^2.3.0"
  },"devDependencies": {
    "@babel/core": "^7.8.6","babel-jest": "~25.2.6","babel-preset-expo": "~8.1.0","jest": "~25.2.6","react-test-renderer": "~16.9.0"
  },"private": true,"name": "VidaArchive","version": "1.0.0"
}

我需要早点解决此问题,因为我需要向我的前辈展示我的工作。我也是反应本机环境的新手,因此,我担心的是:

  1. 如何为Android(以及第三方库)设置和使用react-native矢量图标?
  2. RNGestureHandler是什么问题?
  3. 它说Package react-native-gesture-handler已被忽略,因为它包含无效的 原因:找不到模块“ react-native-gesture-handler \ package.json”。这是什么,是什么原因造成的?我该如何解决

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)