无法使用BuildScopeServices.createScriptPluginFactory()react-native创建ScriptPluginFactory类型的服务。怎么修?

时间:2019-01-30 19:50:31

标签: android windows react-native-android

我有用JavaScript编写的“ Helloworld”应用程序的模板代码,并且在Windows上是react-native。我连接了我的Android模拟器,并想在其上启动该应用程序。当我运行“ react-native run-android”命令时,会发生以下情况。 Node.js将作为一个单独的窗口打开,并写为“完成加载依赖图”。但是,在终端窗口中,有以下错误消息:

>User helloworld $ react-native run-android  
Starting JS server...  
Building and installing the app on the device (cd android && gradlew.bat installDebug)...  
FAILURE: Build failed with an exception.  

>*What went wrong:  
Could not create service of type ScriptPluginFactory using 
BuildScopeServices.createScriptPluginFactory().  
>Could not create service of type PluginResolutionStrategyInternal using BuildScopeServices.createPluginResolutionStrategy().  

>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 1s  
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:  
https://facebook.github.io/react-native/docs/getting-started.html  
Command failed: gradlew.bat installDebug  
Error: Command failed: gradlew.bat installDebug    
    at checkExecSyncError (child_process.js:616:11)  
    at Object.execFileSync (child_process.js:634:13)  
    at runOnAllDevices (C:\Users\User\helloworld\node_modules\react-native\local-cli\runAndroid\runAndroid.js:299:19)  
    at buildAndRun (C:\Users\User\helloworld\node_modules\react-native\local-cli\runAndroid\runAndroid.js:135:12)  
    at isPackagerRunning.then.result (C:\Users\User\helloworld\node_modules\react-native\local-cli\runAndroid\runAndroid.js:65:12)  
    at process._tickCallback (internal/process/next_tick.js:68:7)

-关于是否连接仿真器:

$ adb devices
List of devices attached
emulator-5554   device 

(适用于我的Android智能手机)。已启用USB调试。

-关于我尝试解决的问题:

  • 我的用户设置为管理员。
  • 我有JDK11.0.1版本。我安装了JDK1.8.0_201,现在将其设置为我的Java版本。

    User helloworld $ java -version
    java version "1.8.0_201"
    
  • 我在项目目录中创建了“ .gradle”文件夹,以防访问/创建此类文件夹时遇到问题。

-我在local.properties文件中指定了sdk.dir的路径

-我的操作系统是Windows 8.1。 Gradle的版本是4.7。
-我已经安装了Android Studio,JDK8和11。
-我将GitBash用于终端。
-我有以下系统的环境变量:
ANDROID_HOME = c:\ Users \ User \ AppData \ Local \ Android \ Sdk
GRADLE_HOME = C:\ Users \ User.gradle \ wrapper \ dists \ gradle-4.7-all \ 4cret0dgl5o3b21weaoncl7ys \ gradle-4.7
JAVA_HOME = C:\ Program Files \ Java \ jdk1.8.0_201
路径 = C:\ Program Files(x86)\ Common Files \ Oracle \ Java \ javapath; C:\ Windows \ system32; C:\ Windows; C:\ Windows \ System32 \ Wbem; C: \ Windows \ System32 \ WindowsPowerShell \ v1.0 \; C:\ Program Files(x86)\ NVIDIA Corporation \ PhysX \ Common; C:\ Program Files \ Git \ cmd;。\ Plugins; C:\ Users \ User \ AppData \ Local \ Programs \ Python \ Python37-32; C:\ Program Files \ nodejs \; c:\ Users \ User \ AppData \ Local \ Android \ Sdk \ platform-tools; C:\ Users \ User \ AppData \ Local \ Android \ Sdk \ platform-tools;%GRADLE_HOME%\ bin;%JAVA_HOME%\ bin

如果您对之前的问题感兴趣,请执行以下操作: 我最初的问题是,没有显示任何错误,但是在模拟器上仍然没有启动任何错误。我通过将项目的“ android”文件夹放入Android Studio来解决该问题,并在智能手机上启动了该应用程序。但是,当我对App.js进行小的更改时,由于某些未知错误而无法更新该项目,因此我无法将其作为新项目重新打开。因此,我不得不通过尝试通过终端使用“ react-native run-android”来运行应用程序来解决此问题,而现在我处于此问题的状态。

2 个答案:

答案 0 :(得分:0)

mmmm ...当您在控制台上运行react-native run-android时,1它应该检查您是否有android sdk,第二它应该编译一些东西,第三,它应该在ANOTHER控制台中启动Metro bundler。 “正在完成加载依赖关系图”应该出现在该其他控制台上,而主控制台仍将编译大约一分钟甚至更长的时间...然后它将启动该意图并打开该应用程序。有时,它只会在首次加载后显示空白屏幕,因此您应该退出该应用程序并将其从最近的应用程序中删除,然后重新打开该应用程序

发布屏幕快照,似乎您只能在主控制台未显示(?)时看到该辅助控制台

答案 1 :(得分:0)

您要运行必须使用Android Studio的React-native或纯Java应用程序吗?

如果是Studio应用:如果要启用该功能,必须通过手机启用开发者的选项:

https://www.samsung.com/uk/support/mobile-devices/how-do-i-turn-on-the-developer-options-menu-on-my-samsung-galaxy-device/