speed2o7
speed2o7

Reputation: 23

Agora Android example app crashing on launch

I am able to get the project compiling but it crashes as soon as it launches. I've tested this on a physical Samsung Galaxy S8 and an emulated Pixel 3. Both produce the same results.

It seems to be crashing on line 15 in AGApplication.java.

mWorkerThread.start();

It produces the error:

E/AndroidRuntime: FATAL EXCEPTION: Thread-6
    Process: io.agora.openlive.voice.only, PID: 13997
    java.lang.RuntimeException: NEED TO check rtc sdk init fatal error
    java.lang.IllegalArgumentException: cannot initialize Agora Rtc Engine, error=101
        at io.agora.rtc.internal.RtcEngineImpl.nativeObjectInit(Native Method)
        at io.agora.rtc.internal.RtcEngineImpl.<init>(RtcEngineImpl.java:185)
        at io.agora.rtc.RtcEngine.create(RtcEngine.java:65)
        at io.agora.openlive.voice.only.model.WorkerThread.ensureRtcEngineReadyLock(WorkerThread.java:183)
        at io.agora.openlive.voice.only.model.WorkerThread.run(WorkerThread.java:97)

        at io.agora.openlive.voice.only.model.WorkerThread.ensureRtcEngineReadyLock(WorkerThread.java:186)
        at io.agora.openlive.voice.only.model.WorkerThread.run(WorkerThread.java:97)

I have tried integrating the SDK through JCenter using the provided Gradel configuration as well as manually integrating the SDK that I downloaded from Agora.

build.gradle:

apply plugin: 'com.android.application'

repositories {
    jcenter()
}

android {
    compileSdkVersion 26

    defaultConfig {
        applicationId "io.agora.openlive.voice.only"
        minSdkVersion 16 // ICE_CREAM_SANDWICH
        targetSdkVersion 26
        versionCode 19
        versionName "x.y.z"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'org.slf4j:slf4j-api:1.7.21'
    implementation 'com.github.tony19:logback-android-core:1.1.1-4'
    implementation('com.github.tony19:logback-android-classic:1.1.1-4') {
        // workaround issue #73
        exclude group: 'com.google.android', module: 'android'
    }

    implementation 'io.agora.rtc:full-sdk:3.0.0'

    androidTestImplementation 'com.jayway.android.robotium:robotium-solo:5.6.3'
}

AGApplication.java

package io.agora.openlive.voice.only;

import android.app.Application;

import io.agora.openlive.voice.only.model.CurrentUserSettings;
import io.agora.openlive.voice.only.model.WorkerThread;

public class AGApplication extends Application {

    private WorkerThread mWorkerThread;

    public synchronized void initWorkerThread() {
        if (mWorkerThread == null) {
            mWorkerThread = new WorkerThread(getApplicationContext());
            mWorkerThread.start();

            mWorkerThread.waitForReady();
        }
    }

    public synchronized WorkerThread getWorkerThread() {
        return mWorkerThread;
    }

    public synchronized void deInitWorkerThread() {
        mWorkerThread.exit();
        try {
            mWorkerThread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        mWorkerThread = null;
    }

    public static final CurrentUserSettings mAudioSettings = new CurrentUserSettings();
}

MainActivity.java:

package io.agora.openlive.voice.only.ui;

import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;

import io.agora.openlive.voice.only.R;
import io.agora.openlive.voice.only.model.ConstantApp;
import io.agora.rtc.Constants;

public class MainActivity extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void initUIandEvent() {
        EditText v_room = (EditText) findViewById(R.id.room_name);
        v_room.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                boolean isEmpty = TextUtils.isEmpty(s.toString());
                findViewById(R.id.button_join).setEnabled(!isEmpty);
            }
        });

        String lastChannelName = vSettings().mChannelName;
        if (!TextUtils.isEmpty(lastChannelName)) {
            v_room.setText(lastChannelName);
            v_room.setSelection(lastChannelName.length());
        }
    }

    @Override
    protected void deInitUIandEvent() {
    }

    @Override
    public boolean onCreateOptionsMenu(final Menu menu) {
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return super.onOptionsItemSelected(item);
    }

    public void onClickJoin(View view) {
        // show dialog to choose role
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.msg_choose_role);
        builder.setNegativeButton(R.string.label_audience, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                MainActivity.this.forwardToLiveRoom(Constants.CLIENT_ROLE_AUDIENCE);
            }
        });
        builder.setPositiveButton(R.string.label_broadcaster, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                MainActivity.this.forwardToLiveRoom(Constants.CLIENT_ROLE_BROADCASTER);
            }
        });
        AlertDialog dialog = builder.create();

        dialog.show();
    }

    public void forwardToLiveRoom(int cRole) {
        final EditText v_room = (EditText) findViewById(R.id.room_name);
        String room = v_room.getText().toString();

        Intent i = new Intent(MainActivity.this, LiveRoomActivity.class);
        i.putExtra(ConstantApp.ACTION_KEY_CROLE, cRole);
        i.putExtra(ConstantApp.ACTION_KEY_ROOM_NAME, room);

        startActivity(i);
    }
}

Upvotes: 2

Views: 3510

Answers (2)

Sai
Sai

Reputation: 15738

The SDK returns ERR_INVALID_APP_ID(101) when initializing the Agora service, or reports the ERR_INVALID_APP_ID(101) error in the onError callback when you try to join a channel by calling joinChannel.

Reason: The App ID is invalid, usually because the data format of the App ID is incorrect.

Solution: Check the data format of your App ID. Ensure that you use the correct App ID to initialize the Agora service.

Upvotes: 4

Shaocheng Yang
Shaocheng Yang

Reputation: 312

have you changed the appid in the string.xml file? You need to generate an appid from Agora console for you application. Here is the instruction about how to get an appid: https://medium.com/@hermes_11327/how-to-get-started-with-agora-io-c73934bcab2b

Upvotes: 0

Related Questions