DEV Community

Cover image for From JS to Fire OS: React Native for Amazon Devices

From JS to Fire OS: React Native for Amazon Devices

React Native enables developers to build native apps for Amazon Fire OS devices using their existing JavaScript and React skills. Since Fire OS is based on the Android Open Source Project (AOSP), if you are already working with React Native you can easily target our devices without learning a new tech stack or maintaining separate codebases.

We recommend using the Expo framework to build React Native apps as it enables an easier and faster development experience. Follow along to see how to get up and running with React Native for both Fire Tablets and Fire TVs.

โœ… Pre-requisites for this guide

Install the following:

  • Node.js: The JavaScript runtime environment
  • npm or Yarn: Package managers for JavaScript
  • Android Studio: the IDE used to compile and run your Fire OS apps locally

Configure Android Studio and its command-line tools:

  1. Follow this guide to set your ANDROID_HOME environment variable
  2. Install the following emulators from Android Studioโ€™s virtual device manager:
For Tablet: For TV:
tablet avd tv avd

๐Ÿ“ฑ Building for Fire Tablets

In the terminal, create a new React Native project with the expo package installed:

npx create-expo-app FireTabletDemo --template blank
Enter fullscreen mode Exit fullscreen mode

Running on Fire Tablet Emulator

List the available avds then launch the Android Tablet:

emulator -list-avds
emulator -avd name-of-your-tablet-emulator
Enter fullscreen mode Exit fullscreen mode

Navigate to the project directory (e.g. FireTabletDemo) and run the app using npx:

cd FireTabletDemo
npx expo start -a 
Enter fullscreen mode Exit fullscreen mode

Tablet emulator demo

Your app is now running on the emulator using a local development server and Expo Go, without having to create the Android build.

Running on a physical tablet device:

Follow the instructions here to connect your tablet via adb. Afterwards, confirm it is available as a device:

adb devices -l
Enter fullscreen mode Exit fullscreen mode

adb devices result
Navigate to the project directory then run a development build on your target device (e.g. KFTRWI)

cd FireTabletDemo
npx expo run:android -d [deviceName]
Enter fullscreen mode Exit fullscreen mode

The development build will now install within the android directory:

Tablet android build

Tablet development build

๐Ÿ“บ Building for Fire TVs

To build apps for Fire TVs with React Native you can follow a similar journey.

In a new directory, create a new React Native project with the expo, this time using the with-tv example:

npx create-expo-app FireTVDemo -e with-tv
Enter fullscreen mode Exit fullscreen mode

Running on Android TV Emulator

Launch the Android TV emulator:

emulator -avd name-of-your-tv-emulator
Enter fullscreen mode Exit fullscreen mode

Navigate to the project directory and run your app:

cd FireTVDemo
npx expo start -a
Enter fullscreen mode Exit fullscreen mode

Similar to the Fire tablets, your app will run on the avd emulator without having to create the Android build:

TV emulator build

Target the build for TVs:

In order to build for TVs, set the isTV prop to true in your app.json:

{
  "expo": {
    "plugins": [
      [
        "@react-native-tvos/config-tv",
        {
          "isTV": true,
        }
      ]
    ],
    "name": "FireTVDemo",
    "slug": "FireTVDemo"
  }
}
Enter fullscreen mode Exit fullscreen mode

Running your project on a Fire TV device

To connect your Fire TV, follow the instructions here then check that your device is connected using adb:

adb devices -l
Enter fullscreen mode Exit fullscreen mode

adb devices result

Navigate to the project directory then run a development build on your target device (e.g. -d AFTSS)

cd FireTVDemo
npx expo run:android -d [deviceName]
Enter fullscreen mode Exit fullscreen mode

You now have the development build installed on your device:

TV device build

๐Ÿ’ก You can verify your android builds are optimized for TV by checking that your app is using the Android leanback features in the Android manifest file.

Next steps

Congratulations on building your first React Native app for Amazon Fire Devices! To continue your learning journey you can:

Top comments (2)

Collapse
 
primetarget profile image
Ethan Anderson

This is a really informative guide on using React Native for Fire OS devices! I was wondering, do you have any tips for optimizing performance on these devices?

Collapse
 
anishamalde profile image
Anisha Malde

Hey Ethan, great question, I recommend checking out this guide from callstack - callstack.com/ebook/the-ultimate-g.... We are hoping to contribute to a section focused on TV soon!