Error setting up react-native on ubuntu 16.04 - android

I just started learning react native. I am following this tutorial to set up my environment: https://www.raywenderlich.com/178012/react-native-tutorial-building-android-apps-javascript
Everything seems okay until the point where I have to run 'react-native run-android'. I get the error below:
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
FAILURE: Build failed with an exception.
What went wrong:
Could not determine java version from '9.0.4'.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
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
I have both JAVA 8 and 9 installed but I am pointing to Java 8. This is what $JAVA_HOME returns when I echo:
"/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java"
Note, I have an emulator running too.

Have you tried to do what s on this link below as-well:
https://facebook.github.io/react-native/docs/getting-started.html
This page will help you install and build your first React Native app.
The commands:
$npm install -g create-react-native-app
$create-react-native-app AwesomeProject
$cd AwesomeProject
$npm start
(I also tried a Youtube video regarding how to start and run a project on Ubuntu : https://www.youtube.com/watch?v=OZ5nCNOzflM )
I did it myself and for me it worked, at least for what I showed above.
This part is about building projects with React Native:
https://facebook.github.io/react-native/docs/getting-started.html
Commands :
$npm install -g react-native-cli
Install JS needed:
Add the following lines to your $HOME/.bash_profile config file:
export JAVASCRIPT_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
Create project:
$react-native init AwesomeProject
Run:
$cd AwesomeProject
$react-native run-android
Let me know if I was of any help or not.
I am also trying to integrate Boilerplate for Android using React Native on a Linux Platform (Ubuntu) and I still didn t find a solution to do that, except what I described above.
Good Luck :)

Related

React Native build fails with "compileSdkVersion is not specified" message

I have created a fresh React Native project using expo init RNCourse-Bare, I'm following expo bare approach. I haven't changed anything in the project, just tried to run it against Virtual Device using npm run android --info command, here's my output:
And here's my .bash_profile:
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export ANDROID_HOME=$ANDROID_SDK_ROOT
export PATH=$PATH:ANDROID_SDK_ROOT/emulator
export PATH=$PATH:ANDROID_SDK_ROOT/platform-tools
And here's my Virtual Device:
Also, I have 2 versions of SDK installed:
android-31
android-33-ext
Any ideas?
Restarting my laptop solved the issue

Specify configs in the ini-formatted file:

Noob here,
Im trying to run android emulator installed for my reactnative app to test on vscode online on azure linux machine and getting the follow error:
Specify configs in the ini-formatted file:
/home/vsonline/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
when I run npm start-android-emulator I get the error.
Please any help. I am trying to run react-native code without installing android studio
you should use npx or yarn like this npx start-android-emulator or yarn start-android-emulator

Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory() react-native. How to fix?

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.
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 (?)
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/

React Native: Cannot see the change after running command "npm run android" on Mac Terminal

Hi, I am using Android Studio to run React Native. However, I am not able to see the change after running command "npm run android" inside the folder that contains all the files (App.js). I am stuck with this instruction screen and don't know how to fix it.
Thank you.
Run: npm install -g react-native-cli
then , run : react-native run-android

Execution failed for task ':app:compileDebugJavaWithJavac' react native

I am trying to run react native app on my android device like this in cmd
cd C:\Users\User\Desktop\js
react-native run-android
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.
Could not find tools.jar
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 5.243 secs 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/android-setup.html
Can anyone please tell me how to fix this problem?
Use the following step once, it may help you:
step 1: open cmd through administrator
step 2: navigate to your application by cd <path to your project>
step 3: run this command: ./gradlew clean
step 4: react-native run-android
Have you installed JDK and Android SDK properly? Are the JAVA_HOME and ANDROID_HOME properly placed in your environment variables?
I faced this issue while working on react-native project on Linux.
In my case issue occured because I linked some external plugin and then removed it without unlink. In that case you can attentively read your console error message. It should point to place that source an error.
The solution if ur version of react-native >= 0.61.0. It shows error as when we add any plugin and use link command then it makes changes in android and ios folder. But when we remove plugin, it gets removed from package.json but inside android changes are not reverted and it gives error. So use below command to generate android folder again.
I hope it will solve the error-
sudo rm -rf android/ ios/
yarn add react-native-eject
npx react-native eject
If you are working with react native, just make sure you set up environment variables correctly for java compiler.
after this goto package.json file in your project:
change this:
"react-native": "https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz",
to:
"react-native": "0.57.5",
save and run npm install
Source: https://github.com/facebook/react-native/issues/21722

Categories

Resources