我可以编译该项目,但是启动后它就会崩溃。我已经在实际的三星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);
}
}
最佳答案
初始化Agora服务时,SDK返回ERR_INVALID_APP_ID(101),或者当您尝试通过调用joinChannel加入通道时,在onError回调中报告ERR_INVALID_APP_ID(101)错误。
原因:应用程序ID无效,通常是因为应用程序ID的数据格式不正确。
解决方案:检查您的App ID的数据格式。确保使用正确的App ID初始化Agora服务。