shaqian / flutter_ssh

SSH and SFTP client for Flutter
https://pub.dartlang.org/packages/ssh
MIT License
117 stars 83 forks source link

Error after upgraded to Flutter 1.12 #27

Open JuanM04 opened 4 years ago

JuanM04 commented 4 years ago

For some reason, it does work when I'm debugging; but after I build the production APK, it throws this error:

PlatformException(connection_failure, java.lang.ClassNotFoundException: com.jcraft.jsch.jce.Random, null)
Flutter Doctor ``` [✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.1 19B88, locale en-US) • Flutter version 1.12.13+hotfix.5 at /Users/juanm04/dev/tools/flutter • Framework revision 27321ebbad (6 days ago), 2019-12-10 18:15:01 -0800 • Engine revision 2994f7e1e6 • Dart version 2.7.0 [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2) • Android SDK at /Users/juanm04/Library/Android/sdk • Android NDK location not configured (optional; useful for native profiling support) • Platform android-29, build-tools 29.0.2 • ANDROID_HOME = /Users/juanm04/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405) • All Android licenses accepted. [✗] Xcode - develop for iOS and macOS ✗ Xcode installation is incomplete; a full installation is necessary for iOS development. Download at: https://developer.apple.com/xcode/download/ Or install Xcode via the App Store. Once installed, run: sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer sudo xcodebuild -runFirstLaunch ✗ CocoaPods not installed. CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side. Without CocoaPods, plugins will not work on iOS or macOS. For more info, see https://flutter.dev/platform-plugins To install: sudo gem install cocoapods [✓] Android Studio (version 3.5) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin version 42.1.1 • Dart plugin version 191.8593 • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405) [!] IntelliJ IDEA Ultimate Edition (version 2019.2.4) • IntelliJ at /Applications/IntelliJ IDEA.app ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. • For information about installing plugins, see https://flutter.dev/intellij-setup/#installing-the-plugins [✓] VS Code (version 1.41.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.7.1 [✓] Connected device (1 available) • ONEPLUS A6013 • 192.168.86.123:5555 • android-arm64 • Android 10 (API 29) ```
thomashuettmaier commented 4 years ago

Had the same issues this solved it for me:

JuanM04 commented 4 years ago

@thomashuettmaier Thanks, that worked for me! How can I do it with flutter build apk --split-per-abi?

tc14077 commented 4 years ago

I also encountered this issue. The error log shows:

/flutter/.pub-cache/hosted/pub.dartlang.org/ssh-0.0.5/android/src/main/java/sq/flutter/ssh/SshPlugin.java:404: warning: [unchecked] unchecked conversion
          Vector<LsEntry> files = channelSftp.ls(args.get("path").toString());
                                                ^                       
  required: Vector<ChannelSftp.LsEntry>                                 
  found:    Vector
1 warning  

* What went wrong:                                                      
Execution failed for task ':ssh:verifyReleaseResources'.                
> java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
  myapp/build/ssh/intermediates/res/merged/release/values/values.xml:236: error: resource android:attr/fontVariationSettings not found.
  myapp/build/ssh/intermediates/res/merged/release/values/values.xml:237: error: resource android:attr/ttcIndex not found.
  error: failed linking references.      

Anyone has ideas on it?

thomashuettmaier commented 4 years ago

@thomashuettmaier Thanks, that worked for me! How can I do it with flutter build apk --split-per-abi?

Sorry I don't have an idea how to do that.

JuanM04 commented 4 years ago

I also encountered this issue. The error log shows:

/flutter/.pub-cache/hosted/pub.dartlang.org/ssh-0.0.5/android/src/main/java/sq/flutter/ssh/SshPlugin.java:404: warning: [unchecked] unchecked conversion
          Vector<LsEntry> files = channelSftp.ls(args.get("path").toString());
                                                ^                       
  required: Vector<ChannelSftp.LsEntry>                                 
  found:    Vector
1 warning  

* What went wrong:                                                      
Execution failed for task ':ssh:verifyReleaseResources'.                
> java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
  myapp/build/ssh/intermediates/res/merged/release/values/values.xml:236: error: resource android:attr/fontVariationSettings not found.
  myapp/build/ssh/intermediates/res/merged/release/values/values.xml:237: error: resource android:attr/ttcIndex not found.
  error: failed linking references.      

Anyone has ideas on it?

It says :ssh:verifyReleaseResources, so maybe there is an error when building the APK

Nico04 commented 4 years ago

Any progress on this issue ? The workaround doesn't work for me (or maybe I didn't fully understand it)

JuanM04 commented 4 years ago

I just set API level ≥ 21. My app simply doesn't support Android 4.4 now

Nico04 commented 4 years ago

I just set API level ≥ 21. My app simply doesn't support Android 4.4 now

targetSdkVersion is 28, and minSdkVersion is 18, but I'm testing on Android 9.0, so I don't see the link that this issue may have with minSdkVersion ?

JuanM04 commented 4 years ago

I did that, worked for a while weirdly, and then I stopped using this package

Nico04 commented 4 years ago

I did that, worked for a while weirdly, and then I stopped using this package

You found an alternative ?

JuanM04 commented 4 years ago

No to flutter_ssh, I just found an alternative to solve my particular problem

Diviloper commented 4 years ago

I managed to solve the crash in the production APK by adding the --no-shrink flag to the build:

flutter build apk --no-shrink --split-per-abi

My only guess is that the code shrinker thinks the library is not in use and deletes it Hope it helps

Nico04 commented 4 years ago

The workaround also works for me with appbundle flutter build apk --no-shrink

Any idea how to really fix this ?

zuiwuchang commented 4 years ago

com.jcraft.jsch.jce.Random

i have same problem,but i solved it

first edit android/app/build.gradle enable minifyEnabled and useProguard

 buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.release

            minifyEnabled true
            useProguard true

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

then create android/app/proguard-rules.pro and write class com.jcraft.,my document like this

#Flutter Wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.**  { *; }
-keep class io.flutter.util.**  { *; }
-keep class io.flutter.view.**  { *; }
-keep class io.flutter.**  { *; }
-keep class io.flutter.plugins.**  { *; }
-keep class com.jcraft.**  { *; }
zuiwuchang commented 4 years ago

Any progress on this issue ? The workaround doesn't work for me (or maybe I didn't fully understand it)

https://github.com/shaqian/flutter_ssh/issues/27#issuecomment-599180850

camelChief commented 1 year ago

i have same problem,but i solved it

first edit android/app/build.gradle enable minifyEnabled and useProguard

 buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.release

            minifyEnabled true
            useProguard true

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

then create android/app/proguard-rules.pro and write class com.jcraft.,my document like this

#Flutter Wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.**  { *; }
-keep class io.flutter.util.**  { *; }
-keep class io.flutter.view.**  { *; }
-keep class io.flutter.**  { *; }
-keep class io.flutter.plugins.**  { *; }
-keep class com.jcraft.**  { *; }

If anyone is still struggling with this issue, and this work around didn't fix it for you, try creating the proguard-rules.pro file as stated, but don't edit your build.gradle file. For whatever reason, editing the build.gradle file produced errors for me. While digging, I found this answer https://stackoverflow.com/a/70268820 which states that useProguard is obsolete and will cause Groovy to throw errors. The Android docs https://developer.android.com/studio/build/shrink-code#configuration-files seem to imply that you can still define ProGuard rules to prevent files being removed. So I removed the code from build.gradle that was causing the error and it worked!