0

I have the template code for my "Helloworld" app written in javascript and react-native on Windows. I connected my android emulator and wanted to launch the app on it. The following happens when I run "react-native run-android" command. Node.js opens as a separate window and it's written "Loading dependency graph, done". However, in the terminal window, there is following error message:

>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)

-Concerning whether emulator is connected:

$ adb devices
List of devices attached
emulator-5554   device 

(Works similarly for my Android smartphone). USB debugging is enabled.

-Concerning what I have tried to solve the problem:

  • My user is set as administrator.
  • I had JDK11.0.1 version. I installed JDK1.8.0_201 and it is now set as my java version.

    User helloworld $ java -version
    java version "1.8.0_201"
    
  • I created ".gradle" folder in my project's directory in case there are problems with accessing/creating this kind of folder.

-I specified the path for sdk.dir in local.properties file

-My OS is Windows 8.1. Gradle's version is 4.7.
-I have installed Android Studio, JDK8 and 11.
-I am using GitBash for the terminal purposes.
-I have the following system's environment variables:
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
Path = 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

In case you are interested what was in the question before: My initial problem was that there just was not any error shown, but still nothing was launched on the emulator. I went around that by putting my project's "android" folder into Android Studio and it launched the app on my smartphone. However, when I introduced small changes to App.js, the project could not be updated due to some unknown error, and I couldn't reopen it as a new project. So I had to solve this problem by trying to run the app by using "react-native run-android" through terminal, and now I'm at this state of the problem.

2 Answers2

0

Mmmm... when you run react-native run-android on the console, 1 it should check if you have the android sdk's, second it should compile some things, and third, it should start metro bundler in ANOTHER console . The "Loading dependency graph, done" should appear on that OTHER console, while the main console is gonna still compile for about a minute or even more... then it's gonna launch the intent and open the app. Sometimes it just displays a blank screen after the first load, so you should exit the app and delete it from recents, and reopen the app

Post screenshots, it seems like you only see that secondary console while the main console is not displaying (?)

RegularGuy
  • 3,516
  • 1
  • 12
  • 29
  • I meant that, as you said, Metro Bundler is displayed in another console and it says "Loading dependency graph, done" there. I also have the android sdk with the ANDROID_HOME and Path variables set. Which kind of "some things" should it compile? And is there any other way to solve the problem, since I don't even see blank screen, just nothing happens on my smartphone – Темирлан Мырзахметов Jan 31 '19 at 08:17
  • Iin the main console should popup an error, or it should get "stuck" in a specific part , please post a screenshot of the MAIN console, the metro bundler is like a secondary console and in reality it doesn't show if your build succeeds or fails . – RegularGuy Jan 31 '19 at 14:04
  • could you please check it now? – Темирлан Мырзахметов Feb 04 '19 at 19:41
  • `-I have installed Android Studio, JDK8 and 11` , please make sure that the one JDK you are using is JDK 8 , it need to be 8 for react native to work https://stackoverflow.com/questions/53272230/could-not-create-service-of-type-scriptpluginfactory-using-buildscopeservices-cr – RegularGuy Feb 05 '19 at 15:47
0

Do you want to run a react-native or purely java application for which you must have used Android studio?

If for the studio app: you must enable the developer's options from your phone for enabling that check this:

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