• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Could not find class 'com.jcraft.jsch.JSch', referenced from method

Deemar

Newbie
Feb 7, 2012
38
2
I'm attempting to follow the very simple SSH tutorial located here and when I run it, I get the following error from Logcat.

05-27 22:45:10.498: E/dalvikvm(571): Could not find class 'com.jcraft.jsch.JSch', referenced from method ssh.test.two.Sshtest2Activity.executeRemoteCommand

I see the emulated device, my application opens on the emulated device but it's a blank screen, I don't get any sort of output on the emulated device. No errors, just this one in Logcat.

After copying the code from that tutorial, I added the JRE dependencies for JSCH into a folder I made named "lib" and then right clicked the JSCH one, clicked Build Path and clicked Add To Build Path. There were no errors in the code, here is the whole thing if you want to take a look.

Code:
package ssh.test.two;

import java.io.ByteArrayOutputStream;
import java.util.Properties;

import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

import android.app.Activity;

public class Sshtest2Activity extends Activity {
	public static String executeRemoteCommand(
            String username,
            String password,
            String hostname,
            int port) throws Exception {     

JSch jsch = new JSch();
Session session = jsch.getSession("username", "192.168.0.121", 22);
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("ls");
channelssh.connect();        
channelssh.disconnect();

return baos.toString();
}
}

and

Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ssh.test.two"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="15" />
 <uses-permission android:name="android.permission.INTERNET" />
    
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".Sshtest2Activity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

I did edit out the username and password when pasting this code here, mine has the actual username and password in it. And they are correct, I use SSH all the time inside my network.
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones