java-native-interface

Load a PNG image into Java as BufferedImage through JNI C code

我的未来我决定 提交于 2020-01-02 11:14:06
问题 I have the following problem. I have C code that acquires a PNG image as basically raw data and keeps it in memory. I would like this raw data to be translated to a BufferedImage in Java, through the use of JNI. Does anyone know any way of doing this or has done this before? 回答1: I'll assume you know the basics of how to call functions with JNI. It's not that complicated, although it can be a pain in the ass. If you want to get it done quickly, just write the PNG to a temp file, pass the file

Android - JNI guidelines

空扰寡人 提交于 2020-01-02 08:25:24
问题 I want to incorporate small, lean and mean C-based parser into my Android project. I've done JNI programming in the past but not any type of native (C) development on Android. My plan is to compile C lib into SO and create JNI wrapper around it which I'm going to use in my app. Is this how it can/should be done? Second and most important question - how can I include .so into my APK? Where would it go? 回答1: use Android NDK Download n docs Android NDK 1.6 This will save you from writing JNI

Android - setRequestedOrientation - Activity and views lifecycle

北城余情 提交于 2020-01-02 06:57:28
问题 I'm having some trouble with native code using JNI and I suspect that this is maybe due to a call to setRequestedOrientation() . What happens to the activity when I call setRequestedOrientation() ? Is it just restarted or is it entirely destroyed? Also, what happens the to views? If in onCreate I have : protected void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); try { this.setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE );

Native crash on an Android-Java based app?

强颜欢笑 提交于 2020-01-02 06:24:09
问题 Background My app has 100% code written in Java, it doesn't need to make any heavy operations. The app itself uses only the next libraries, yet non of them have JNI code: ActionBarSherlock google-play-services_lib The problem Today I got a weird crash report, which doesn't show any normal exception information . The report was sent via a "Galaxy S5 (klte)" device, with Android 4.4 . Here's the crash report title: Native crash at /dev/ashmem/dalvik-jit-code-cache in /dev/ashmem/dalvik-jit-code

JNI - UnsatisfiedLinkError - loadLibrary always fails

淺唱寂寞╮ 提交于 2020-01-02 05:21:15
问题 I am attempting to get a simple JNI example working, but no matter what I do, I cannot get it to work using the loadLibrary command. It works perfectly if I specify the absolute path of the .so file and use System.load instead of System.loadLibrary. Here is my directory tree: . |-- - |-- TranslatorWrapper.c |-- TranslatorWrapper.class |-- TranslatorWrapper.cpp |-- TranslatorWrapper.h |-- TranslatorWrapper.java `-- libTranslatorWrapper.so Here is the Java code: public class TranslatorWrapper {

JNI - UnsatisfiedLinkError - loadLibrary always fails

百般思念 提交于 2020-01-02 05:21:03
问题 I am attempting to get a simple JNI example working, but no matter what I do, I cannot get it to work using the loadLibrary command. It works perfectly if I specify the absolute path of the .so file and use System.load instead of System.loadLibrary. Here is my directory tree: . |-- - |-- TranslatorWrapper.c |-- TranslatorWrapper.class |-- TranslatorWrapper.cpp |-- TranslatorWrapper.h |-- TranslatorWrapper.java `-- libTranslatorWrapper.so Here is the Java code: public class TranslatorWrapper {

using JNI AndroidJNI.GetMethodID in unity with string parameters

泪湿孤枕 提交于 2020-01-02 04:34:16
问题 I'm working on unity with android java plugin I was trying to call function from java in unity and it worked successfully. cls_Activity = AndroidJNI.FindClass("com/unity3d/player/UnityPlayer"); fid_Activity = AndroidJNI.GetStaticFieldID(cls_Activity, "currentActivity", "Landroid/app/Activity;"); obj_Activity = AndroidJNI.GetStaticObjectField(cls_Activity, fid_Activity); kdataActivityClass = AndroidJNI.FindClass("com/kdata/unitytest/UnityUrlPlugin"); startAdsMethod = AndroidJNI.GetMethodID

Are all the “Magic” methods on the JVM marked as Native?

穿精又带淫゛_ 提交于 2020-01-02 03:50:11
问题 By "Magic" I mean the methods which have semantics which are not expressed in pure Java. I know all native methods are magic, in that their implementation is provided by the underlying runtime and not by Java bytecodes. Is the reverse true? Are all magic methods native , or are there some magic methods apparently implemented in pure Java, but with some extra help from some JVM-special-casing? The use case is that I want to modify the semantics of Java by instrumenting its bytecodes. All these

write file in memory with java.nio?

て烟熏妆下的殇ゞ 提交于 2020-01-02 03:36:08
问题 With nio it is possible to map an existing file in memory. But is it possible to create it only in memory without file on the hard drive ? I want to mimic the CreateFileMapping windows functions which allow you to write in memory. Is there an equivalent system in Java ? The goal is to write in memory in order for another program ( c ) to read it. 回答1: Have a look at the following. A file is created but this might be as close as your going to get. MappedByteBuffer MappedByteBuffer.load()

Exception Access Violation Java?

别来无恙 提交于 2020-01-02 03:23:08
问题 I'm currently writing a JNI project where I'm getting the following error log when trying to run my Java code. It tells me that the problematic frame is a jvm.dll one, and in trying to isolate the problem, I'm trying to work out where exactly my problem is (in the JVM vs. my native code) I've attached the thread section of the log, and can append the rest if needed. I also tried reinstalling the JVM. A fatal error has been detected by the Java Runtime Environment: EXCEPTION_ACCESS_VIOLATION