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

Feat/windows autolinking #494

Merged

Conversation

mateusz1913
Copy link
Contributor

@mateusz1913 mateusz1913 commented Nov 22, 2020

Summary

Hi, since version react-native-windows 0.63 there is autolinking implemented (https://microsoft.github.io/react-native-windows/docs/native-modules-autolinking), but apparently windows implementation of this module is not recognized during autolinking process.
In order to support autolinking for windows, implementation should be changed to support RNW 0.62 and RNW 0.63+ according to (microsoft/react-native-windows#6024 (comment)) - react-native-camera and react-native-config modules are examples with windows implementation that supports autolinking.

In this PR, I have changed structure of windows implementation to support detecting project and solution files for autolinking mechanism on RNW 0.63 and also updated installation and manual linking docs.

Closes #490

Test Plan

Create react-native project with react-native-windows 0.63 version, install async-storage module without manual linking and run project (you can clone https://github.com/mateusz1913/rnwindowstest repo where I set up everything already)

@krizzu
Copy link
Member

krizzu commented Nov 26, 2020

Hey @kaiguo , mind having a look here?

@kaiguo
Copy link
Contributor

kaiguo commented Nov 30, 2020

@chrisglein @jonthysell

Copy link

@jonthysell jonthysell left a comment

Choose a reason for hiding this comment

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

Seems to build fine with autolinking once you make the changes I've recommended.

</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="ReactNativeWindowsProps">
<ReactNativeWindowsDir Condition="'$(ReactNativeWindowsDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'node_modules\react-native-windows\package.json'))\node_modules\react-native-windows\</ReactNativeWindowsDir>

Choose a reason for hiding this comment

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

I would change $(MSBuildThisFileDirectory) to $(SolutionDir) as per newer recommendations: https://microsoft.github.io/react-native-windows/docs/native-modules-setup#cwinrt

</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="ReactNativeWindowsProps">
<ReactNativeWindowsDir Condition="'$(ReactNativeWindowsDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'node_modules\react-native-windows\package.json'))\node_modules\react-native-windows\</ReactNativeWindowsDir>

Choose a reason for hiding this comment

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

As with the main project, replace $(MSBuildThisFileDirectory) with $(SolutionDir) as per https://microsoft.github.io/react-native-windows/docs/0.61/native-modules-setup#1-fixing-relative-microsoftreactnative-project-paths

*Note:* For `Windows` the [manual linking](Linking.md) is currently the only linking option.
#### Windows

- **React Native Windows > 0.63**

Choose a reason for hiding this comment

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

RNW >= 0.63

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props')" />
<Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props')" />

Choose a reason for hiding this comment

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

You missed one update from Microsoft.Windows.CppWinRT.2.0.190730.2 to Microsoft.Windows.CppWinRT.2.0.200316.3 here:

-<Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props')" />
+<Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.props')" />

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props')" />
<Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200316.3\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.190730.2\build\native\Microsoft.Windows.CppWinRT.props')" />

Choose a reason for hiding this comment

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

You can't just update the Microsoft.Windows.CppWinRT version in the vcxproj, you also need to update the version in the packages.config file in this folder for this to work properly.

- split .vcxproj and .sln files for compatibility with 0.63, 0.62 and 0.61 of react-native-windows
- moved common files into code directory
- fixed incorrect versions of cppwinrt package
- fixed typo in installation's docs
- changed directory path from MSBuildThisFileDirectory to SolutionDir
@mateusz1913 mateusz1913 force-pushed the feat/windows-autolinking branch from 308e199 to 12247d5 Compare December 2, 2020 17:22
@mateusz1913
Copy link
Contributor Author

Thanks for review! I applied requested changes and rebased with commit from master

@krizzu
Copy link
Member

krizzu commented Dec 18, 2020

@jonthysell Thanks for jumping in! Do you think it's ready to go?

Copy link

@jonthysell jonthysell left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Copy link
Member

@krizzu krizzu left a comment

Choose a reason for hiding this comment

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

Thanks a lot @mateusz1913 @jonthysell , great to have auto-linking for windows in 👏

@krizzu krizzu merged commit db6b7a5 into react-native-async-storage:master Jan 8, 2021
@flaviobvds
Copy link

Hi. Sorry if this is a newbie question. But even after the commit I'm still not able to import the changes into my project when I run npm install @react-native-async-storage/async-storage
What should I do to get the latest version including the changes comitted in #494?

@chrisglein
Copy link
Contributor

Hi. Sorry if this is a newbie question. But even after the commit I'm still not able to import the changes into my project when I run npm install @react-native-async-storage/async-storage
What should I do to get the latest version including the changes comitted in #494?

Generally I look at the Releases page (available from the home page of any repo). In this case it's this: https://github.com/react-native-async-storage/async-storage/releases
The latest available release is older than this commit. So you'll either need to wait for the next one (release schedule is up to the repo owner, and varies repo to repo) or manually apply the commit to your copy of the code to unblock yourself in the meantime (one of the advantages of modules shipping as source).

@krizzu
Copy link
Member

krizzu commented Jan 18, 2021

🎉 This PR is included in version 1.13.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

Does react-native-async-storage v1.13.2 support react-native-windows 0.63?
6 participants