Agora Android 示例应用在启动时崩溃
Posted
技术标签:
【中文标题】Agora Android 示例应用在启动时崩溃【英文标题】:Agora Android example app crashing on launch 【发布时间】:2020-04-21 19:00:03 【问题描述】:我能够编译项目,但它一启动就崩溃了。我已经在物理三星 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);
【问题讨论】:
请提供 gradle.build 文件,以及您的基础应用程序类和启动器活动类文件。 【参考方案1】:SDK在初始化Agora服务时返回ERR_INVALID_APP_ID(101),或者调用joinChannel加入频道时onError回调中报ERR_INVALID_APP_ID(101)错误。
原因:App ID无效,一般是因为App ID的数据格式不正确。
解决方法:检查您的 App ID 的数据格式。确保您使用正确的 App ID 来初始化 Agora 服务。
【讨论】:
【参考方案2】:您是否更改了 string.xml 文件中的 appid?您需要从 Agora 控制台为您的应用程序生成一个 appid。以下是有关如何获取 appid 的说明: https://medium.com/@hermes_11327/how-to-get-started-with-agora-io-c73934bcab2b
【讨论】:
以上是关于Agora Android 示例应用在启动时崩溃的主要内容,如果未能解决你的问题,请参考以下文章
启动 Unity 时应用程序崩溃 - 在 Android Studio 中测试时不会崩溃
VideoCastManager 在手机启动时崩溃 Android 应用程序