java.lang.RuntimeException: setAudioSource failed

I am confused your title says java.lang.RuntimeException: setAudioSource failed and your stack trace says java.lang.RuntimeException: stop failed.

For java.lang.RuntimeException: setAudioSource failed you might be missing Runtime Permission.

You need to take Manifest.permission.RECORD_AUDIO from user.

public void onRecordBtnClicked() {
  if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO)
      != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.RECORD_AUDIO },
        10);
  } else {
    recordAudio();
  }
}

private void recordAudio() {
  //Record Audio.
}

@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
    @NonNull int[] grantResults) {
  super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  if (requestCode == 10) {
    if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
      recordAudio();
    }else{
      //User denied Permission.
    }
  }
}

I had the exact same problem and managed to fix it by asking for permission to record audio:

if (ActivityCompat.checkSelfPermission(activity(), Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {

    ActivityCompat.requestPermissions(activity(), new String[]{Manifest.permission.RECORD_AUDIO}, BuildDev.RECORD_AUDIO);

} else {

    startRecording();

}

where

BuildDev.RECORD_AUDIO is public static final int RECORD_AUDIO = 0;