use_native_modules! skipped the react-native dependency 'react-native-unity-view'. No podspec file was found. in IOS only.
marikani opened this issue ยท 33 comments
My react native version 0.60.5,Android is working fine.
This is fine as long as you add the library manually.
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?
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 #141).
For anyone interested:
- Add a Podspec file at root of
react-native-unity-view
. You will need to adjust thes.source
value to match your fork's location. We are using anadd-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
- Update
package.json
, adding ahomepage
attribute required by Podspec
"homepage": "https://github.com/f111fei/react-native-unity-view/",
- 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 theUnityExport
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
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
)
Awesome job
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.",
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 Any error that is related to React is your Header Search Paths
for this package.
@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:
Select RNUnityView
, and look at "Build Settings > Header Search Paths". You should see this:
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.
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?
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 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 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 You don't do anything else with that file besides the steps in the docs.
@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 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"
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.
Since you guys are pretty active, maybe you can help. I have an unsolved issue mentioned in #114 . Does anyone know why that happens?
@gustavobuttenbender Have you managed to get it running? I have the same set of errors.
My steps:
- Create clean rn 0.61.5 project
- npm install react-native-unity-view-reinvented --save
- Modify Pod file
- Create and setup unity 2018.4 project, add required files and build for ios
- Open workspace in xcode
- Add UnityConfig.xcconfig to
ios/${XcodeProjectName}/
- Add
#include "../Pods/Target Support Files/Pods-YOU-PROJECT-NAME/Pods-YOU-PROJECT-NAME.debug.xcconfig"
to top of UnityConfig - Drag UnityConfig inside Xcode main project
- Set UnityConfig as Configuration file for all targets of main project
- "Dead Code Stripping" to "Yes"
- Modify main.m file
- Run pod install
Did I miss sth.?
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 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 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 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 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 - 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 jiulongw/swift-unity#120 (comment)
@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...
@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
@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
.
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 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?
@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.
If still someone looking for solution i have made a folks to run on Unity 2019 https://github.com/akroshteotia/react-native-unity-view