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

Attempt to invoke virtual method 'void com.twiliovoicereactnative.JSEventEmitter.setContext(com.facebook.react.bridge.ReactApplicationContext) #440

Open
tragicmj opened this issue Oct 23, 2024 · 0 comments
Assignees

Comments

@tragicmj
Copy link

Description

Trying to integrate Twilio voice official sdk, I have completed all the steps as per android but still getting the following error after the app is successfully built. The splash screen comes & then I get this error.

Reproduction Steps

  1. Run npx react-native run-android
  2. Once App is run, you get the splash screen & then the error.

Expected Behavior

  1. App to run & load the app screen instead of error

Actual Behavior

Once App is run, you get the splash screen & then the error.

Reproduction Frequency

Every time I run the app, get the issue

Screenshots

WhatsApp Image 2024-10-23 at 5 00 27 PM

Software and Device Information

Please complete the following information.

  • Device: Oppo A7
  • OS: Android version 8.1
  • React version: 18.2.0
  • React Native version: 0.74.4
  • Node version: 18.18.0
  • npm or yarn version: 9.8.1

Additional Context

I have removed the package name from all three files for pasting here
MainApplication.KT

import android.app.Application
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactHost
import com.facebook.react.ReactNativeHost
import org.devio.rn.splashscreen.SplashScreenReactPackage
import com.intercom.reactnative.IntercomModule
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.soloader.SoLoader
import com.twiliovoicereactnative.VoiceApplicationProxy;
import com.facebook.FacebookSdk
import com.facebook.appevents.AppEventsLogger
import android.content.BroadcastReceiver
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import android.content.Context

class MainApplication : Application(), ReactApplication {

  override val reactNativeHost: ReactNativeHost =
    object : DefaultReactNativeHost(this) {
      override fun getPackages(): List<ReactPackage> =
          PackageList(this).packages.apply {

          }

      override fun getJSMainModuleName(): String = "index"

      override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG

      override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
      override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
    }

  override val reactHost: ReactHost
    get() = getDefaultReactHost(applicationContext, reactNativeHost)

  private val mReactNativeHost = MainReactNativeHost(this)
  private val voiceApplicationProxy = VoiceApplicationProxy(mReactNativeHost)


  override fun registerReceiver(receiver: BroadcastReceiver?, filter: IntentFilter): Intent? {
    return if (Build.VERSION.SDK_INT >= 34 && applicationInfo.targetSdkVersion >= 34) {
        super.registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED)
    } else {
        super.registerReceiver(receiver, filter)
    }
  }

  override fun onCreate() {
    super.onCreate()
    FacebookSdk.sdkInitialize(applicationContext)
    SoLoader.init(this, false)
 
    if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
      // If you opted-in for the New Architecture, we load the native entry point for this app.
      load()
    }
  }

  override fun onTerminate() {
    voiceApplicationProxy.onTerminate()
    super.onTerminate()
  }

}

MainActivity.KT

import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
import com.facebook.react.defaults.DefaultReactActivityDelegate
import com.facebook.react.ReactRootView
import org.devio.rn.splashscreen.SplashScreen
import android.os.Bundle
import android.os.Build
import android.view.WindowManager
import com.twiliovoicereactnative.VoiceActivityProxy;
import android.widget.Toast;
import android.Manifest;
import android.content.Intent;
class MainActivity : ReactActivity() {

  override fun getMainComponentName(): String = "appName"

    private val activityProxy = VoiceActivityProxy(this) { permission ->
        when {
            Manifest.permission.RECORD_AUDIO == permission -> {
                Toast.makeText(
                    this@MainActivity,
                    "Microphone permissions needed. Please allow in your application settings.",
                    Toast.LENGTH_LONG
                ).show()
            }
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && Manifest.permission.BLUETOOTH_CONNECT == permission -> {
                Toast.makeText(
                    this@MainActivity,
                    "Bluetooth permissions needed. Please allow in your application settings.",
                    Toast.LENGTH_LONG
                ).show()
            }
            Build.VERSION.SDK_INT > Build.VERSION_CODES.S_V2 && Manifest.permission.POST_NOTIFICATIONS == permission -> {
                Toast.makeText(
                    this@MainActivity,
                    "Notification permissions needed. Please allow in your application settings.",
                    Toast.LENGTH_LONG
                ).show()
            }
        }
    }



  override fun onCreate(savedInstanceState: Bundle?) {
    SplashScreen.show(this)
      super.onCreate(null)
        activityProxy.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
            setShowWhenLocked(true)
            setTurnScreenOn(true)
        }
        window.addFlags(
          WindowManager.LayoutParams.FLAG_FULLSCREEN or
          WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
          WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON or
          WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
          WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
        )
  }

  override fun onDestroy() {
    activityProxy.onDestroy()
    super.onDestroy()
  }

  override fun onNewIntent(intent: Intent?) {
      super.onNewIntent(intent)
      activityProxy.onNewIntent(intent)
  }


}

MainReactNativeHost.kt

import android.app.Application
import com.facebook.react.PackageList
import com.facebook.react.ReactPackage
import com.twiliovoicereactnative.VoiceApplicationProxy

class MainReactNativeHost(application: Application) : VoiceApplicationProxy.VoiceReactNativeHost(application) {
    override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG

    override fun getPackages(): List<ReactPackage> {
        val packages = PackageList(this).packages
        // Packages that cannot be autolinked yet can be added manually here
        // packages.add(MyReactNativePackage())
        return packages
    }

    override fun getJSMainModuleName(): String = "index"
}
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

No branches or pull requests

2 participants