f111fei / react-native-unity-view

Show an unity view in react native
MIT License
402 stars 102 forks source link

use_native_modules! skipped the react-native dependency 'react-native-unity-view'. No podspec file was found. in IOS only. #136

Open marikani opened 5 years ago

marikani commented 5 years ago

My react native version 0.60.5,Android is working fine.

ziyoshams commented 5 years ago

This is fine as long as you add the library manually.

benjarwar commented 5 years ago

Since 0.60 RN has moved to CocoaPods as default for dependency management. It would be best to add a Podspec for this project. @f111fei any plans to do so?

benjarwar commented 5 years ago

We are successfully using Pods to manage react-native-unity-view (we're using a forked version of this library, since it may be unmaintained; see https://github.com/f111fei/react-native-unity-view/issues/141).

For anyone interested:

  1. Add a Podspec file at root of react-native-unity-view. You will need to adjust the s.source value to match your fork's location. We are using an add-podspec branch as per the below:
require 'json'

package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

Pod::Spec.new do |s|
  s.name         = 'RNUnityView'
  s.version      = package['version']
  s.summary      = package['description']
  s.license      = package['license']

  s.authors      = package['author']
  s.homepage     = package['homepage']
  s.platform     = :ios, '9.0'
  s.ios.deployment_target = '9.0'
  s.tvos.deployment_target = "9.0"

  s.source       = { :git => '[https://github.com/******/react-native-unity-view.git]', :branch => 'add-podspec' }
  s.source_files  = 'ios/**/*.{h,m,mm}'

  s.dependency 'React'
end
  1. Update package.json, adding a homepage attribute required by Podspec
  "homepage": "https://github.com/f111fei/react-native-unity-view/",
  1. Fix the header search paths for RNUnityView after it is compiled as a target of your Pods project during pod install. This ensures that the Pods-managed version of RNUnityView can find files in the UnityExport directory as well as React dependencies. This is what works for us:
post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == 'RNUnityView'
      target.build_configurations.each do |config|
        config.build_settings['HEADER_SEARCH_PATHS'] ||= "$(inherited)"\
                                                         " $(PODS_ROOT)/../../node_modules/React/**"\
                                                         " $(PODS_ROOT)/../../node_modules/react-native/React/**"\
                                                         " $(PODS_ROOT)/../UnityExport/Classes"\
                                                         " $(PODS_ROOT)/../UnityExport/Classes/Unity"\
                                                         " $(PODS_ROOT)/../UnityExport/Libraries"\
                                                         " $(PODS_ROOT)/../UnityExport/Libraries/libil2cpp/include"\
                                                         " $(PODS_ROOT)/../UnityExport/Libraries/bdwgc/include"
      end
    end
  end
end
  1. cd ios && pod install

Notes:

ziyoshams commented 5 years ago

Awesome job

benjarwar commented 5 years ago

One more thing. On our CI, the Podspec wasn't passing validation because the description field in package.json passed to summary attribute in Podspec was an empty string. We fixed by updating package.json like so, from the README:

  "description": "Integrate unity3d within a React Native app. Add a react native component to show unity. Works on both iOS and Android.",
marlon-wiprud commented 5 years ago

Finally getting a chance to try out some of these solutions - thanks a ton for supplying the approach you took @benjarwar .

After implementing the above steps, I am running into this error: Property 'eventDispatcher' not found on object of type 'RCTBridge *'

wondering if anyone else has encountered this?

ziyoshams commented 5 years ago

@marlon-wiprud Any error that is related to React is your Header Search Paths for this package.

benjarwar commented 5 years ago

@marlon-wiprud can you send your ios/Podfile? Your React deps should all be managed there.

@ziyoshams is right, that the header search paths of RNUnityView will determine whether or not it can find React files. The problem is that CocoaPods works by accumulating all Podfile dependencies into a custom Pods project. In that process, header search paths set in this lib's RNUnityView.xcodeproj get nuked.

You can inspect what's set after running pods install by looking at the Targets listed in the Pods project in your workspace. So with Pods selected in the main nav, hit the dropdown or expand the project sidebar:

Screen Shot 2019-11-21 at 10 15 29 AM

Select RNUnityView, and look at "Build Settings > Header Search Paths". You should see this:

Screen Shot 2019-11-21 at 10 18 09 AM

benjarwar commented 5 years ago

Looking back at this, I think RNUnityView does not explicitly need to have React paths added once it's also managed using CocoaPods along with React Native. So these two lines can be removed from step 3 above:

                                                         " $(PODS_ROOT)/../../node_modules/React/**"\
                                                         " $(PODS_ROOT)/../../node_modules/react-native/React/**"\

We had remnants of getting Pods working in React Native < 0.60 in our Podfile, which required removing React deps from the Pods project within post_install hook.

gustavobuttenbender commented 5 years ago

Hi @benjarwar, thank you for the .podspec! I was able to pass through the .a files not being found; however, I got this error now in the Linking step of the build process, any chances you might have encounter it?

image

Not sure if I am missing something. I have made the link process manually:

I have exported my unity project and added to ios folder, like this: ios/UnityExport.

I did not add the UnityConfig.xconfig file to XCode (not using it at all). Is it needed now that we are using CocoaPods? I also do not have the UnityExport folder inside my XCode project, do I need to move it manually? If yes, should I also copy the resources?

Any help would be much appreciated. Thanks!

ziyoshams commented 5 years ago

@gustavobuttenbender Yes you need UnityConfig.xconfig because it contains needed flags for compiler. The thing you don't need is to link the library manually. Linking is taken care by podspec.

gustavobuttenbender commented 5 years ago

@ziyoshams Ok! Do you know how should I use the UnityConfig.xconfig with CocoadPods? Should I merge the .config into my PODS-{PROJECT_TARGET}.xconfig file?

ziyoshams commented 5 years ago

@gustavobuttenbender You don't do anything else with that file besides the steps in the docs.

gustavobuttenbender commented 5 years ago

@ziyoshams but currently I point to the PODS-{TARGET}.debug/release in my root Project configuration. I couldn't just start pointing to UnityConfig.xconfig, right?

ziyoshams commented 5 years ago

@gustavobuttenbender In UnityConfig file you should have a line that includes you pods. Open that file and you should see something like this:

#include "../Pods/Target Support Files/Pods-YOU-PROJECT-NAME/Pods-YOU-PROJECT-NAME.debug.xcconfig"
jeserodz commented 4 years ago

In case you're looking for an updated version of this library, compatible with Cocoapods, you can take a look at this fork: https://github.com/rexraphael/react-native-unity-view.

Is also available via NPM/Yarn as react-native-unity-view-reinvented.

I submitted a PR to fix the podspec in the fork, as is missing .mm files. Until it gets merged, you could easily do the one-liner patch after installing the package, but before running pod install.

Note: You still need to add your current Podfile settings to UnityConfig.xcconfig as @ziyoshams commented above.

benjarwar commented 4 years ago

@jeserodz nice work! In the absence of a response from @f111fei in #141, it might be worth folks switching over to this repo for better community support.

Also recommend taking a look at this PR, and incorporating it into react-native-unity-view-reinvented: https://github.com/f111fei/react-native-unity-view/pull/137

ziyoshams commented 4 years ago

Since you guys are pretty active, maybe you can help. I have an unsolved issue mentioned in #114 . Does anyone know why that happens?

megasus commented 4 years ago

@gustavobuttenbender Have you managed to get it running? I have the same set of errors. My steps:

  1. Create clean rn 0.61.5 project
  2. npm install react-native-unity-view-reinvented --save
  3. Modify Pod file
  4. Create and setup unity 2018.4 project, add required files and build for ios
  5. Open workspace in xcode
  6. Add UnityConfig.xcconfig to ios/${XcodeProjectName}/
  7. Add #include "../Pods/Target Support Files/Pods-YOU-PROJECT-NAME/Pods-YOU-PROJECT-NAME.debug.xcconfig" to top of UnityConfig
  8. Drag UnityConfig inside Xcode main project
  9. Set UnityConfig as Configuration file for all targets of main project
  10. "Dead Code Stripping" to "Yes"
  11. Modify main.m file
  12. Run pod install

Did I miss sth.?

megasus commented 4 years ago

Not sure why, but it's compiling without errors for me now. But I have a really weird bug now (iOS), that only occurs after adding react-native-unity-view-reinvented: The whole layout of my app seems to be reversed. For example If i left align text, the text will be right aligned and vise versa. Also flexDirection seems to be reversed, as by default elements are arranged from bottom to top. Even with the default react native example app, the same effect occurs.

jeserodz commented 4 years ago

@megasus that issue has happened to me in 2 different projects after integrating RN Unity View. It might be related to where you added the #import line in the UnityConfig.xcconfig file.

Turns out that the #import line has to be added at the bottom of the file, not at the top.

See here for more details.

megasus commented 4 years ago

@jeserodz Amazingly, that worked. Thank you!

nicost71 commented 4 years ago

@jeserodz First of all, thanks a lot for all your work, brought me quite a step further. Unfortunately I am not able to build integrate RNUnityView completely... I always end up in the error [...]/node_modules/react-native-unity-view-reinvented/ios/UnityUtils.mm:39:5: error: use of undeclared identifier 'UnityInitStartupTime' UnityInitStartupTime();

Do you have any hint what this could be? Or even better, a demo project which you managed to get it running? Again, thanks you very much for your help!

jeserodz commented 4 years ago

@nicost71 Can you give a try removing that line and running the app? I have integrated this to multiple Unity + RN projects lately, and one of them showed this issue. After removing the line and building to see what would happen, it worked as expected.

About the root cause of the error, we would need to look further, but I think it might be related to the Unity version used when exporting to Xcode.

nicost71 commented 4 years ago

@jeserodz I am using Unity 2019.2.14f1 together with "react-native-unity-view-reinvented": "^1.4.2" and "react-native": "0.61.5"... When I comment this line of code I got the error posted below. When I uncommented it again, I did not get the "UnityInitStartupTime()" Error anymore for some reason, but the same as with the commented code: `[...]//UnityExport/Classes/DynamicLibEngineAPI.mm:138:14: fatal error: 'Classes/iPhone_Sensors.h' file not found

include "Classes/iPhone_Sensors.h"`

If I change this line to "#include "iPhone_Sensors.h", the code compiles "forever" (over 45 mins now...)

As I am rather new to RN + Unity, I am quite struggling, if my entire setup is correctly working (with settings taken from Podfile, and no manual "hacks"). Do you have any "demo-project" you are willing to share with us, demonstrating a working setup? I know it's asked a lot, but I am sure many would profit from your expertise :-)

jeserodz commented 4 years ago

@nicost71 - I'll try to put together a working example project for you to reference. I'm sorry I am not able to share the codebases of the projects I'm working with this library.

However, the error you mentioned is progress in the setup. Remove "Classes/" from "Classes/iPhone_Sensors.h" and build again. (you'll notice that the file iPhone_Sensors.h is actually in the same directory as DynamicLibEngineAPI.mm).

However, DynamicLibEngineAPI.mm can actually be removed altogether in most cases. Checkout this https://github.com/jiulongw/swift-unity/pull/120#issuecomment-456315250

nicost71 commented 4 years ago

@jeserodz Thanks so much! An example project will for sure help me (and certainly others) building RN&Unity Apps, and push this even further. As mentioned before, I did try with stripping the "Classes/" from the include, which (btw. same result as removing the references to DynamicLibEngineAPI.mm) resulted in building forever...

sburaksak commented 4 years ago

@megasus I followed your steps, but could not get successfully build. Errors are below. Can you help me, thank you so much?

@jeserodz I am using reinvented fork, what should for this error? @benjarwar

Screen Shot 2020-02-12 at 16 42 03
benjarwar commented 4 years ago

@sburaksak not sure, and I'm no longer working on a React Native/Unity project. I do remember having issues when we tried exporting with 2019 Unity builds, which seemed to have compatibility issues with this library (which has not been well-maintained for quite some time). I believe we were stuck on Unity 2018.2.5f1.

ziyoshams commented 4 years ago

For folks who are using latest Unity, i can confirm that https://github.com/asmadsen/react-native-unity-view package works very well with minimal effort.

fabioglimb commented 4 years ago

@ziyoshams hi, when i try to run the example from the repo you posted, i get this build error in xcode Undefined symbols for architecture arm64: "_onUnityMessage", referenced from: _UnityMessageManager_onUnityMessage_m8A904C01129EA827FDD76B08B34FAF9A6C4B5E36 in Assembly-CSharp.o (maybe you meant: _UnityMessageManager_onUnityMessage_m8A904C01129EA827FDD76B08B34FAF9A6C4B5E36) ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

i've done correctly all the steps, i'm on unity 2019.3.0f6. Any idea how to solve this problem?

ziyoshams commented 4 years ago

@fabioglimb I have not run the example app from that repo. I just followed the installation steps for my project and it is pretty stable. I have seen that error that you are getting and I think it was related to Unity Versions. I can't confirm the Unity version that I used since I no longer work on that project. Try implementing it to your own project, maybe you won't get that error.

akroshteotia commented 3 years ago

If still someone looking for solution i have made a folks to run on Unity 2019 https://github.com/akroshteotia/react-native-unity-view