我实现了IBM watson Assistant,它在android调试中工作得很好。当我构建一个签名的apk时,问题就来了。上面总是写着未经授权。我不认为这是关键,因为它在调试模式下工作得很好。我需要一些帮助,因为这个项目正在进行中。到目前为止,我尝试的是在IBM云中更改密钥,并尝试了其他密钥,但它引发了未发现的异常,我认为这是由错误的密钥引起的。我是不是应该允许IBM cloud中的某些东西用于签名的apk?或者是否有来自签名apk的证书,我必须上传到IBM云中?即时通信工具使用IBM watson Assistant v2
private Assistant watsonAssistant;
private Response<SessionResponse> watsonAssistantSession;
private void createServices() {
watsonAssistant = new Assistant("2020-04-01", new IamAuthenticator(getString(R.string.assistant_apikey)));
watsonAssistant.setServiceUrl(getString(R.string.assistant_url));
}
private void sendMessage(){
Thread thread = new Thread(() -> {
try {
if (watsonAssistantSession == null) {
ServiceCall<SessionResponse> call = watsonAssistant.createSession(new CreateSessionOptions.Builder().assistantId(getString(R.string.normal_assistant_id)).build());
watsonAssistantSession = call.execute();
}
MessageInput input = new MessageInput.Builder()
.text(userInput)
.build();
MessageOptions options = new MessageOptions.Builder()
.assistantId(getString(R.string.normal_assistant_id))
.input(input)
.sessionId(watsonAssistantSession.getResult().getSessionId())
.build();
Response<MessageResponse> response = watsonAssistant.message(options).execute();
if (response.getResult().getOutput() != null && !response.getResult().getOutput().getGeneric().isEmpty()) {
List<RuntimeResponseGeneric> responses = response.getResult().getOutput().getGeneric();
for (RuntimeResponseGeneric r : responses) {
switch (r.responseType()) {
case "text":
aiResponse = r.text();
aiConversationList.add(new AIConversation(r.text(), "ai", System.currentTimeMillis()));
break;
default:
Log.e("Error", "Unhandled message type");
}
}
runOnUiThread(() -> {
sendConvoToServer(userInput, aiResponse);
txtWelcomeAI.setVisibility(View.VISIBLE);
aiAdapter.notifyItemInserted(aiConversationList.size() - 1);
userInputTxt.setEnabled(true);
pRecyclerView.scrollToPosition(aiConversationList.size() - 1);
aStatus.setText("online");
});
}
} catch (Exception e) {
e.printStackTrace();
Log.e("IBM_EXCEPTION", e.toString());
aiConversationList.add(new AIConversation("Oops! Something went wrong", "ai", System.currentTimeMillis()));
aiAdapter.notifyItemInserted(aiConversationList.size() - 1);
runOnUiThread(() -> {
pRecyclerView.scrollToPosition(aiConversationList.size() - 1);
aStatus.setText("online");
userInputTxt.setEnabled(true);
});
}
});
thread.start();
}
发布于 2020-04-13 05:16:56
如果其他人在调试和发布apks之间遇到像我这样的问题,试着检查一下你是否做过混淆。如果是这样,那么混淆可能是一个问题。至少对我来说是这样。因此,要么在应用程序级别禁用build.gradle模糊处理,要么在proguard-rules中添加一些规则
https://stackoverflow.com/questions/61172512
复制相似问题