[英]Cannot get to work .so shared library in android project
Absolutely new to android development and java so problem may be trivial, but I already confused about what to try or read or google next so please help. android开发和java绝对是新手,所以问题可能微不足道,但我已经对尝试或阅读的内容或google感到困惑,因此请提供帮助。 Trying to create an application that should be doing some batch processing on selected set of images.
试图创建一个应用程序,该应用程序应该对选定的图像集进行一些批处理。 Found a library that perfectly suit my needs, connected it and wrote a simple test, that had to check out if everything works as it should:
找到了一个完全适合我需要的库 ,将其连接起来并编写了一个简单的测试,该程序必须检查一切是否正常运行:
if (requestCode == SELECT_PICTURE && resultCode == RESULT_OK && null != data) {
Uri selectedImageUri = data.getData();
m_ImagePath = getRealPathFromUri(selectedImageUri);
try {
m_MagickImage = new MagickImage(new ImageInfo(m_ImagePath));
m_EffectImage = m_MagickImage.rotateImage(90);
m_Bitmap = MagickBitmap.ToReducedBitmap(m_EffectImage, 1000);
} catch (MagickException e) {
Log.d(LOGTAG, e.toString());
}
ImageView imageview = (ImageView) findViewById(R.id.imageView);
imageview.setImageBitmap(m_Bitmap);
//imageview.setImageURI(selectedImageUri);
openFileButton.setVisibility(View.GONE);
}
Project builds completely fine with no warnings, but when I deployed it on real hardware and clicked button assigned to written test, I got the following error in logcat: 项目构建完全正常,没有警告,但是当我将其部署在真实硬件上并单击分配给书面测试的按钮时,在logcat中出现以下错误:
JNI DETECTED ERROR IN APPLICATION: GetStringUTFChars received NULL jstring
in call to GetStringUTFChars
from void magick.ImageInfo.setFileName(java.lang.String)
"main" prio=5 tid=1 Runnable
And 200 strings more of system information and warnings (don't think they are important but can provide everything needed on demand). 还有200多个系统信息和警告字符串(不要认为它们很重要,但可以按需提供所需的一切)。
Also after that run i got plenty of red warnings like 而且在那次奔跑之后,我收到了很多红色警告,例如
cannot resolve corresponding jni function Java_magick_ImageInfo_setFileName
In almost every java file related to Android-Imagemagick. 在几乎所有与Android-Imagemagick相关的Java文件中。
Library was connected as .jar file, following instructions I found in this thread. 按照我在此线程中找到的说明,将库连接为.jar文件。 Here's my setup:
这是我的设置:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
testCompile 'junit:junit:4.12'
}
and 和
sourceSets {
main {
java.srcDirs = ['src/main/java']
}
}
In build.gradle. 在build.gradle中。
armeabi.jar with .so files in 'libs' directory in root of project, 'fakeawt' and 'magick' folders with wrapper classes in 'src/main/java', and armeabi.jar,在项目根目录的'libs'目录中具有.so文件,在'src / main / java'中具有包装类的'fakeawt'和'magick'文件夹,以及
static {
System.loadLibrary("imagemagick");
}
At the beginning of Main.java. 在Main.java的开头。
Any idea what might go wrong and how to fix it properly? 任何想法可能出什么问题以及如何正确解决?
I suggest if your using Android studio follow the project structure: App |->src |->jnilibs here copy all the folders same as from https://github.com/paulasiimwe/Android-ImageMagick/tree/master/libs and paste into jnilibs(libs) than add follow line in app build.gradle 我建议您使用的Android Studio是否遵循项目结构:App |-> src |-> jnilibs在此处复制与https://github.com/paulasiimwe/Android-ImageMagick/tree/master/libs相同的所有文件夹并粘贴到jnilibs(libs)中,然后在应用程序build.gradle中添加跟随行
sourceSets.main {
jniLibs.srcDir 'src/main/libs' // use the jni .so compiled from the manual ndk-build command
jni.srcDirs = [] //disable automatic ndk-build call
}
sync gradle 同步gradle
don't copy jni files in your project ,It is for your custom changes in library. 不要在您的项目中复制jni文件,这是为了您在库中进行自定义更改。 Set NDK path from the settings.
从设置中设置NDK路径。
Sorry, the issue wasn't relevant to ndk or shared library. 抱歉,该问题与ndk或共享库无关。 It was just deprecated getRealPathFromUri() function, that always returns NULL value when used with modern android 5+ image chooser.
它只是不推荐使用的getRealPathFromUri()函数,与现代android 5+图像选择器一起使用时始终返回NULL值。
Also passing NULL pointer to JNI method always causes segfault for some reason, so these values must be verified in advance. 另外,由于某种原因,将NULL指针传递给JNI方法总是会导致段错误,因此必须事先验证这些值。
Solved by replacing appropriate functions according to this answer and creating if-else statement to check if returned real Path to file is not NULL. 通过根据此答案替换适当的函数并创建if-else语句来检查返回的真实文件路径是否为NULL来解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.