我正在尝试使用react-native-view,但是在构建Android时出现错误。
https://github.com/react-native-community/react-native-webview
我已经根据上面的链接执行了安装和命令。
$ yarn add react-native-webview
$ react-native链接react-native-webview
当我想到$ react-native链接react-native-webview 似乎在命令输入期间发生了错误。 因为$ react-native取消链接React-native-webview,所以错误在构建过程中消失了。 但是我是一名反应型初学者,我不确定。
错误日志
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'}}
/>
);
}
}
谢谢:D
答案 0 :(得分:1)
发生此错误是由于使用了react-native link some-module
的路径将不同的斜杠解决了。
修复:
\
中的所有/
替换为settings.gradle
。答案 1 :(得分:0)
在projectName/android/settings.gradle
中将/
更改为//
或\
,以使其成为有效路径。输出将是这样的:
project(':react-native-webview')。projectDir =新文件(rootProject.projectDir,'.. \\ node_modules \\ react-native-webview \\ android')