Jay-flow
Jay-flow

Reputation: 187

react-native-view error when building Android

I am trying to use react-native-view, but I get an error when building Android.

https://github.com/react-native-community/react-native-webview

I have executed the installation and the command according to the link above.

$ yarn add react-native-webview

$ react-native link react-native-webview

When I think of $ react-native link react-native-webview It appears that an error occurred during command input. Because $react-native unlink React-native-webview, the error disappears during the build process. But I'm a react-native beginner and I may not be sure.

Error Log

JS server already running.
Building and installing the app on the device (cd android && gradlew.bat installDebug)...

FAILURE: Build failed with an exception.

* Where:
Settings file 'C:\Users\kimpe\ReactNativeProjects\BagStation\android\settings.gradle' line: 3

* What went wrong:
Could not compile settings file 'C:\Users\kimpe\ReactNativeProjects\BagStation\android\settings.gradle'.
> startup failed:
  settings file 'C:\Users\kimpe\ReactNativeProjects\BagStation\android\settings.gradle': 3: unexpected char: '\' @ line 3, column 117.
     e_modules\react-native-webview\android')
                                   ^

  1 error


* 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 15s
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\kimpe\ReactNativeProjects\BagStation\node_modules\react-native\local-cli\runAndroid\runAndroid.js:299:19)
    at buildAndRun (C:\Users\kimpe\ReactNativeProjects\BagStation\node_modules\react-native\local-cli\runAndroid\runAndroid.js:135:12)
    at isPackagerRunning.then.result (C:\Users\kimpe\ReactNativeProjects\BagStation\node_modules\react-native\local-cli\runAndroid\runAndroid.js:65:12)
    at process._tickCallback (internal/process/next_tick.js:68:7)


Process finished with exit code 1

/App.js

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 * @lint-ignore-every XPLATJSCOPYRIGHT1
 */

import React, {Component} from 'react';
import { WebView } from "react-native-webview";


type Props = {};
export default class App extends Component<Props> {
  render() {
    return (
        <WebView
            source={{uri: 'https://example.com'}}
        />
    );
  }
}

Thank you :D

Upvotes: 0

Views: 1854

Answers (2)

Naveen Vignesh
Naveen Vignesh

Reputation: 1359

This error occurs because of different slash that is resolved as path you use react-native link some-module.

Fixes:

  • Replace all \ to / in settings.gradle.
  • Also run commands from git bash or cygwin. They will resolve proper.

Upvotes: 1

OriHero
OriHero

Reputation: 1228

In projectName/android/settings.gradle change / to // or \ so that it become valid path. Output will be something like this:

project(':react-native-webview').projectDir = new File(rootProject.projectDir, '..\\node_modules\\react-native-webview\\android')

Upvotes: 0

Related Questions