How to Import Create Module in Expo or React-native?

After doing ‘expo init’, I entered ‘expo eject’ and separated it.

I made a basic ‘jar’ file to test application to App.js using ‘jar’ file.

enter image description here

The implementation is simple.

CreateAJarFile.class in jar:

class CreateAJarFile {
    public static void main(String args[]) {
        System.out.println("We got test");


dependencies {
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  implementation files('libs/myJarFile.jar')

After applying Android, I made a module to write modules on ‘Apps.js’.


enter image description here

package com.myjarfile;

import android.widget.Toast;

import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

import java.util.Map;
import java.util.HashMap;

public class CreateAJarFile extends ReactContextBaseJavaModule {

  private static final String DURATION_SHORT_KEY = "SHORT";
  private static final String DURATION_LONG_KEY = "LONG";

  public CreateAJarFile(ReactApplicationContext reactContext) {

  public String getName() {
    return "CreateAJar";

  public Map<String, Object> getConstants() {
    final Map<String, Object> constants = new HashMap<>();
    constants.put(DURATION_SHORT_KEY, Toast.LENGTH_SHORT);
    constants.put(DURATION_LONG_KEY, Toast.LENGTH_LONG);
    return constants;

  public void show() {
    System.out.println("We got test");


package com.myjarfile;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CreateAJarFilePackage implements ReactPackage {

    public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
        return Collections.emptyList();

    public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
        List<NativeModule> modules = new ArrayList<>();

        modules.add(new CreateAJarFile(reactContext));

        return modules;



import { NativeModules } from "react-native";

const { CreateAJar } = NativeModules;

export default CreateAJar;


import com.myjarfile.CreateAJarFilePackage;
public List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
        // Add your own packages here!
        // TODO: add native modules!

        // Needed for `react-native link`
        // new MainReactPackage()
        new CreateAJarFilePackage());

I made a module like this, added it, and tested it on App.js.

import CreateAJar from "./android/app/src/main/java/com/myjarfile/CreateAJar";

export default class App extends React.Component {
this.jarfunc = this.jarfunc.bind(this);
jarfunc() {;
return (
<View style={styles.container}>

However, both the module and the function could not be read.

How do I apply the module I created to ‘App.js’?

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.