react native错误:The development server returned response error code: 500


64x64
匿名 2017-10-30 23:10 629

调试react native项目时,出现错误The development server returned response error code: 500,提示如下:

`The development server returned response error code: 500

URL: http://xxx.xxx.xxx.xxx:8081/index.bu...

Body:
{"from":"E:\react-native-workspace\Jkvip\src\RootScene.js","to":"./img/tabbbar/tabbar_home_selected.png","message":"Unable to resolve module ./img/tabbbar/tabbar_home_selected.png from E:\\react-native-workspace\\Jkvip\\src\\RootScene.js: could not resolve `E:\react-native-workspace\Jkvip\src\img\tabbbar\tabbar_home_selected.png' as a file nor as a folder","name":"UnableToResolveError","type":"UnableToResolveError","errors":[{}]}
processBundleResult

BundleDownloader.java:225
access$100

BundleDownloader.java:40
onResponse

BundleDownloader.java:192
execute

RealCall.java:135
run

NamedRunnable.java:32
runWorker

ThreadPoolExecutor.java:1133
run

ThreadPoolExecutor.java:607
run

Thread.java:761


react nativewebviewvue 回答问题

2 个解决方案


1
匿名 2017-10-30T23:10:58

确认node服务是否已经开启。


2
等待青春 2017-11-05T23:17:56

使用反射的方式修改webview允许跨域

package com.example.weinre;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.webkit.WebView;

public class MyWebView extends WebView {

    public MyWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
    }

    public MyWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyWebView(Context context) {
        super(context);
    }

    public void enablecrossdomain() {
        try {
            Field field = WebView.class.getDeclaredField("mWebViewCore");
            field.setAccessible(true);
            Object webviewcore = field.get(this);
            Method method = webviewcore.getClass().getDeclaredMethod(
                    "nativeRegisterURLSchemeAsLocal", String.class);
            method.setAccessible(true);
            method.invoke(webviewcore, "http");
            method.invoke(webviewcore, "https");
        } catch (Exception e) {
            Log.d("custom webview", "enablecrossdomain error");
            e.printStackTrace();
        }
    }

    public void enablecrossdomain41() {
        try {
            Field webviewclassic_field = WebView.class
                    .getDeclaredField("mProvider");
            webviewclassic_field.setAccessible(true);
            Object webviewclassic = webviewclassic_field.get(this);
            Field webviewcore_field = webviewclassic.getClass()
                    .getDeclaredField("mWebViewCore");
            webviewcore_field.setAccessible(true);
            Object mWebViewCore = webviewcore_field.get(webviewclassic);
            Field nativeclass_field = webviewclassic.getClass()
                    .getDeclaredField("mNativeClass");
            nativeclass_field.setAccessible(true);
            Object mNativeClass = nativeclass_field.get(webviewclassic);

            Method method = mWebViewCore.getClass().getDeclaredMethod(
                    "nativeRegisterURLSchemeAsLocal",
                    new Class[] { int.class, String.class });
            method.setAccessible(true);
            method.invoke(mWebViewCore, mNativeClass, "http");
            method.invoke(mWebViewCore, mNativeClass, "https");
        } catch (Exception e) {
            Log.d("custom webview", "enablecrossdomain error");
            e.printStackTrace();
        }
    }

}

调用设置:  

 webview.enablecrossdomain41();
settings.setAllowUniversalAccessFromFileURLs(true)  


评论