viromedia / viro

ViroReact: AR and VR using React Native
MIT License
2.31k stars 483 forks source link

Cannot load obj/mt/jpg in ios debug build #487

Closed realchiu closed 5 years ago

realchiu commented 5 years ago

Environment

Please provide the following information about your environment:

  1. Development OS: Mac
  2. Device OS & Version: iOS version 11.0
  3. Version: "react-native": "0.55.4", "react-viro": "^2.12.0"
  4. Device(s): Iphone 6 to X

Description

It keeps on saying failed to load bundle, unable to resolve module xxxxxx.obj/mtl/jpg. But In android model can be loaded perfectly. I have made sure the path is absolutely correct, and all the file names are correct. I have also tried to modify the name as xxxx_obj.obj or xxxx_mtl.mtl, but it still does not work.

My podfile code of viroreact are as follow: pod 'ViroReact', :path => '../node_modules/react-viro/ios/' pod 'ViroKit_static_lib', :path => '../node_modules/react-viro/ios/dist/ViroRenderer/static_lib' to avoid one build error(but I forgot what exactly the error was).

I have added rn-cli.config, but it seems xcode does not import it.

getAssetExts() { return ['obj', 'mtl', 'bin', 'gltf', 'jpeg']; },

Sometimes this error will disappear, but with another exception with code lldb is thrown.

Reproducible Demo

require obj/mtl/jpg in the react native code, and have a debug build on ios devices like iphoneX and iphone 6.

hexp1989 commented 5 years ago

Hello @realchiu

I also used viro static lib with react-native, and seems everything going well.

I remember the reason is react-native-vector-icon cannot successful build which created by react-viro init. So I create react-native project intergeted the Viro SDK.

My package.json.

...
"dependencies": {
  "react": "16.3.1",
  "react-native": "0.55.1",
  "react-native-elements": "^1.0.0-beta7",
  "react-native-gesture-handler": "^1.0.10",
  "react-native-vector-icons": "^6.1.0",
  "react-navigation": "^3.0.5",
  "react-viro": "2.12.0"
}
...

Then init ios build and create Podfile.(Be sure cocoapods already installed)

platform :ios, '9.3'

target 'RNViroDemos' do
  pod 'ViroReact', :path => '../node_modules/react-viro/ios/'
  pod 'ViroKit_static_lib', :path => '../node_modules/react-viro/ios/dist/ViroRenderer/static_lib'
end

Execute pod install in $<PROJECT_DIR>/ios.

My rn-cli.config.js

'use strict';

const path = require('path');

module.exports = {
  getProjectRoots() {
    return this._getRoots();
  },

  getAssetRoots() {
    return this._getRoots();
  },

  getAssetExts() {
    return ["obj", "mtl", "JPG", "PNG", "mp4", "vrx", "hdr", "gltf", "glb", "bin", "arobject"];
  },

  _getRoots() {
    // match on either path separator
    if (__dirname.match(/node_modules[\/\\]react-native[\/\\]packager$/)) {
      // packager is running from node_modules of another project
      return [path.resolve(__dirname, '../../..')];
    } else if (__dirname.match(/Pods\/React\/packager$/)) {
      // packager is running from node_modules of another project
      return [path.resolve(__dirname, '../../..')];
    } else {
      return [path.resolve(__dirname, '.')];
    }
  },

};

Open $<PROJECT_NAME>.xcworkspace in Xcode.(My is Xcode 10) and config Provision profile\Certificate.

And I use react-native command react-native run-ios --device="My iPhone", everything is up.

Sometimes there are werid errors when build.

That's some of problems I have encountered.

I found above errors always occurs after react-native recomplied.

Before ios building, you don't need to manually compile the main.jsbundle.

Good luck.

realchiu commented 5 years ago

Thank you for your help but I cannot create a new project integrated with Viro SDK because I have already built a quite large project. This issue happens when I wants to integrate react viro with my existing project. But the main problem is that It works perfectly fine in android, but not IOS. I have struggled in this issue for almost 2 weeks but still cannot find a way to solve it.

VikAdvani commented 5 years ago

Hi @realchiu, A few things to try:

1) Since you are using a debug build, do you see the application making a request for the resource on the ngrok or package server on your machine?

2) can you try renaming the files to not include the postfix: ie, xxx_obj.obj-> xxx.obj.

3) Please attach the model and textures to this issue or email them to us at support@viromedia.com so we can test your model specifically so we can debug.

4) Do you have any log files you can send us that describe the error?

5) Do other models work for you? If you remove this problem model and try another model with textures does that work fine?

realchiu commented 5 years ago
  1. Yes, from the metro bundler but just some error messages.

  2. Originally my files' names are without the postfix. So with/without the postfix will still give the error.

  3. I will do it in a moment. Thank you.

  4. May you tell me where can I find these log files? I only got error log from the terminal.

    Loading dependency graph, done. error: bundling failed: Error: Unable to resolve module ../model/earthworm/earthworm.obj from *my_project_folder_root*/src/views/ARExploreView.js: The module ../model/earthworm/earthworm.obj could not be found from *my_project_folder_root*/src/views/ARExploreView.js. Indeed, none of these files exist:

    • earthworm.obj
    • *my_project_folder_root*/src/model/earthworm/earthworm.obj/index(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json) at ModuleResolver.resolveDependency (my_project_folder_root/node_modules/react-native/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:161:851) at ResolutionRequest.resolveDependency (my_project_folder_root/node_modules/react-native/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:91:16) at DependencyGraph.resolveDependency (my_project_folder_root/node_modules/react-native/node_modules/metro/src/node-haste/DependencyGraph.js:272:4579) at dependencies.map.relativePath (my_project_folder_root/node_modules/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:376:19) at Array.map () at resolveDependencies (my_project_folder_root/node_modules/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:374:16) at my_project_folder_root/node_modules/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:212:33 at Generator.next () at step (my_project_folder_root/node_modules/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:313) at my_project_folder_root/node_modules/react-native/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:473
  5. I have in total of 5 obj models with mtl but only 4 of them are working. Textures with format jpg(not JPG) can be loaded successfully.

realchiu commented 5 years ago

Sorry that the problem is suddenly solved with no reasons...I don't know what has happened, but let me close the issue first. I will reopen this issue if there are any follow ups.

mehrankhandev commented 5 years ago

I was implementing viro in my existing project and same issue was coming . I was using "react-native 0.57.7" and "react-viro 2.12.0"

After reading docs I have found that "react-viro v2.12.0" is compatible with "React Native v0.55.1"

I have Downgraded react native version to "0.55.1" and issue fixed.