twilio / voice-quickstart-android

Quickstart app for the Voice Android SDK
https://www.twilio.com/docs/api/voice-sdk/android/getting-started
MIT License
184 stars 140 forks source link

Registering FCM token with Twilio to receive incoming call invites error (deprecated library) #523

Closed D-I-S-C closed 2 years ago

D-I-S-C commented 2 years ago

Before filing an issue please check that the issue is not already addressed by the following:

Please ensure that you are not sharing any Personally Identifiable Information(PII) or sensitive account information (API keys, credentials, etc.) when reporting an issue.

Description

When building the app, the following error happens:

error: cannot find symbol
import com.google.firebase.iid.FirebaseInstanceId;

  symbol:   class FirebaseInstanceId
  location: package com.google.firebase.iid

This error is due to FirebaseInstanceId now being deprecated, however not too sure on the new code required to make it work.

Steps to Reproduce

  1. Generate google-services.json
  2. Open the project in Android Studio
  3. Use Twilio CLI to deploy access token and TwiML application to Twilio Serverless
  4. Create a TwiML application for the Access Token
  5. Generate an access token for the quickstart
  6. Build the app (error occurs here)

Code

/*
 * Register your FCM token with Twilio to receive incoming call invites
 */
private void registerForCallInvites() {
    FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(this, instanceIdResult -> {
        String fcmToken = instanceIdResult.getToken();
        Log.i(TAG, "Registering with FCM");
        Voice.register(accessToken, Voice.RegistrationChannel.FCM, fcmToken, registrationListener);
    });
}

Expected Behavior

Succesful build.

Actual Behavior

Error as decribed above.

Reproduces How Often

100% (all the time).

Versions

        JavaVersion.VERSION_11,
        'androidGradlePlugin': '7.2.1',
        'googleServices'     : '4.3.10',
        'compileSdk'         : 31,
        'buildTools'         : '30.0.2',
        'minSdk'             : 21,
        'targetSdk'          : 31,
        'material'           : '1.4.0',
        'firebase'           : '17.6.0',
        'voiceAndroid'       : '6.1.1',
        'audioSwitch'        : '1.1.4',
        'androidxLifecycle'  : '2.2.0',
        'junit'              : '1.1.1'

Device Model

Nexus 4 API 27

kbagchiGWC commented 2 years ago

@D-I-S-C

Can you share the version of the dependencies used in your app build.gradle? https://github.com/twilio/voice-quickstart-android/blob/master/app/build.gradle#L74

D-I-S-C commented 2 years ago

@kbagchiGWC I have shared the versions for the project and the app in the original post under versions.

Below is the actual build.gradle (app) code used in my app:

apply plugin: 'com.android.application'

ext.playCustomRingback = { def playCustomRingback = System.getenv("playCustomRingback");

if (playCustomRingback == null) {
    logger.log(LogLevel.INFO, "Could not locate playCustomRingback environment variable. " +
            "Trying local.properties")
    Properties properties = new Properties()
    if (project.rootProject.file('local.properties').exists()) {
        properties.load(project.rootProject.file('local.properties').newDataInputStream())
        playCustomRingback = properties.getProperty('playCustomRingback')
    }
}

if (playCustomRingback == null) {
    playCustomRingback = false
}

return playCustomRingback;

}

android { compileSdkVersion versions.compileSdk

compileOptions {
    sourceCompatibility versions.java
    targetCompatibility versions.java
}

defaultConfig {
    applicationId "com.twilio.voice.quickstart"
    minSdkVersion versions.minSdk
    targetSdkVersion versions.targetSdk
    versionCode 1
    versionName "1.0"
}

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.debug
        buildConfigField("boolean", "playCustomRingback", "${playCustomRingback()}")
    }
    debug {
        buildConfigField("boolean", "playCustomRingback", "${playCustomRingback()}")
    }
}

// Specify that we want to split up the APK based on ABI
splits {
    abi {
        // Enable ABI split
        enable true

        // Clear list of ABIs
        reset()

        // Specify each architecture currently supported by the Video SDK
        include "armeabi-v7a", "arm64-v8a", "x86", "x86_64"

        // Specify that we do not want an additional universal SDK
        universalApk false
    }
}

}

dependencies { implementation "com.twilio:audioswitch:${versions.audioSwitch}" implementation "com.twilio:voice-android:${versions.voiceAndroid}" implementation "com.google.android.material:material:${versions.material}" implementation "com.google.firebase:firebase-messaging:${versions.firebase}" implementation "androidx.lifecycle:lifecycle-extensions:${versions.androidxLifecycle}" androidTestImplementation "androidx.test.ext:junit:${versions.junit}"

// added for firebase
implementation platform('com.google.firebase:firebase-bom:30.1.0') // Firebase BoM
implementation 'com.google.firebase:firebase-analytics'

}

apply plugin: 'com.google.gms.google-services'

kbagchiGWC commented 2 years ago

@D-I-S-C

Try replacing you current code in registerForCallInvites() with the code below. Let me know if this fixes your issue. We will look in to updating the QS with this changes.

/*
 * Register your FCM token with Twilio to receive incoming call invites
 */
  private void registerForCallInvites() {
      FirebaseMessaging.getInstance ().getToken ()
              .addOnCompleteListener ( task -> {
                  if (!task.isSuccessful ()) {
                      return;
                  }
                  if (null != task.getResult ()) {
                      String fcmToken = Objects.requireNonNull ( task.getResult () );
                      Log.i(TAG, "Registering with FCM");
                      Voice.register(accessToken, Voice.RegistrationChannel.FCM, fcmToken, registrationListener);
                  }
              } );
    }
D-I-S-C commented 2 years ago

The code is now compiling without errors - thank you! However, when I run it on any kind of emulator using the AVD and make a call as instructed, I hear "we are sorry an application error has occurred", the call is finished and I get the following message on my console (in error logs): "An attempt to retrieve content from https://my-quickstart-dev.twil.io/make-call returned the HTTP status code 404"