Andy Stannard
Andy Stannard

Reputation: 1703

Is it possible to create an Android Wear app with react native

I have had a play with react native creating ios apps but have not tried android yet. With android you also get 'android wear' for watches etc, will react native work creating apps for those devices?

Upvotes: 18

Views: 22456

Answers (3)

fabOnReact
fabOnReact

Reputation: 5942

Github Project: https://github.com/fabOnReact/react-native-wear-connectivity

Installation

yarn add react-native-wear-connectivity

How to create a WearOS app using react-native

  • Create a new react-native app using the same name as your Mobile app. It is important to use the same name because both apps need to share the same package name (AndroidManifest, build.gradle, the project files) and applicationId (build.gradle).
npx react-native@latest init YourMobileAppName
  • Add the following line to the new project AndroidManifest (file ):
<!-- this file is located at android/app/src/main/AndroidManifest.xml -->
<uses-feature android:name="android.hardware.type.watch" />
  • Create a new emulator of type WearOS Large round.
  • Pair the Android emulator with the Wear OS emulator. Follow this instructions.
  • Start the metro server on port 8082 with yarn start --port=8082
  • Build the project with yarn android, open the react native dev menu and change the bundle location to your-ip:8082 (for ex. 192.168.18.2:8082).
  • Repeat the same steps for the Android Phone Emulator and use a different port (for ex. 8081).
  • Important Note: Before publishing to Google Play, make sure that both apps are signed using the same key (instructions here)

You can now build the app with yarn android. JS fast-refresh and the other metro functionalities work without problem.

API Documentation

Send Messages

import { sendMessage } from 'react-native-wear-connectivity';

sendMessage({ text: 'Hello watch!' });

Receive Messages

import { watchEvents } from 'react-native-wear-connectivity';

const unsubscribe = watchEvents.on('message', (message) => {
  console.log('received message from watch', message);
});

Upvotes: 1

Andrew Zhilin
Andrew Zhilin

Reputation: 1708

Actually, you can try React native vanilla

Upvotes: 7

Marcus Johansson
Marcus Johansson

Reputation: 158

React Native does not run on Android Wear at the current time, so you would have to do that code native.

Upvotes: 12

Related Questions