rk3326 android 8.1 上传sftp时候jsch类报错

错误log:

compressFiles關閉流成功---》
03-22 18:16:15.824   618  2514 I EvanUtils:wangp: 打包成功
03-22 18:16:15.824   618  2514 I EvanUtils:wangp: compressFiles關閉流成功---》
03-22 18:16:15.829   618  2514 I DataLogActivity:wangp: 打包壓縮主程序關閉zos成功---》
03-22 18:16:15.830   618  2514 I c*.a*.s*.SFTPUtil: sftp connect by host:ota.cndlcd.com username:viomi-client
03-22 18:16:15.831   618  2514 I c*.a*.s*.SFTPUtil: Session is build
03-22 18:16:15.832   618  2514 E c*.a*.s*.SFTPUtil: wp--------->Cannot connect to specified sftp server : ota.cndlcd.com:22 
03-22 18:16:15.832   618  2514 E c*.a*.s*.SFTPUtil:  Exception message is: java.lang.ClassNotFoundException: com.jcraft.jsch.jce.Random
03-22 18:16:15.832   618  2514 I c*.a*.s*.SFTPUtil: wp---------make sure the net is connected!!
03-22 18:16:15.832   618  2514 I DataLogActivity:wangp: 文件存在开始上传
03-22 18:16:15.834   618  2514 I EvanUtils:wangp: ip-->/192.168.28.10
03-22 18:16:15.836   618  2514 I EvanUtils:wangp: strMacAddr-->64:90:C1:69:E3:D3
03-22 18:16:15.837   618  2514 I DataLogActivity:wangp: 要上传的文件:viomi/3326/64_90_C1_69_E3_D3/2020-03-22-18-16-15datalogs.zip
03-22 18:16:15.838   618  2514 W System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.jcraft.jsch.ChannelSftp.cd(java.lang.String)' on a null object reference
03-22 18:16:15.838   618  2514 W System.err:     at com.android.systemui.SFTPUtil.upload(SFTPUtil.java:193)
03-22 18:16:15.838   618  2514 W System.err:     at com.android.systemui.DataLogActivity.uploadDropbox(DataLogActivity.java:174)
03-22 18:16:15.838   618  2514 W System.err:     at com.android.systemui.DataLogActivity$1.run(DataLogActivity.java:88)
03-22 18:16:15.838   618  2514 W System.err:     at java.lang.Thread.run(Thread.java:764)
03-22 18:16:15.838   618  2514 I DataLogActivity:wangp: 上传失败:java.lang.NullPointerException: Attempt to invoke virtual method 'void com.jcraft.jsch.ChannelSftp.cd(java.lang.String)' on a null object reference
03-22 18:16:15.979  1098  1645 I viomi_serial_jni: read first time length =0 tmp=0
03-22 18:16:15.979  1098  1645 E viomi_serial_jni: return read length =0 hex data=
03-22 18:16:15.980  1098  1645 D IotToMcuSerialManager.lambda$subscribeRead$15$IotToMcuSerialManager(L:461): IotToMcuSerialManager To mcu serial read length = 0
03-22 18:16:15.981  1098  1645 E IotToMcuSerialManager.serialReadParse(L:578): IotToMcuSerialManager To mcu serial Read fail, length = 0
03-22 18:16:15.982  1098  1645 E IotToMcuSerialManager.lambda$subscribeRead$16(L:463): IotToMcuSerialManager Attempt to get length of null array
03-22 18:16:16.179  1098  1645 I viomi_serial_jni: read first time length =0 tmp=0
03-22 18:16:16.179  1098  1645 E viomi_serial_jni: return read length =0 hex data=

在jar包下面找到两个Ramdom类:

@aserver:~/rk3326_8.1_0320/frameworks/base/packages/SystemUI/libs$ jar -vtf jsch-0.1.56.jar | grep 'Random'     
   134 Sat Sep 03 18:41:46 CST 2016 com/jcraft/jsch/Random.class
   774 Sat Sep 03 18:41:46 CST 2016 com/jcraft/jsch/jce/Random.class

加入引用还是一样报错:

import com.jcraft.jsch.jce.Random;

关键代码:此代码在android studio sdk25,27上编译正常可以上传,rk3288 7.1平台也正常,就是在rk3326平台报错,更换jar包也一样。相关jar包:http://gofile.me/4ZJ1m/E2uk9hzlw 密码:123456

/**
     * 连接sftp服务器
     *
     * @throws Exception
     */
    public void login(){
        try {
            JSch jsch = new JSch();
            if (privateKey != null) {
                jsch.addIdentity(privateKey);// 设置私钥
                log.info("sftp connect,path of private key file:{}" , privateKey);
            }
            log.info("sftp connect by host:{} username:{}",host,username);
            session = jsch.getSession(username, host, port);
            log.info("Session is build");
            if (password != null) {
                session.setPassword(password);
            }
            Properties config = new Properties();
            config.put("StrictHostKeyChecking", "no");
            session.setConfig(config);
            session.connect();
            log.info("Session is connected");
            Channel channel = session.openChannel("sftp");
            channel.connect();
            log.info("channel is connected");
            sftp = (ChannelSftp) channel;
            log.info(String.format("wp--------->sftp server host:[%s] port:[%s] is connect successfull", host, port));
        } catch (JSchException e) {
            log.error("wp--------->Cannot connect to specified sftp server : {}:{} \n Exception message is: {}", new Object[]{host, port, e.getMessage()});
            log.info("wp---------make sure the net is connected!!");
        }
    }

水平有限,找不出问题出在哪里,请大家指点谢谢。

你可能感兴趣的:(android)