rk3326 android 8.1 上传sftp时候jsch类报错(已解决)

https://blog.csdn.net/yhm2046/article/details/105034357

前两天的问题已经解决,做个记录

参考:https://bbs.csdn.net/topics/396196538

https://www.jianshu.com/p/b333f3718373 //Android代码混淆

https://blog.csdn.net/forlong401/article/details/23539123  //ProGuard的作用、使用及bug分析

https://blog.csdn.net/ooo4561213/article/details/7287557 //android 混淆器的使用 proguard.flags

https://blog.csdn.net/zhelong111/article/details/84507657?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task  //Android不混淆第三方jar包

https://blog.csdn.net/wusj3/article/details/93460996  //解决Android 8.0及以上系统接收不到广播的问题

原因:

1.android8.1默认开启了混淆,导致找不到第三方jar包内的方法

2.jsch类网络连接在wifi连接时候会有不流畅问题,加入sleep和for循环解决

原因1解决办法:

修改\frameworks\base\packages\SystemUI\proguard.flags:加入红色代码

-keep class com.android.systemui.statusbar.policy.KeyButtonView {
  public float getDrawingAlpha();
  public void setDrawingAlpha(float);
}
-libraryjars   libs/jsch-0.1.52.jar     
-dontwarn  com.jcraft.jsch.**
-keep class  com.jcraft.jsch.** { *; }
-keep interface  com.jcraft.jsch.** { *; }

-keep class com.android.systemui.statusbar.policy.KeyButtonRipple {
  public float getGlowAlpha();
  public float getGlowScale();
  public void setGlowAlpha(float);
  public void setGlowScale(float);
}

-keep class com.android.systemui.statusbar.car.CarStatusBar
-keep class com.android.systemui.statusbar.phone.StatusBar
-keep class com.android.systemui.statusbar.tv.TvStatusBar
-keep class com.android.systemui.car.CarSystemUIFactory
-keep class com.android.systemui.SystemUIFactory

-keepclassmembers class ** {
    public void onBusEvent(**);
    public void onInterprocessBusEvent(**);
}
-keepclassmembers class ** extends **.EventBus$InterprocessEvent {
    public (android.os.Bundle);
}

-keep class com.android.systemui.recents.views.TaskView {
    public int getDim();
    public void setDim(int);
    public float getTaskProgress();
    public void setTaskProgress(float);
}

-keepclasseswithmembers class * {
    public (android.content.Context, android.util.AttributeSet);
}

-keep class ** extends android.support.v14.preference.PreferenceFragment
-keep class com.android.systemui.tuner.*
-keep class com.android.systemui.plugins.** {
    public protected *;
}
 

修改:frameworks\base\packages\SystemUI\Android.mk

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := SystemUI-proto

LOCAL_SRC_FILES := $(call all-proto-files-under,src)

LOCAL_PROTOC_OPTIMIZE_TYPE := nano
LOCAL_PROTO_JAVA_OUTPUT_PARAMS := optional_field_style=accessors

include $(BUILD_STATIC_JAVA_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := SystemUI-tags

LOCAL_SRC_FILES := src/com/android/systemui/EventLogTags.logtags

include $(BUILD_STATIC_JAVA_LIBRARY)

# ------------------

##LOCAL_DEX_PREOPT := nostripping

include $(CLEAR_VARS)

LOCAL_USE_AAPT2 := true

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-Iaidl-files-under, src)

LOCAL_STATIC_ANDROID_LIBRARIES := \
    SystemUIPluginLib \
    android-support-v4 \
    android-support-v7-recyclerview \
    android-support-v7-preference \
    android-support-v7-appcompat \
    android-support-v7-mediarouter \
    android-support-v7-palette \
    android-support-v14-preference \
    android-support-v17-leanback


LOCAL_STATIC_JAVA_LIBRARIES := \
    jsr305 \
    settings-logtags \
    commons-io-2.6 \
    jsch-0.1.52 \
    slf4j-android-1.7.26 \
    slf4j-api-1.7.26    \
    SystemUI-tags \
    SystemUI-proto

LOCAL_JAVA_LIBRARIES := telephony-common
LOCAL_JAVA_LIBRARIES += android.car

LOCAL_PACKAGE_NAME := SystemUI
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true

LOCAL_PROGUARD_FLAG_FILES := proguard.flags
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res-keyguard $(LOCAL_PATH)/res

ifneq ($(INCREMENTAL_BUILDS),)
    LOCAL_PROGUARD_ENABLED := disabled
    LOCAL_JACK_ENABLED := incremental
    LOCAL_DX_FLAGS := --multi-dex
    LOCAL_JACK_FLAGS := --multi-dex native
endif

include frameworks/base/packages/SettingsLib/common.mk

LOCAL_AAPT_FLAGS := --extra-packages com.android.keyguard

include $(BUILD_PACKAGE)

include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := commons-io-2.6:libs/commons-io-2.6.jar \
                                        jsch-0.1.52:libs/jsch-0.1.52.jar \
                                        slf4j-android-1.7.26:libs/slf4j-android-1.7.26.jar \
                                        slf4j-api-1.7.26:libs/slf4j-api-1.7.26.jar

include $(BUILD_MULTI_PREBUILT)
include $(call all-makefiles-under,$(LOCAL_PATH))
 

问题2解决:

//尝试6次连接网络,确保网络连接成功
        boolean rs=false;
        for(int i=0;i<6;i++){
            rs=sftp.login(1);
            System.out.println(i+" times connect,rs is"+rs);
                   if(rs)    break;    
       }  

    /***
    reload login
    **/
    public boolean login(int i){
        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");   //wangp add sleep();

            Thread.sleep(3000);

            Channel channel = session.openChannel("sftp");
            channel.connect();
            log.info("channel is connected");
            sftp = (ChannelSftp) channel;
            log.info(String.format(TAG+"sftp server host:[%s] port:[%s] is connect successfull", host, port));
            return true;
        } catch (JSchException e) {
            log.error(TAG+"Cannot connect to specified sftp server : {}:{} \n Exception message is: {}", new Object[]{host, port, e.getMessage()});
            log.info(TAG+"make sure the net is connected!!");
            e.printStackTrace();
            return false;            
        } catch(Exception e){
            System.out.println(TAG+"login exception-------------------"+e);
            e.printStackTrace();
            return false;                        
        }
    }

完整补丁:http://gofile.me/4ZJ1m/bBnJywyEy  passwd:123456

你可能感兴趣的:(android,java)