问题
I am building an Android app to communicate with a NAO robot so I downloaded the naoqi jar library and added it to my project.
I downloaded the JAR library from the following link:
https://developer.softbankrobotics.com/pepper-naoqi-25-downloads-linux
After that I tried running the code from the link
https://github.com/aldebaran/libqi-java/blob/master/examples/android/RobotTalk/src/com/aldebaran/HelloAndroidActivity.java
The JAR library is included within build.gradle like follows
Hello An additional information on how the JAR file is included within build.grade
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation files('libs\\java-naoqi-sdk-2.5.6.5-linux64 (1).jar')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
I made some changes on the code to look as the following:
package samerrihawi.com.naoapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.aldebaran.qi.AnyObject;
import com.aldebaran.qi.CallError;
import com.aldebaran.qi.Session;
public class MainActivity extends AppCompatActivity {
private Session session = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1=findViewById(R.id.button1);
final EditText mEdit = (EditText)findViewById(R.id.editIP);
final EditText EditPort = (EditText)findViewById(R.id.editPort);
final EditText editSentences = (EditText)findViewById(R.id.editText);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Context context = getApplicationContext();
String url = "tcp://" + mEdit.getText().toString() + ":" + EditPort.getText().toString();
Log.v("com.aldebaran.RobotTalk.connectSD", "Connecting to " + url);
session = new Session();
try
{
session.connect(url).sync();
}
catch (Exception e)
{
Toast toast = Toast.makeText(context, "Connection Error : " + e.getMessage(), Toast.LENGTH_SHORT);
toast.show();
Log.v("com.aldebaran.RobotTalk.connectSD", "Connection Error : " + e.getMessage());
return;
}
Log.v("com.aldebaran.RobotTalk.connectSD", "Trying to get a proxy on serviceTest");
AnyObject proxy;
try {
proxy = session.service("ALTextToSpeech");
} catch (Exception e1) {
Toast toast = Toast.makeText(context, "Cannot get proxy on ALTextToSpeech", Toast.LENGTH_SHORT);
toast.show();
Log.v("com.aldebaran.RobotTalk.connectSD", "Failure ! Cannot get proxy on ALTextToSpeech");
return;
}
try
{
Log.v("com.aldebaran.RobotTalk.connectSD", "Saying : " + editSentences.getText().toString());
proxy.call("say", editSentences.getText().toString());
} catch (CallError e) {
Toast toast = Toast.makeText(context, "Error : " + e.getMessage(), Toast.LENGTH_SHORT);
toast.show();
return;
} catch (Exception e) {
Toast toast = Toast.makeText(context, "Error : " + e.getMessage(), Toast.LENGTH_SHORT);
toast.show();
return;
}
Log.v("com.aldebaran.RobotTalk.connectSD", "Done");
Toast toast = Toast.makeText(context, "Done", Toast.LENGTH_SHORT);
toast.show();
}
});
}
}
And after some trial and error, I found out that the program throws the exception when creating a new object from Session in the following line:
session=new Session();
And I am getting the following stacktrace exception:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: samerrihawi.com.naoapplication, PID: 13347
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/samerrihawi.com.naoapplication-TccpRt1-40ybe5SafG2Riw==/base.apk"],nativeLibraryDirectories=[/data/app/samerrihawi.com.naoapplication-TccpRt1-40ybe5SafG2Riw==/lib/x86, /system/lib, /vendor/lib]]] couldn't find "libgnustl_shared.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:1011)
at java.lang.System.loadLibrary(System.java:1657)
at com.aldebaran.qi.EmbeddedTools.loadEmbeddedLibraries(EmbeddedTools.java:117)
at com.aldebaran.qi.Session.<clinit>(Session.java:16)
at samerrihawi.com.naoapplication.MainActivity$1.onClick(MainActivity.java:41)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24701)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
The source of the exception is within this part of the code
String javaVendor = System.getProperty("java.vendor");
if (javaVendor.contains("Android"))
{
// Using System.loadLibrary will find the libraries automatically depending on the platform,
// but we still need to load the dependencies manually and in the correct order.
System.loadLibrary("gnustl_shared");
System.loadLibrary("qi");
System.loadLibrary("qimessagingjni");
System.out.printf("Libraries loaded. from android\n");
}
I am totally new to NAO programming.
So what must I do in this case to solve this issue ?
Thanks a lot
回答1:
The .jar you use is not compiled for Android, but for Linux 64:
implementation files('libs\\java-naoqi-sdk-2.5.6.5-linux64 (1).jar')
Instead, you must either recompile libqi-java for Android, or try using the one provided along the Qi SDK for Pepper:
add the repository to your root
build.gradle
file:maven { url 'http://android.aldebaran.com/sdk/maven' }
add the dependency in your module's
build.gradle
file (for instanceapp/build.gradle
)implementation 'com.aldebaran:libqi-java-android:3.1.0'
However you managed to embed libqi-java
, do not for get to load the native libraries first by calling, in Java:
new EmbeddedTools().loadEmbeddedLibraries();
Note that the protocol is not guaranteed compatible with NAOqi 2.5.
来源:https://stackoverflow.com/questions/62683433/unsatisfiedlinkerror-for-com-aldebaran-qi