简体   繁体   English

在 Android 上安装 Chilkat

[英]Chilkat installation on Android

I'm trying to use chilkat library on an existing app that uses API 16 under Android Studio (macOS - Android Studio 3.5).我正在尝试在 Android Studio (macOS - Android Studio 3.5) 下使用 API 16 的现有应用程序上使用 chilkat 库。 Needs suggestions about how to correctly import the chilkat library in Android Studio.需要有关如何在 Android Studio 中正确导入 chilkat 库的建议。

I need to determine if the library can be used with the application (about some SFTP operations).我需要确定该库是否可以与应用程序一起使用(关于一些 SFTP 操作)。

Following the instructions found on the Chilkat site ( https://www.chilkatsoft.com/chilkatAndroid.asp ) I was able to compile the app including the library.按照 Chilkat 网站 ( https://www.chilkatsoft.com/chilkatAndroid.asp ) 上的说明,我能够编译包括库在内的应用程序。 However, in order to compile the app I had to add the Multidex support in the gradle build for the app :但是,为了编译应用程序,我必须在应用程序的 gradle 构建中添加 Multidex 支持:

........ ........ android { compileSdkVersion 28 buildToolsVersion '27.0.3' defaultConfig { minSdkVersion 16 targetSdkVersion 16 versionCode 72 versionName '1.6.6' multiDexEnabled true <------- added } dexOptions { javaMaxHeapSize "4g" } ......... ......... dependencies { ....... ....... implementation 'com.android.support:multidex:1.0.3' <---- added } ........................ android { compileSdkVersion 28 buildToolsVersion '27.0.3' defaultConfig { minSdkVersion 16 targetSdkVersion 16 versionCode 72 versionName '1.6.6' multiDexEnabled true <-------添加了 } dexOptions { javaMaxHeapSize "4g" } .......................... 依赖项 { .... ....... 实现 'com.android.support :multidex:1.0.3' <---- 添加 }

And the "project structure" of the app is different from the one described in the instructions so I did end up copying the libs files in a jniLibs directory under the /app directory on the project.并且该应用程序的“项目结构”与说明中描述的不同,因此我最终将 libs 文件复制到项目 /app 目录下的 jniLibs 目录中。 The source files were copied into : /app/src/main/java/com/chilatsoft源文件被复制到:/app/src/main/java/com/chilatsoft

On the main application I did included the lib as suggested by the instruction and added the loader.在主应用程序中,我确实按照指令的建议包含了 lib 并添加了加载程序。

In the end I am able to compile the app with no errors, however runtime the app crash indicating that the chilkat library is not found.最后,我能够在没有错误的情况下编译应用程序,但是运行时应用程序崩溃表明未找到 chilkat 库。

java.lang.UnsatisfiedLinkError: Couldn't load chilkat from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/com.symbol.emdk.jar", zip file "/data/app/com.xxxxxxxxxxx.apk"],nativeLibraryDirectories=[/data/app-lib/com.xxxxxxxxxxx, /vendor/lib, /system/lib]]]: findLibrary returned null at java.lang.Runtime.loadLibrary(Runtime.java:358) java.lang.UnsatisfiedLinkError:无法从加载器 dalvik.system.PathClassLoader[DexPathList[[zip 文件“/system/framework/com.symbol.emdk.jar”,zip 文件“/data/app/com.xxxxxxxxxxx”加载 chilkat .apk"],nativeLibraryDirectories=[/data/app-lib/com.xxxxxxxxxxx, /vendor/lib, /system/lib]]]: findLibrary 在 java.lang.Runtime.loadLibrary(Runtime.java:358) 处返回 null

This make me think I did imported the library not correctly.这让我觉得我没有正确导入库。 Any hint/step guide to follow to import chilkat correctly ?正确导入 chilkat 需要遵循的任何提示/步骤指南吗?

Before to buy the license I would like to be sure that the library can be used for the project.在购买许可证之前,我想确保该库可用于该项目。 I can't change API or restart from scratch or change structure of the current app.我无法更改 API 或从头开始或更改当前应用程序的结构。

Thanks for any help !谢谢你的帮助 ! Steve史蒂夫

When your app loads a JNI .so share lib like this:当您的应用加载 JNI .so 时,像这样共享库:

static 
    {
    System.loadLibrary("chilkat");
    }

The Java runtime loader is looking in some list of directories for libchilkat.so Java 运行时加载程序正在查找 libchilkat.so 的一些目录列表

The error message seems to show the list of directories where it's looking:错误消息似乎显示了它正在查找的目录列表:

alvik.system.PathClassLoader[DexPathList[[zip file "/system/framework
/com.symbol.emdk.jar", zip file "/data/app/com.xxxxxxxxxxx.apk"],
nativeLibraryDirectories=[/data/app-lib/com.xxxxxxxxxxx, 
/vendor/lib, /system/lib]]]: findLibrary returned null at
 java.lang.Runtime.loadLibrary(Runtime.java:358)

The directories are:这些目录是:

/data/app-lib/com.xxxxxxxxxxx /data/app-lib/com.xxxxxxxxxxx

/vendor/lib /供应商/库

/system/lib /系统/库

And the libchilkat.so is not in any of them.而 libchilkat.so 不在其中任何一个中。 The libchilkat.so is located in a directory within your project's directory tree. libchilkat.so 位于项目目录树中的一个目录中。 One solution is to move the libchilkat.so to one of those directories.一种解决方案是将 libchilkat.so 移动到这些目录之一。 Another solution is to (somehow) add the directory where the libchilkat.so exists to the list of directories searched.另一种解决方案是(以某种方式)将 libchilkat.so 所在的目录添加到搜索的目录列表中。

Another possible solution is to explicitly load the .so.另一种可能的解决方案是显式加载 .so。 Instead of calling System.loadLibrary("chilkat") where you leave it up to the system to locate the libchilkat.so, call System.load instead of System.loadLibrary .与其调用 System.loadLibrary("chilkat") 来让系统定位 libchilkat.so,不如调用System.load而不是System.loadLibrary (See https://www.chilkatsoft.com/java-loadLibrary-Linux.asp ) But this might be difficult because the .so to be loaded depends on the runtime architecture (armeabi-v7a, x86_64, etc.) (请参阅https://www.chilkatsoft.com/java-loadLibrary-Linux.asp )但这可能很困难,因为要加载的 .so 取决于运行时架构(armeabi-v7a、x86_64 等)

For starters, you need to install and configure the android ndk对于初学者,您需要安装和配置 android ndk

Android developers ndk documentation Android 开发者 ndk 文档

Then you need to include the appropriate .so files然后你需要包含适当的 .so 文件

load .so files in android 在android中加载.so文件

Finally, you need to load the native code with最后,您需要加载本机代码

static 
    {
    System.loadLibrary("chilkat");
    }

Once that is done you can continue with the tutorials完成后,您可以继续学习教程

Official chilkat tutorial examples官方 chilkat 教程示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM