0
votes

I am trying to create a custom plugin for android devices in react-native which can call user from app interface itself rather than using native android app and implementing the plugin in expo app by linking it in expo app. But when I am importing the module in my JS code and using it the module is coming to be null.

This is my build.gradle file

buildscript {
    repositories {
        jcenter()
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
    }
}

apply plugin: 'com.android.library'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.1"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
    lintOptions {
        abortOnError false
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.facebook.react:react-native:+'
}


This is my package.json file

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "expo": "^33.0.0",
    "react": "16.8.3",
    "react-dom": "^16.8.6",
    "react-native": "https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz",
    "react-native-react-native-call-app": "file:../react-native-call-app",
    "react-native-web": "^0.11.4"
  },
  "devDependencies": {
    "babel-preset-expo": "^5.1.1"
  },
  "private": true
}

// Plugin code for call app module https://github.com/NikhilOO7/react-native-call-app-module

// js code

import RNReactNativeCallApp from "react-native-react-native-call-app";
onPress = id => {
        console.log(id, RNReactNativeCallApp);
        RNReactNativeCallApp.callPerson(id);
    };
2

2 Answers

0
votes

You can add custom native modules only after eject. https://docs.expo.io/versions/latest/expokit/eject/

0
votes

If you don't want to let go of expo and still want a way to add custom native modules, here is an interesting way to do it.

You have to eject the expo kit but choose to use expo kit there, make some changes in your app.json file, and in babel.config.js add module-resolver plugin.

With just these changes, you can run expo and ejected-expo app together from the same codebase. In the ejected version, you can add the native modules and in the unejected version, you can simply mock the native functionality.

Here is the complete blog which you can follow, it also provides a starter kit for you to start from. https://codersera.com/blog/running-expo-react-native-together/