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

Allow auto-deployment with react-native-pod #117

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

rhdeck
Copy link

@rhdeck rhdeck commented Nov 28, 2017

By deploying PocketSVG as a CocoaPod via react-native-pod peer dependency (which also takes care of creating the Podfile, you can allow automatic installation. No more opening Xcode!

The project.pbxproj change tells the static library to use the parent app's Pod.

@macrozone
Copy link
Collaborator

yeah, cool! I heard that in react-native 0.50 there is built-in support for podfiles. Do you use that?

@macrozone
Copy link
Collaborator

i will check it tomorrow and release it if it works properly

@rhdeck
Copy link
Author

rhdeck commented Nov 28, 2017 via email

@macrozone
Copy link
Collaborator

Hi @rhdeck this issue here rhdeck/react-native-pod#1 is blocking us from merging this pr.

@rhdeck
Copy link
Author

rhdeck commented Dec 6, 2017

I published a fix to react-native-pod, but I'm not sure how you came across it. Can you share the workflow? you can give it another go, but I want the module to be useful, so understanding your situation would be worth a lot.

@rhdeck
Copy link
Author

rhdeck commented Dec 6, 2017

FWIW, here is my workflow for a one-line command to build and run your sample app using my fork. Obv it assumes the demo App.js code is in cwd.

react-native init testapp ; \
cd testapp ; \
cp ../App.js . ; \
yarn add \
  rhdeck/react-native-arkit \
  react-native-pod \
  react-native-fix-ios-version \
  react-native-camera-ios-enable \
  react-native-bundlebase \
  react-native-runios-withdevteam ; \
react-native link ; \
react-native runios --device --development-team

</View>
);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will remove all the appsample stuff. I learned how to do a react-native template, and it is a better approach.

@macrozone
Copy link
Collaborator

macrozone commented Dec 21, 2017

@rhdeck could you provide migration information? What needs to be changed in the xcode project? at the moment you need to add pocketsvg to libraries and to Embedded Binaries. Can this be removed?

@rhdeck
Copy link
Author

rhdeck commented Dec 21, 2017 via email

@rhdeck
Copy link
Author

rhdeck commented Dec 21, 2017

I'm not going to get that rebase done today - aiming for tomorrow.

