react-native-unity-view icon indicating copy to clipboard operation
react-native-unity-view copied to clipboard

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

Open marikani opened this issue 4 years ago • 33 comments

My react native version 0.60.5,Android is working fine.

marikani avatar Sep 24 '19 10:09 marikani

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

ziyoshams avatar Oct 04 '19 18:10 ziyoshams

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 avatar Nov 07 '19 15:11 benjarwar

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:

  • If you have header/library/framework search paths to UnityExport files in your parent project, you can probably remove them as the Pods-managed RNUnityView will receive its own updated paths as per step 3 above.
  • We found that once RNUnityView is managed by Pods, the target RNUnityView Xcode project in the Pods project of our Workspace did not preserve the header search paths set to the Xcode project in this project repository. Hence, the extra step to update the header search paths in the post_install hook.
  • Make extra sure to avoid setting recursive header search paths to the UnityExport directory. We had done this while troubleshooting RNUnityView being unable to find UnityExport deps. And there are files, such as /UnityExport/Libraries/libil2cpp/include/icalls/mscorlib/System/String.h, that name collide with standard C++ library headers, causing builds to fail (often with hard to debug errors like 'limits' file not found)

benjarwar avatar Nov 19 '19 19:11 benjarwar

Awesome job

ziyoshams avatar Nov 20 '19 00:11 ziyoshams

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.",

benjarwar avatar Nov 20 '19 15:11 benjarwar

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?

marlon-wiprud avatar Nov 21 '19 13:11 marlon-wiprud

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

ziyoshams avatar Nov 21 '19 14:11 ziyoshams

@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 avatar Nov 21 '19 15:11 benjarwar

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.

benjarwar avatar Nov 21 '19 17:11 benjarwar

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:

  • add RNUnityView.xcodeproj to the Libraries folder of my XCode Project;
  • add libRNUnityView.a to the Link Binary With Libraries;

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!

gustavobuttenbender avatar Nov 26 '19 18:11 gustavobuttenbender

@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.

ziyoshams avatar Nov 26 '19 19:11 ziyoshams

@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?

gustavobuttenbender avatar Nov 26 '19 20:11 gustavobuttenbender

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

ziyoshams avatar Nov 26 '19 20:11 ziyoshams

@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?

gustavobuttenbender avatar Nov 26 '19 21:11 gustavobuttenbender

@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"

ziyoshams avatar Nov 27 '19 15:11 ziyoshams

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.

jeserodz avatar Nov 30 '19 19:11 jeserodz

@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

benjarwar avatar Dec 02 '19 19:12 benjarwar

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

ziyoshams avatar Dec 03 '19 16:12 ziyoshams

@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 avatar Dec 06 '19 16:12 megasus

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.

megasus avatar Dec 09 '19 17:12 megasus

@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.

jeserodz avatar Dec 09 '19 19:12 jeserodz

@jeserodz Amazingly, that worked. Thank you!

megasus avatar Dec 10 '19 11:12 megasus

@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!

nicost71 avatar Dec 18 '19 13:12 nicost71

@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.

jeserodz avatar Dec 18 '19 14:12 jeserodz

@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 :-)

nicost71 avatar Dec 18 '19 15:12 nicost71

@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

jeserodz avatar Dec 18 '19 15:12 jeserodz

@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...

nicost71 avatar Dec 18 '19 17:12 nicost71

@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

sburaksak avatar Feb 12 '20 13:02 sburaksak

@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.

benjarwar avatar Feb 12 '20 23:02 benjarwar

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.

ziyoshams avatar Mar 01 '20 19:03 ziyoshams