iOS Release Build Failed to load Local HTML/JS/CSS Files in React Native WebView
Description
I'm trying to load SPA with AngularJS and HTML in React Native WebView.
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import { WebView } from "react-native-webview";
export default class App extends Component{
render() {
return (
<WebView
useWebKit={true}
originWhitelist={['*']}
source={ Platform.OS === 'ios' ? require('./MyPackage/www/index.html') : {uri: 'file:///android_asset/www/index.html'} }
onLoadProgress={e=>console.log(e.nativeEvent.progress)}
javaScriptEnabled={true}
domStorageEnabled={true}
nativeConfig={{ props: { webContentsDebuggingEnabled: true } }}
setAllowFileAccessFromFileURLs={true}
setAllowUniversalAccessFromFileURLs={true}
/>
);
}
}
For Android, I'm copying the content of MyPackage inside android_asset folder as:
task copyReactNativeHTML(type: Copy) {
from '../../MyPackage/'
into 'src/main/assets'
}
gradle.projectsEvaluated {
bundleDebugJsAndAssets.dependsOn(copyReactNativeHTML)
bundleReleaseJsAndAssets.dependsOn(copyReactNativeHTML)
}
^The above is working fine for Android Debug/Release Build without any error.
For iOS, I'm keeping MyPackage folder at root level of the project.
It's working fine in iOS Debug Build but when I tried to load it in iOS Release Build it's throwing following error:
[Error] Failed to load resource: The requested URL was not found on this server.
file:///var/containers/Bundle/Application/4074A848-9399-4CD1-B7B6-58C4DDBFF1C6/SampleReactNativeApp.app/assets/MyPackage/www/css/bootstrap.css
[Error] Failed to load resource: The requested URL was not found on this server.
file:///var/containers/Bundle/Application/4074A848-9399-4CD1-B7B6-58C4DDBFF1C6/SampleReactNativeApp.app/assets/MyPackage/www/js/angular.js
^Here the id (4074A848-9399-4CD1-B7B6-58C4DDBFF1C6) is randomly getting generated every time in the above Error and SampleReactNativeApp is my project/app name.
I tried debugging it in Safari Browser and found that none of the resources(JS/CSS) are getting loaded which I'm including in index.html
Environment
React Native Environment Info:
System:
OS: macOS Sierra 10.12.6
CPU: (4) x64 Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz
Memory: 138.34 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 11.1.0 - /usr/local/bin/node
npm: 6.4.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 11.2, macOS 10.13, tvOS 11.2, watchOS 4.2
Android SDK:
API Levels: 21, 22, 23, 24, 25, 26, 27, 28
Build Tools: 21.1.2, 22.0.1, 23.0.1, 23.0.2, 23.0.3, 24.0.0, 24.0.1, 24.0.2, 24.0.3, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.1, 27.0.2, 27.0.3, 28.0.0, 28.0.0, 28.0.0, 28.0.1, 28.0.2, 28.0.3
System Images: android-28 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5056338
Xcode: 9.2/9C40b - /usr/bin/xcodebuild
npmPackages:
react: 16.6.0-alpha.8af6728 => 16.6.0-alpha.8af6728
react-native: 0.57.3 => 0.57.3
npmGlobalPackages:
react-native-cli: 2.0.1
ios react-native webview wkwebview react-native-ios
add a comment |
Description
I'm trying to load SPA with AngularJS and HTML in React Native WebView.
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import { WebView } from "react-native-webview";
export default class App extends Component{
render() {
return (
<WebView
useWebKit={true}
originWhitelist={['*']}
source={ Platform.OS === 'ios' ? require('./MyPackage/www/index.html') : {uri: 'file:///android_asset/www/index.html'} }
onLoadProgress={e=>console.log(e.nativeEvent.progress)}
javaScriptEnabled={true}
domStorageEnabled={true}
nativeConfig={{ props: { webContentsDebuggingEnabled: true } }}
setAllowFileAccessFromFileURLs={true}
setAllowUniversalAccessFromFileURLs={true}
/>
);
}
}
For Android, I'm copying the content of MyPackage inside android_asset folder as:
task copyReactNativeHTML(type: Copy) {
from '../../MyPackage/'
into 'src/main/assets'
}
gradle.projectsEvaluated {
bundleDebugJsAndAssets.dependsOn(copyReactNativeHTML)
bundleReleaseJsAndAssets.dependsOn(copyReactNativeHTML)
}
^The above is working fine for Android Debug/Release Build without any error.
For iOS, I'm keeping MyPackage folder at root level of the project.
It's working fine in iOS Debug Build but when I tried to load it in iOS Release Build it's throwing following error:
[Error] Failed to load resource: The requested URL was not found on this server.
file:///var/containers/Bundle/Application/4074A848-9399-4CD1-B7B6-58C4DDBFF1C6/SampleReactNativeApp.app/assets/MyPackage/www/css/bootstrap.css
[Error] Failed to load resource: The requested URL was not found on this server.
file:///var/containers/Bundle/Application/4074A848-9399-4CD1-B7B6-58C4DDBFF1C6/SampleReactNativeApp.app/assets/MyPackage/www/js/angular.js
^Here the id (4074A848-9399-4CD1-B7B6-58C4DDBFF1C6) is randomly getting generated every time in the above Error and SampleReactNativeApp is my project/app name.
I tried debugging it in Safari Browser and found that none of the resources(JS/CSS) are getting loaded which I'm including in index.html
Environment
React Native Environment Info:
System:
OS: macOS Sierra 10.12.6
CPU: (4) x64 Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz
Memory: 138.34 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 11.1.0 - /usr/local/bin/node
npm: 6.4.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 11.2, macOS 10.13, tvOS 11.2, watchOS 4.2
Android SDK:
API Levels: 21, 22, 23, 24, 25, 26, 27, 28
Build Tools: 21.1.2, 22.0.1, 23.0.1, 23.0.2, 23.0.3, 24.0.0, 24.0.1, 24.0.2, 24.0.3, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.1, 27.0.2, 27.0.3, 28.0.0, 28.0.0, 28.0.0, 28.0.1, 28.0.2, 28.0.3
System Images: android-28 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5056338
Xcode: 9.2/9C40b - /usr/bin/xcodebuild
npmPackages:
react: 16.6.0-alpha.8af6728 => 16.6.0-alpha.8af6728
react-native: 0.57.3 => 0.57.3
npmGlobalPackages:
react-native-cli: 2.0.1
ios react-native webview wkwebview react-native-ios
We've had this same problem a few days ago. Could you check in Xcode if your files are being bundles with the compile target. (the checkboxes on the right when selecting the directory in xcode)
– Y. Gherbi
Nov 22 '18 at 23:34
add a comment |
Description
I'm trying to load SPA with AngularJS and HTML in React Native WebView.
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import { WebView } from "react-native-webview";
export default class App extends Component{
render() {
return (
<WebView
useWebKit={true}
originWhitelist={['*']}
source={ Platform.OS === 'ios' ? require('./MyPackage/www/index.html') : {uri: 'file:///android_asset/www/index.html'} }
onLoadProgress={e=>console.log(e.nativeEvent.progress)}
javaScriptEnabled={true}
domStorageEnabled={true}
nativeConfig={{ props: { webContentsDebuggingEnabled: true } }}
setAllowFileAccessFromFileURLs={true}
setAllowUniversalAccessFromFileURLs={true}
/>
);
}
}
For Android, I'm copying the content of MyPackage inside android_asset folder as:
task copyReactNativeHTML(type: Copy) {
from '../../MyPackage/'
into 'src/main/assets'
}
gradle.projectsEvaluated {
bundleDebugJsAndAssets.dependsOn(copyReactNativeHTML)
bundleReleaseJsAndAssets.dependsOn(copyReactNativeHTML)
}
^The above is working fine for Android Debug/Release Build without any error.
For iOS, I'm keeping MyPackage folder at root level of the project.
It's working fine in iOS Debug Build but when I tried to load it in iOS Release Build it's throwing following error:
[Error] Failed to load resource: The requested URL was not found on this server.
file:///var/containers/Bundle/Application/4074A848-9399-4CD1-B7B6-58C4DDBFF1C6/SampleReactNativeApp.app/assets/MyPackage/www/css/bootstrap.css
[Error] Failed to load resource: The requested URL was not found on this server.
file:///var/containers/Bundle/Application/4074A848-9399-4CD1-B7B6-58C4DDBFF1C6/SampleReactNativeApp.app/assets/MyPackage/www/js/angular.js
^Here the id (4074A848-9399-4CD1-B7B6-58C4DDBFF1C6) is randomly getting generated every time in the above Error and SampleReactNativeApp is my project/app name.
I tried debugging it in Safari Browser and found that none of the resources(JS/CSS) are getting loaded which I'm including in index.html
Environment
React Native Environment Info:
System:
OS: macOS Sierra 10.12.6
CPU: (4) x64 Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz
Memory: 138.34 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 11.1.0 - /usr/local/bin/node
npm: 6.4.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 11.2, macOS 10.13, tvOS 11.2, watchOS 4.2
Android SDK:
API Levels: 21, 22, 23, 24, 25, 26, 27, 28
Build Tools: 21.1.2, 22.0.1, 23.0.1, 23.0.2, 23.0.3, 24.0.0, 24.0.1, 24.0.2, 24.0.3, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.1, 27.0.2, 27.0.3, 28.0.0, 28.0.0, 28.0.0, 28.0.1, 28.0.2, 28.0.3
System Images: android-28 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5056338
Xcode: 9.2/9C40b - /usr/bin/xcodebuild
npmPackages:
react: 16.6.0-alpha.8af6728 => 16.6.0-alpha.8af6728
react-native: 0.57.3 => 0.57.3
npmGlobalPackages:
react-native-cli: 2.0.1
ios react-native webview wkwebview react-native-ios
Description
I'm trying to load SPA with AngularJS and HTML in React Native WebView.
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import { WebView } from "react-native-webview";
export default class App extends Component{
render() {
return (
<WebView
useWebKit={true}
originWhitelist={['*']}
source={ Platform.OS === 'ios' ? require('./MyPackage/www/index.html') : {uri: 'file:///android_asset/www/index.html'} }
onLoadProgress={e=>console.log(e.nativeEvent.progress)}
javaScriptEnabled={true}
domStorageEnabled={true}
nativeConfig={{ props: { webContentsDebuggingEnabled: true } }}
setAllowFileAccessFromFileURLs={true}
setAllowUniversalAccessFromFileURLs={true}
/>
);
}
}
For Android, I'm copying the content of MyPackage inside android_asset folder as:
task copyReactNativeHTML(type: Copy) {
from '../../MyPackage/'
into 'src/main/assets'
}
gradle.projectsEvaluated {
bundleDebugJsAndAssets.dependsOn(copyReactNativeHTML)
bundleReleaseJsAndAssets.dependsOn(copyReactNativeHTML)
}
^The above is working fine for Android Debug/Release Build without any error.
For iOS, I'm keeping MyPackage folder at root level of the project.
It's working fine in iOS Debug Build but when I tried to load it in iOS Release Build it's throwing following error:
[Error] Failed to load resource: The requested URL was not found on this server.
file:///var/containers/Bundle/Application/4074A848-9399-4CD1-B7B6-58C4DDBFF1C6/SampleReactNativeApp.app/assets/MyPackage/www/css/bootstrap.css
[Error] Failed to load resource: The requested URL was not found on this server.
file:///var/containers/Bundle/Application/4074A848-9399-4CD1-B7B6-58C4DDBFF1C6/SampleReactNativeApp.app/assets/MyPackage/www/js/angular.js
^Here the id (4074A848-9399-4CD1-B7B6-58C4DDBFF1C6) is randomly getting generated every time in the above Error and SampleReactNativeApp is my project/app name.
I tried debugging it in Safari Browser and found that none of the resources(JS/CSS) are getting loaded which I'm including in index.html
Environment
React Native Environment Info:
System:
OS: macOS Sierra 10.12.6
CPU: (4) x64 Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz
Memory: 138.34 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 11.1.0 - /usr/local/bin/node
npm: 6.4.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 11.2, macOS 10.13, tvOS 11.2, watchOS 4.2
Android SDK:
API Levels: 21, 22, 23, 24, 25, 26, 27, 28
Build Tools: 21.1.2, 22.0.1, 23.0.1, 23.0.2, 23.0.3, 24.0.0, 24.0.1, 24.0.2, 24.0.3, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.1, 27.0.2, 27.0.3, 28.0.0, 28.0.0, 28.0.0, 28.0.1, 28.0.2, 28.0.3
System Images: android-28 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5056338
Xcode: 9.2/9C40b - /usr/bin/xcodebuild
npmPackages:
react: 16.6.0-alpha.8af6728 => 16.6.0-alpha.8af6728
react-native: 0.57.3 => 0.57.3
npmGlobalPackages:
react-native-cli: 2.0.1
ios react-native webview wkwebview react-native-ios
ios react-native webview wkwebview react-native-ios
edited Nov 23 '18 at 6:54
asked Nov 22 '18 at 21:55
Shantanu Singh
64
64
We've had this same problem a few days ago. Could you check in Xcode if your files are being bundles with the compile target. (the checkboxes on the right when selecting the directory in xcode)
– Y. Gherbi
Nov 22 '18 at 23:34
add a comment |
We've had this same problem a few days ago. Could you check in Xcode if your files are being bundles with the compile target. (the checkboxes on the right when selecting the directory in xcode)
– Y. Gherbi
Nov 22 '18 at 23:34
We've had this same problem a few days ago. Could you check in Xcode if your files are being bundles with the compile target. (the checkboxes on the right when selecting the directory in xcode)
– Y. Gherbi
Nov 22 '18 at 23:34
We've had this same problem a few days ago. Could you check in Xcode if your files are being bundles with the compile target. (the checkboxes on the right when selecting the directory in xcode)
– Y. Gherbi
Nov 22 '18 at 23:34
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438380%2fios-release-build-failed-to-load-local-html-js-css-files-in-react-native-webview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438380%2fios-release-build-failed-to-load-local-html-js-css-files-in-react-native-webview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
We've had this same problem a few days ago. Could you check in Xcode if your files are being bundles with the compile target. (the checkboxes on the right when selecting the directory in xcode)
– Y. Gherbi
Nov 22 '18 at 23:34