1

I'm developing video conference app, so i need to create a independent rooms for users for conference. so i'm using opentok (tokbox) sdk for android. below are my gradle compile files for opentok :

compile 'com.opentok.android:opentok-android-sdk:2.12.0'
compile 'com.tokbox:opentok-server-sdk:2.3.2'

Now i am genereate session id and token id with the help of opentok server sdk (java). this is the code for generating session id and token id.

//java code
OpenTok openTok = new OpenTok(Integer.parseInt(OpenTokConfig.API_KEY), OpenTokConfig.SECRET_KEY);
try {
     SessionProperties sessionProperties = new SessionProperties.Builder().mediaMode(MediaMode.ROUTED).build();
     Session session = openTok.createSession(sessionProperties);
     sessionId = session.getSessionId();
     //successfully we got the session id here
     tokenId = openTok.generateToken(sessionId); //app crashed here
} catch (OpenTokException e) {
     e.printStackTrace();
}

After debugging this code, we got the session id successfully, but i have facing the problem in generating tokenid.App is crashed suddenly at this point, it returns

`Caused by: java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.decodeBase64
at com.opentok.util.Crypto.decodeSessionId(Crypto.java:47)
at com.opentok.OpenTok.generateToken(OpenTok.java:131)
at com.opentok.OpenTok.generateToken(OpenTok.java:181)`

I had going in depth debugging into opentok sdk the app crashed in this method

//class name is : Crypto
public static List<String> decodeSessionId(String sessionId) throws UnsupportedEncodingException {
    sessionId = sessionId.substring(2);
    sessionId = sessionId.replaceAll("-", "+").replaceAll("_", "/");
    byte[] buffer = Base64.decodeBase64(sessionId); //app crashed in this line
    sessionId = new String(buffer, "UTF-8");
    return new ArrayList<String>(Arrays.asList(sessionId.split("~")));
}

I know the problem is related to decode issue.I had searched about this issue in so many places, but i had not getting any related answers about this issue.Opentok team simply says upgrade your sdk's. Please give the right direction.

saw303
  • 8,051
  • 7
  • 50
  • 90
krish
  • 131
  • 1
  • 1
  • 9
  • Already i had added into to gradle file, compile 'commons-codec:commons-codec:1.10', but no luck – krish Nov 15 '17 at 11:12

1 Answers1

1

This is the same as this problem Apache Commons Codec with Android: could not find method

The OpenTok Java SDK is meant to be used in a Server-Side application, not in your Android application because otherwise you compromise your API Secret. Someone could take it and use it to create their own OpenTok Sessions and you get the bill. The recommended way to do this is to have a server-side API that you call from your Android application to fetch a sessionId and token.

If you still want to get this to work in your Android app you might be able to include commons-codec 1.4+ to get this method. Otherwise you might need to fork the OpenTok Java SDK and have it use an older version of the Base64.decodeBase64 method that takes a byte[] instead of a String.

Adam Ullman
  • 1,517
  • 7
  • 12
  • 1
    Hi adam, we moved to server side api for getting opentok session id and token id, i think this is the simple way. Guys don't generate server side session and token ids in android app. – krish Nov 17 '17 at 10:40