Yes, the plan is to remove the manual steps related to pocketsvg entirely. Instead, we use a couple of peer dependencies so that you can just build on top of the RN "hello world" project (created by react-native init:

  • react-native-fix-ios-version to set the target version of the app to iOS 11 (necessary for ARKit)
  • react-native-pod to manage the installation of the pods.

Both will execute the necessary changes on the underlying project as of react-native link.

A few others will help too:

  • react-native-camera-ios-enable will add the privacy text,
  • react-native-runios-withdevteam will allow launching the app to device without ever opening xcode to manage the signing - it takes care of it on the command line.
  • react-native-bundlebase is going to be necessary for a lot of people who chose generic names for their projects, since by default the rn project names the bundle something like "org.react.example.[projectname]" and iTunes Connect requires that the full bundle identifier be owned by you.

These too do their work as of react-native link

That's why I recommended that "magic spell" extended command line approach a couple weeks ago - it just works - and you never touch xcode!

Those are just notes tho. Code changes to follow. I love your project - I want to help make it more deployable!

@macrozone
Copy link
Collaborator

macrozone commented Feb 7, 2018

hi @rhdeck

I tried to use it, but it does not work on a existing project. I typed react-native link in the project directory, but I receive this error on build:

Showing All Messages
/path/to/react-native-arkit/ios/RCTConvert+ARKit.m:10:9: 'SVGBezierPath.h' file not found

I tried to debug that, with no luck.

I already have a podfile in the project. So i deleted that, but no podfile is created on react-native link react-native-arkit

EDIT: I had to remove it first with react-native unlink react-native-arkit and then calling react-native link. unlinking and then calling react-native link react-native-arkit does not work

Edit2: After going deep in the rabbit hole, i still get the same error as above:

/path/to/react-native-arkit/ios/RCTConvert+ARKit.m:10:9: 'SVGBezierPath.h' file not found

Maybe some information:

i am using a linked version of react-native-arkit (yarn link react-native-arkit), so that i can develop on it. Maybe this messes with the path resolution of xcode and that's why header files are not found. beeing able to link the library is a must though.

@macrozone
Copy link
Collaborator

npm stopped to allow unexisting dependencies in the package.json, so I thought this here would be a good solution.

unfortunatly I could not manage to get it run. I tried 4 hours, but xcode and cocoapods is a big riddle for me.

I now found a workaround by using a git-submodule for PocketSVG. This needs a small adjustment on existing projects (see release notes for 0.8.x beta).

I would love to get this to work with cocoapods, but it's hard without a clear migration path.

@rhdeck
Copy link
Author

rhdeck commented Feb 7, 2018

Sounds like there are a couple moving parts here

1. yarn link

Yes, the yarn link creates problems in react-native! The trick here is that symlinks are one-way. Your app knows about the module at /node_modules/react-native-arkit/ios but the module doesn't know about the Pods directory at ../../../ios/Pods - because it's not there in a linked situation. So a relative path symlink that works for deployment does not work for development.

When I am dev-ing using the link where I have a dependency on Pods I create an additional header path for my static library under "Build Settings" of
($SRCROOT)/../../[appname]/ios/Pods (recursive) to the module I am working with for it to work properly. (I keep the module in a peer directory with my app, so I have Documents/react-native-arkit and Documents/[appname], where because of the link there is a symlink at Documents/[appname]/node_modules/react-native-arkit. Not the only solution, but the one I like best and would recommend.

Consumers of the module will not have to do the above. It just works! (See "magic spell" below)

2. react-native-pod

react-native-pod hooks the prelink and postlink events of react-native link (no arguments) so that whenever you run it, it will update your podfile based on the currently installed dependencies and their pods entry in package.json. So I think your issue was probably that you kept adding an argument to your link command.

Deployment Example

Here is a GUI-free "magic spell" that I tested on my macbook with XCode 9.2:

react-native init testapp
cd testapp
yarn add rhdeck/react-native-arkit react-native-pod react-native-bundlebase react-native-fix-ios-version react-native-camera-ios-enable react-native-setdevteam react-native-xcode
react-native setdevteam
react-native link
react-native xcode

(react-native xcode takes care of determining whether to open the xcodeproj or xcworkspace)

Then select your device and press play!

If you wanted to just run from the command line and deploy to your default device, you could:

react-native run-ios --device

Then add your code from the README to App.js - and away you go. (A little processcolor error will occur due to the green and white lights. Remove or wrap the strings with {processColor("[color]")} to get rid of your red screen! )

I have been doing quite a bit of deeply native development with iOS RN (e.g. I made most of those components I referenced in December, as well as modules like react-native-coreml) so feel free to chat me if I can help on that front.

I think your project is really cool and I hope with this PR that I could help make it easier for others to deploy!

@rhdeck
Copy link
Author

rhdeck commented Feb 14, 2018

Made a thing that could help with your development: react-native-fix-pod-links

The key is that it makes that bridging reference work.

Assuming you have an app you are developing from, you don't need this part, and can skip to the next one.

react-native init testapp 
cd testapp
yarn link react-native-arkit (Assuming your package is yarn linked)
yarn add react-native-arkit

Great! Let's add the necessary tools to your app, from the cwd of your project root.

yarn add react-native-fix-pod-links  react-native-pod react-native-bundlebase react-native-fix-ios-version react-native-camera-ios-enable react-native-setdevteam react-native-xcode
react-native setdevteam
react-native addpodlinks <-- This is the new command
react-native link
react-native xcode

So what does this do? It will make sure that your library - whereever it is - maintains the link to your pods via an absolute path added to header search paths.

You can remove that absolute path:

react-native removepodlinks

Its brand new, but I thought it might help bridge the gap between making this easy to distribute and easy to develop. Hope it helps you!

@bnjm
Copy link
Contributor

bnjm commented Apr 9, 2018

Any more luck with this? There's another dependency that might be added to the project (https://github.com/magicien/GLTFSceneKit) and an auto install would simplify things a lot.

@rhdeck
Copy link
Author

rhdeck commented Apr 10, 2018

I'll clone down the master branch and test/update.

@rhdeck
Copy link
Author

rhdeck commented Apr 12, 2018

I updated my repo and the following works for live development in XCode and VS Code (fixing pod header search paths using react-native-fix-pod-links plugin command react-native addpodlinks):

git clone https://github.com/rhdeck/react-native-arkit ; \
cd react-native-arkit ; \
yarn install ; \
cd .. ; \
react-native init arkittest4 ; \
cd arkittest4 ; \
yarn add \
  link:../react-native-arkit \
  react-native-pod \
  react-native-fix-pod-links \
  react-native-xcode \
  react-native-setdevteam \
  react-native-fix-ios-version \
  react-native-camera-ios-enable ; \
react-native link ; \
react-native setdevteam; \
react-native addpodlinks; \
cp ../App.js . ; \
react-native xcode ; \
code . 

The following works for a deployment situation:

react-native init arkittest3 ; \
cd arkittest3 ; \
yarn add \
  rhdeck/react-native-arkit \
  react-native-pod \
  react-native-setdevteam \
  react-native-fix-ios-version \
  react-native-camera-ios-enable ; \
react-native link ; \
react-native setdevteam; \
cp ../App.js . ; \
react-native run-ios --device

@bnjm
Copy link
Contributor

bnjm commented Apr 15, 2018

Thanks!! I just tried this out both for local development and regular consumption. With the one-liners above I ran into a problem as I have two version xcode installed (xcode-beta is or was required for ARKit 1.5 features).

Otherwise it worked great, all I had to do was open workspace the file. For as long as this project is iOS only I don't see that as a huge problem. It's such a nice improvement over manually linking everything.

@macrozone What do you think?

@rhdeck
Copy link
Author

rhdeck commented Apr 19, 2018

Side note on react-native xcode not working for you: in my experience the key to that and other command-line Xcode commands is in Xcode -> Preferences -> Locations -> Command Line Tools. Will launch with whatever you have set. Like you, I use Xcode 9.4 beta and find the plugin useful for quick-opening my workspace or project.

@bnjm
Copy link
Contributor

bnjm commented Apr 19, 2018

Thanks for the tip! How does it look to add another pod into react-native-arkit itself? I've been trying with react-native addpod '....' from within the react-native-arkit project but it fails, I believe because it is not recognised as a react-native project (react-native link also does not work).

@rhdeck
Copy link
Author

rhdeck commented Apr 19, 2018

Ah - you want to add the pod to the info in react-native-arkit, like gitf? Since you don't want the dependency in your package.json, I recommend global install and running from there:

yarn global add react-native-pod
cd ~/Documents/GitHub/react-native-arkit
react-native-pod --help # (to get list of commands)
react-native-pod addpod --help # (to get info on how to add a pod)
react-native-pod addpod PocketSVG #if you wanted to reinstall pocketsvg without regard to version
react-native-pod addpod PocketSVG --podversion 2.0.0 #if you wanted to reinstall pocketsvg specifically at 2.0.0

NB all this does is modify the "pods" entry in your package.json file. You can always edit this directly if you like. The following steps work either way.

Assuming that this local repo is still linked to your wrapper testing app, you do this to update the app:

cd ~/Documents/testingapp
react-native link # watch your podfile update and the new dependency get installed
react-native xcode # happy coding

Since this adds the pod to you package.json in the react-native-arkit module, any future apps will get that benefit as soon as they link. (Assuming they have the react-native-pod peerDependency added to their app)

That help?

(I would have shown how to add gITF, but the cocoapods search engine is down right now)

@bnjm
Copy link
Contributor

bnjm commented Apr 19, 2018

Thanks! I followed all the steps using the global react-native-pod and it seemed to work correctly to install the GLTFSceneKit pod...the GLTFSceneKit.framework gets built and placed in the Pods/Products.

However @importing GLTFSceneKit back in react-native-arkit results in "Module not found". I thought it would be a Framework Search Paths issue but that seems to be all correct. It might also be a module specific issue separate from react-native-pod.

@rhdeck
Copy link
Author

rhdeck commented Apr 19, 2018

Now that you've given me the name of the pod, I'll try it on my end too.

@rhdeck
Copy link
Author

rhdeck commented Apr 19, 2018

I took this for a spin and got a few data points:

  1. GLTFSceneKit is in Swift! Good choice.
  2. The command @import GLTFSceneKit generates a red ! "Module not found" in AppDelegate.m (which means it is not about the relationship with the react-native-arkit static library, which in turn means that there is no react-native-pod or react-native-fix-pod-links play here)
  3. The documentation says to use that @import command.

I kind of suspect that this is a Swift-OC interop issue. Getting Swift code to work in Objective-C usually takes explicit @objc attributes on classes/functions and at a gloss I don't see that in the Pod. But I don't see an immediate solution - will let you know if I come across one.

@bnjm
Copy link
Contributor

bnjm commented Apr 20, 2018

That makes sense about objc and Swift interop and shouldn't block this PR.

I tried again with an objc specific pod (GLTFSCN from https://github.com/warrenm/GLTFKit) and got a little further, #import <GLTF/GLTF.h> works correctly, however the path links inside the project are broken
screen shot 2018-04-20 at 14 15 20

Am I missing a step with react-native-fix-pod-links?

@rhdeck
Copy link
Author

rhdeck commented Apr 20, 2018

I managed to replicate your experience. And this time it was specific to using the import statement from the static library - from AppDelegate.m it works fine.

I notice that PocketSVG (which continues to work fine) links internally using "myheader.h" internally while GLTF uses <GLTF/GLTFHeader.h>. This is the difference between global headers and local user headers, and is exactly the kind of detail that I got into Swift to get away from!

But essentially the issue is going to be something about how the static library relates to the global search paths as used in the Pod. This is something that maybe could be fixed through editing the pbxproj file, but I don't have an immediate answer, and our use case (referencing a cocoapod from a static library) is odd enough that Google isn't delivering for me.

All that said, I don't think this is driven by react-native-pod or react-native-fix-pod-links. It's just that these packages (at least at present!) don't solve this particular issue.

I'm running a couple tests in the background and will post a comment if they give more insight.

@hehex9
Copy link

hehex9 commented Jun 9, 2018

Any luck ?

@rhdeck
Copy link
Author

rhdeck commented Jun 10, 2018

The point of discussion six weeks ago was getting the SLs to talk with CocoaPods more broadly. This was not really a specific problem with the PR as I understood it, which has been tested to work properly with the PocketSVG pod dependency that react-native-arkit uses today.

My tests that ran in April didn't really tell me anything more, except that the question of managing the dependency graph with SLs is a mess in XCode. This is an open area of development- really, learning - to make react-native-pod more useful.

I'm open to having been wrong about @bnjm's take on this - don't mean to speak out of turn!

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

Successfully merging this pull request may close these issues.

None yet

4 participants