Agora Android 示例应用程序在启动时崩溃

Agora Android example app crashing on launch

我能够编译项目,但它一启动就崩溃了。我已经在实体三星 Galaxy S8 和模拟 Pixel 3 上对此进行了测试。两者产生相同的结果。

它似乎在 AGApplication.java 中的第 15 行崩溃了。

mWorkerThread.start();

它产生错误:

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)

我已经尝试使用提供的 Gradel 配置通过 JCenter 集成 SDK 以及手动集成我从 Agora 下载的 SDK。

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);
    }
}

你有没有更改string.xml文件中的appid?您需要从 Agora 控制台为您的应用程序生成一个 appid。以下是有关如何获取 appid 的说明: https://medium.com/@hermes_11327/how-to-get-started-with-agora-io-c73934bcab2b

SDK returns ERR_INVALID_APP_ID(101) 初始化 Agora 服务时,或尝试加入频道时在 onError 回调中报 ERR_INVALID_APP_ID(101) 错误调用 joinChannel.

原因:App ID无效,一般是App ID的数据格式不正确。

解决方法:检查您的App ID的数据格式。请确保您使用正确的 App ID 来初始化 Agora 服务。