Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Native真机调试的坑 #21

Open
ceerqingting opened this issue Feb 1, 2019 · 0 comments
Open

React Native真机调试的坑 #21

ceerqingting opened this issue Feb 1, 2019 · 0 comments

Comments

@ceerqingting
Copy link
Owner

ceerqingting commented Feb 1, 2019

1. window上运行时react-native run-android出现

unable to load script from assets 'index.android.bundle'.Make sure your bundle ispackged correctly or you are running a packger server. 

解决方法:
1.在android\app\src\main下新建assets文件
2.在项目根目录下执行react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
执行成功会在android\app\src\main\assets下生成如下文件

index.android.bundle 

2. 403 Forbidden错误

解决方法:

  1. 先查看端口占用情况,默认端口是8081
netstat -aon|findstr '8081'

如果有进程占用可以选择杀死进程

taskkill -PID ***  -F

如果杀不死,那就换端口吧。。。,前提条件下先保证新的端口是没有被占用的

react-native start --port 8083
react-native run-android
  1. 如果换了端口,需要将真机的devSetting中的devServer的host和port修改为你主机的IP和新的端口,
    应该是要保证真机和PC是在统一网段下

3. 打包 Duplicate resources 错误

在这个目录下**/node_modules/react-native/react.gradle** file
在doFirst后面手工添加doLast

doFirst { ... }
doLast {
    def moveFunc = { resSuffix ->
        File originalDir = file("$buildDir/generated/res/react/release/drawable-${resSuffix}");
        if (originalDir.exists()) {
            File destDir = file("$buildDir/../src/main/res/drawable-${resSuffix}");
            ant.move(file: originalDir, tofile: destDir);
        }
    }
    moveFunc.curry("ldpi").call()
    moveFunc.curry("mdpi").call()
    moveFunc.curry("hdpi").call()
    moveFunc.curry("xhdpi").call()
    moveFunc.curry("xxhdpi").call()
    moveFunc.curry("xxxhdpi").call()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant