0
我已經關注了構建ssh應用程序的一些在線教程,但不幸的是生成的應用程序編譯並生成良好,但無法正常運行。我試圖連接到運行Ubuntu的聯想TAB A7的電腦。使用的IDE是android studio。計算機安裝了ssh服務器,並且之前已經通過其他計算機的SSH通過控制器進行控制。我放入這個應用程序的任何命令都不起作用。我沒有觸及佈局文件,因爲此刻我只是試圖發送ssh命令,所以它只是在hello world默認情況下。任何幫助真的會很感激!從Android應用程序到計算機的SSH連接
Android清單文件如下:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="robotics.c">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:hardwareAccelerated="true"
android:theme="@style/AppTheme">
<activity android:name="main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
而且活動的java文件如下:
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import java.io.ByteArrayOutputStream;
import java.util.Properties;
public class mainmenu extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainmenu);
new AsyncTask<Integer, Void, Void>() {
@Override
protected Void doInBackground(Integer... params) {
try {
executeRemoteCommand("d46", "password", "192.168.0.209", 22);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}.execute(1);
}
public static String executeRemoteCommand(String username, String password, String hostname, int port)
throws Exception {
JSch jsch = new JSch();
Session session = jsch.getSession(username, hostname, port);
session.setPassword(password);
// Avoid asking for key confirmation
Properties prop = new Properties();
prop.put("StrictHostKeyChecking", "no");
session.setConfig(prop);
session.connect();
// SSH Channel
ChannelExec channelssh = (ChannelExec)
session.openChannel("exec");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
channelssh.setOutputStream(baos);
// Execute command
channelssh.setCommand("nohup python /home/d46/catkin_ws/control/py_script/controller_walking.py");
//System.out.print("cd /home/pi/Desktop | nohup python red.py");
channelssh.connect();
channelssh.disconnect();
return baos.toString();
}
的logcat的輸出如下:
08-03 10:03:30.599 21960-21960/? E/cutils: to chown(/mnt/shell/emulated/0, 0, 0)
08-03 10:03:30.600 21960-21960/? E/cutils: to chown(/mnt/shell/emulated/obb, 0, 0)
08-03 10:03:30.601 21960-21960/? E/cutils: to chown(/storage/emulated/0/Android, 0, 0)
08-03 10:03:30.602 21960-21960/? E/cutils: to chown(/storage/emulated/0/Android/obb, 0, 0)
08-03 10:03:30.635 21960-21960/robotics.c E/Trace: error opening trace file: No such file or directory (2)
08-03 10:03:30.681 21960-21960/robotics.cW/asset: AssetManager-->addDefaultAssets CIP path not exsit!
08-03 10:03:30.699 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve interface method 16064: Landroid/view/Window$Callback;.onProvideKeyboardShortcuts (Ljava/util/List;Landroid/view/Menu;I)V
08-03 10:03:30.699 21960-21960/robotics.c W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
08-03 10:03:30.699 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve interface method 16066: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
08-03 10:03:30.699 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve interface method 16070: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
08-03 10:03:30.700 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve virtual method 477: Landroid/content/res/TypedArray;.getChangingConfigurations()I
08-03 10:03:30.701 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve virtual method 499: Landroid/content/res/TypedArray;.getType (I)I
08-03 10:03:30.709 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve virtual method 268: Landroid/content/Context;.createDeviceProtectedStorageContext()Landroid/content/Context;
08-03 10:03:30.710 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve virtual method 273: Landroid/content/Context;.getCodeCacheDir()Ljava/io/File;
08-03 10:03:30.710 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve virtual method 274: Landroid/content/Context;.getColor (I)I
08-03 10:03:30.710 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve virtual method 275: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
08-03 10:03:30.710 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve virtual method 277: Landroid/content/Context;.getDataDir()Ljava/io/File;
08-03 10:03:30.710 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve virtual method 278: Landroid/content/Context;.getDrawable (I)Landroid/graphics/drawable/Drawable;
08-03 10:03:30.711 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve virtual method 280: Landroid/content/Context;.getExternalCacheDirs()[Ljava/io/File;
08-03 10:03:30.711 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve virtual method 282: Landroid/content/Context;.getExternalFilesDirs (Ljava/lang/String;)[Ljava/io/File;
08-03 10:03:30.711 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve virtual method 285: Landroid/content/Context;.getNoBackupFilesDir()Ljava/io/File;
08-03 10:03:30.711 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve virtual method 287: Landroid/content/Context;.getObbDirs()[Ljava/io/File;
08-03 10:03:30.711 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve virtual method 298: Landroid/content/Context;.isDeviceProtectedStorage()Z
08-03 10:03:30.747 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve virtual method 16496: Landroid/widget/FrameLayout;.startActionModeForChild (Landroid/view/View;Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
08-03 10:03:30.755 21960-21960/robotics.cW/dalvikvm: VFY: unable to resolve virtual method 275: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
08-03 10:03:30.761 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve virtual method 440: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
08-03 10:03:30.761 21960-21960/robotics.c W/dalvikvm: VFY: unable to resolve virtual method 442: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
08-03 10:03:30.775 21960-21960/robotics.c E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
08-03 10:03:30.775 21960-21960/robotics.cW/dalvikvm: VFY: unable to resolve instanceof 148 (Landroid/graphics/drawable/RippleDrawable;) in Landroid/support/v7/widget/AppCompatImageHelper;
08-03 10:03:30.843 21960-21960/robotics.c E/linker: load_library(linker.cpp:759): library "libmaliinstr.so" not found
[ 08-03 10:03:30.845 21960:0x55c8 E/ ]
appName=robotics.c, acAppName=com.android.cts.openglperf
[ 08-03 10:03:30.845 21960:0x55c8 E/ ]
0
[ 08-03 10:03:30.845 21960:0x55c8 E/ ]
appName=robotics.c, acAppName=com.android.browser
[ 08-03 10:03:30.845 21960:0x55c8 E/ ]
0
08-03 10:05:00.907 21960-21981/robotics.c W/System.err: com.jcraft.jsch.JSchException: java.net.SocketTimeoutException: failed to connect to /192.168.0.201 (port 22) after 90000ms
08-03 10:05:00.908 21960-21981/robotics.c W/System.err: at com.jcraft.jsch.Util.createSocket(Util.java:349)
08-03 10:05:00.908 21960-21981/robotics.c W/System.err: at com.jcraft.jsch.Session.connect(Session.java:215)
08-03 10:05:00.910 21960-21981/robotics.c W/System.err: at com.jcraft.jsch.Session.connect(Session.java:183)
08-03 10:05:00.910 21960-21981/robotics.c W/System.err: at robotics.c.mainmenu.executeRemoteCommand(mainmenu.java:44)
08-03 10:05:00.910 21960-21981/robotics.c W/System.err: at rrobotics.c.mainmenu$1.doInBackground(mainmenu.java:24)
08-03 10:05:00.911 21960-21981/robotics.c W/System.err: at robotics.c.mainmenu$1.doInBackground(mainmenu.java:20)
08-03 10:05:00.911 21960-21981/robotics.c W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:287)
08-03 10:05:00.911 21960-21981/robotics.c W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:234)
08-03 10:05:00.911 21960-21981/robotics.c W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
08-03 10:05:00.914 21960-21981/robotics.c W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
08-03 10:05:00.915 21960-21981/robotics.c W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
08-03 10:05:00.916 21960-21981/robotics.c W/System.err: at java.lang.Thread.run(Thread.java:838)
08-03 10:05:00.916 21960-21981/robotics.c W/System.err: Caused by: java.net.SocketTimeoutException: failed to connect to /192.168.0.201 (port 22) after 90000ms
08-03 10:05:00.917 21960-21981/robotics.c W/System.err: at libcore.io.IoBridge.connectErrno(IoBridge.java:176)
08-03 10:05:00.918 21960-21981/robotics.cW/System.err: at libcore.io.IoBridge.connect(IoBridge.java:112)
08-03 10:05:00.918 21960-21981/robotics.c W/System.err: at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
08-03 10:05:00.918 21960-21981/robotics.c W/System.err: at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
08-03 10:05:00.918 21960-21981/robotics.c W/System.err: at java.net.Socket.startupSocket(Socket.java:578)
08-03 10:05:00.918 21960-21981/robotics.c W/System.err: at java.net.Socket.tryAllAddresses(Socket.java:130)
08-03 10:05:00.919 21960-21981/robotics.c W/System.err: at java.net.Socket.<init>(Socket.java:180)
08-03 10:05:00.919 21960-21981/robotics.c W/System.err: at java.net.Socket.<init>(Socket.java:152)
08-03 10:05:00.919 21960-21981/robotics.c W/System.err: at com.jcraft.jsch.Util.createSocket(Util.java:343)
08-03 10:05:00.919 21960-21981/robotics.c W/System.err: ... 11 more
應該有一個庫(本機),無法加載/位於'庫「libmaliinstr.so」未找到「,也未能連接錯誤'90000ms後無法連接到/192.168.0.201(端口22) '可能是由上面提到的問題引起的 – Yazan
我讀過一些手機/平板電腦沒有包含該庫,它不會影響應用程序的運行 - 感謝您的響應!仍然完全卡住:( – Liz
看起來像它的硬件https://stackoverflow.com/questions/25589959/library-libmaliinstr-so-not-found – Yazan