#jni — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #jni, aggregated by home.social.
-
Создаем Java обертку для C++ класса в Android приложении, а также реализуем обратные вызовы из нэйтива
Кратко расскажу о себе и о том, зачем возникла необходимость в подобном. Я более десяти лет пишу приложения под Android, около 5 лет под IOS, и сейчас переношу свои наработки под десктопы. Приложения мои предназначены для сисадминов, это SSH клиент, сетевые сканеры и тд. В общем, самое сложное - не сам интерфейс, а то, что под капотом. Когда я лишь начинал, я думал, что остановлюсь на платформе Android и стал пилить все на Java. Но затем осознал свою ошибку и исправил ее. На данный момент все мои приложения состоят из двух частей: общего для всех систем ядра на С++ и платформозависимого интерфейса, написанного на Java/Swift/C++ в зависимости от системы. Оговорюсь сразу, эта статья будет лишь своего рода вступлением. Я покажу, как работать с объектно-ориентированным кодом на C++ в Java оболочке (в JNI нам доступен экспорт С функций). Инициализировать объект, делать из него вызовы, удалять, при этом имея аналогичный класс в оболочке, будто бы наш код был написан на Java. Задача эта не слишком сложная, но прежде чем опытные прогеры закрыли эту статью, я оговорюсь, что в следующей части мы уже будем работать с каллбэками - вызовами Java листенеров из нашего С++ кода, а вот это уже задача совсем нетривиальная, требующая понимания работы JNI и Dalvik. Но обо всем по порядку. Итак, у нас есть некий CPP класс и Java оболочка. Через JNI мы можем вызывать только С-функции, то есть не объектный код. Так как же нам работать с ООП? Главная проблема - не столько вызовы, сколько хранение адреса объекта нативного класса. Лично для себя я нашел решение - хранить его в Java классе, как long. То есть, у нас получается приблизительно такой код:
-
“Is it worth to run #Java on #ARM?” If your stack depends on old #JNI libraries, the answer may be complicated. @ArturSkowronski outlines the main migration blockers & possible workarounds. Want the decision framework?
Read here: https://javapro.io/2025/12/05/is-it-worth-to-run-java-on-arm-trust-me-this-is-interesting-question/
@awscloud #performance
-
“Is it worth to run #Java on #ARM?” If your stack depends on old #JNI libraries, the answer may be complicated. @ArturSkowronski outlines the main migration blockers & possible workarounds. Want the decision framework?
Read here: https://javapro.io/2025/12/05/is-it-worth-to-run-java-on-arm-trust-me-this-is-interesting-question/
@awscloud #performance
-
Jextract : "jextract is a tool which mechanically generates Java bindings from native library headers. This tools leverages the clang C API in order to parse the headers associated with a given native library, and the generated Java bindings build upon the Foreign Function & Memory API."
-
Jextract : "jextract is a tool which mechanically generates Java bindings from native library headers. This tools leverages the clang C API in order to parse the headers associated with a given native library, and the generated Java bindings build upon the Foreign Function & Memory API."
-
Getting GPS coordinates from Android through Go wasn't easy, but it's done. It's straightforward when you get the JNI weirdness, but it's a lot of boilerplate and hard to debug.
I'll try to integrate directly it into Fyne with a nice API in the future.
-
Getting GPS coordinates from Android through Go wasn't easy, but it's done. It's straightforward when you get the JNI weirdness, but it's a lot of boilerplate and hard to debug.
I'll try to integrate directly it into Fyne with a nice API in the future.
-
Погружение в JNI: проблемы и решения при взаимодействии между JVM и нативным кодом
Привет! Меня зовут Геннадий Денисов, я руковожу одной из команд разработки мобильного Яндекс Браузера для Android. Недавно в рамках одного проекта мы интегрировали С++‑код в мобильное приложение Браузера. В этой статье я поделюсь основными нюансами работы с Java Native Interface (JNI), инструментами для упрощения разработки и подробностями нашего подхода.
-
🚀🔧 Ah yes, the classic "let's duct-tape #Rust onto Java" strategy—you know, because nothing says "I'm a serious developer" like turning a memory-safe language into a DIY memory management nightmare. 🤦♂️ Ever wonder where your weekends went? They're now spent deciphering #JNI error messages! 😂
https://medium.com/@greptime/how-to-supercharge-your-java-project-with-rust-a-practical-guide-to-jni-integration-with-a-86f60e9708b8 #Java #DuctTape #MemoryManagement #DeveloperHumor #HackerNews #ngated -
🚀🔧 Ah yes, the classic "let's duct-tape #Rust onto Java" strategy—you know, because nothing says "I'm a serious developer" like turning a memory-safe language into a DIY memory management nightmare. 🤦♂️ Ever wonder where your weekends went? They're now spent deciphering #JNI error messages! 😂
https://medium.com/@greptime/how-to-supercharge-your-java-project-with-rust-a-practical-guide-to-jni-integration-with-a-86f60e9708b8 #Java #DuctTape #MemoryManagement #DeveloperHumor #HackerNews #ngated -
For most of my career I have stayed in the Java space and not strayed into native code, recently I have been experimenting with those two worlds coming together include with the new Foreign Function APIs.
This is just a record of my experimentation so far but in case someone finds it useful I have published as a blog post https://lofthouse.dev/2025/03/29/beginning-native-java-development/
-
#Android friends, how do you unit test your #JNI / #KNI code? Do you write extra KNI glue just so you can trigger internal native methods that call back out into #Kotlin?
Do you restrict yourself to only integration tests and black-box tests and just *not* unit-test this stuff?
All solutions we’ve tried/considered so far kinda feel bad.
(I'm mostly dealing with C/C++ and Kotlin)
-
#Android friends, how do you unit test your #JNI / #KNI code? Do you write extra KNI glue just so you can trigger internal native methods that call back out into #Kotlin?
Do you restrict yourself to only integration tests and black-box tests and just *not* unit-test this stuff?
All solutions we’ve tried/considered so far kinda feel bad.
(I'm mostly dealing with C/C++ and Kotlin)
-
[Перевод] Кофе и крабы. Вызов Rust-кода из Java
Java — один из наиболее часто используемых языков программирования, который мы еще не обсуждали в нашем Rust Interop Guide . В этой статье мы рассмотрим три различных метода вызова кода Rust из Java : JNI , JNR-FFI и Project Panama . Мы покажем различия между этими методами и проведем базовый бенчмаркинг для сравнения их производительности. Эти методы работают не только для Java , но и для других языков JVM, таких как Kotlin . Здесь мы в основном сосредоточимся на Java , но примеры Kotlin доступны в ветке Kotlin нашего репозитория GitHub . Эта статья является частью нашего Rust Interop Guide .
-
It has been [0] days since I passed a Java ByteArray object into a C function instead of the GetArrayElements() pointer inside it. #jni
-
It has been [0] days since I passed a Java ByteArray object into a C function instead of the GetArrayElements() pointer inside it. #jni
-
[Перевод] Java становится надежнее: “Целостность по умолчанию” в действии
Команда Spring АйО перевела статью про ужесточение контроля за динамической загрузкой агентов, ограничения доступа к опасным методам работы с памятью и JNI в новых версиях JDK.
-
@fglock @profoundlynerdy We’ve been here before, as far back as 1998 when Larry Wall himself developed the JPL “#Java #Perl Lingo” for @OReillyMedia: https://github.com/Perl/perl5/blob/perl-5.6.0/jpl/README
It was basically a Java code preprocessor that let you inline Perl code in Java methods that could themselves call back to Java via #JNI.
The eventual goal was a Perl-to-Java compiler but it never got there despite distribution with Perl 5.6 through 5.8 as a separate installer.
-
@fglock @profoundlynerdy We’ve been here before, as far back as 1998 when Larry Wall himself developed the JPL “#Java #Perl Lingo” for @OReillyMedia: https://github.com/Perl/perl5/blob/perl-5.6.0/jpl/README
It was basically a Java code preprocessor that let you inline Perl code in Java methods that could themselves call back to Java via #JNI.
The eventual goal was a Perl-to-Java compiler but it never got there despite distribution with Perl 5.6 through 5.8 as a separate installer.
-
Wednesday Links - Edition 2024-06-05
https://dev.to/0xkkocel/wednesday-links-edition-2024-06-05-b6d
#java #jvm #jni #stactrace #rest #ui -
#JDK22 contains the final version of the Foreign Function & Memory API (#JEP454). Being a modern successor to #JNI, it allows cool stuff like building Java wrappers arounds C libraries.
We did just that and are proud to announce the first production-ready version of #jFUSE, allowing you to develop #FUSE filesystems in #Java. It is module-ready, multi-platform, thoroughly tested by @cryptomator and thanks to the FFM API requires no further dependencies.
-
#JDK22 contains the final version of the Foreign Function & Memory API (#JEP454). Being a modern successor to #JNI, it allows cool stuff like building Java wrappers arounds C libraries.
We did just that and are proud to announce the first production-ready version of #jFUSE, allowing you to develop #FUSE filesystems in #Java. It is module-ready, multi-platform, thoroughly tested by @cryptomator and thanks to the FFM API requires no further dependencies.
-
I'm trying to compile #RStat as a static library with the -fPIC flag (so I can use it within #java #jni), but I cannot find the right flags to compile it this way. I tested various flags but I cannot find the correct syntax.
```
configure.ac:278: error: possibly undefined macro: AM_CONDITIONAL
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
```https://gist.github.com/lindenb/e8659d53d5ccdcaa5cdef1e7b2602a61
-
I'm trying to compile #RStat as a static library with the -fPIC flag (so I can use it within #java #jni), but I cannot find the right flags to compile it this way. I tested various flags but I cannot find the correct syntax.
```
configure.ac:278: error: possibly undefined macro: AM_CONDITIONAL
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
```https://gist.github.com/lindenb/e8659d53d5ccdcaa5cdef1e7b2602a61
-
Who do I know who can write JNI code in Rust? Brendan needs to call a threading function because omg and I have enough Redmi phones already.
-
Who do I know who can write JNI code in Rust? Brendan needs to call a threading function because omg and I have enough Redmi phones already.
-
After a while working on this, it is finally out!
@rustlang integrated with #Android and @kotlin.
https://fernandocejas.com/blog/engineering/2023-07-27-rust-cross-platform-android/
-
Tool of the day: https://github.com/dg76/signpackage
If you want to notarize your Java app with native libraries for Mac OS.
#notarize #java #jni #macos -
Tool of the day: https://github.com/dg76/signpackage
If you want to notarize your Java app with native libraries for Mac OS.
#notarize #java #jni #macos -
#Swift is a nice language. Having interop between Swift and #C++ would be neat, but with Socket Runtime we would lose out on a lot of code reuse, Windows and Linux are mostly C/C++ code bases, and our Android is mostly C++ via the #JNI, as a result there’s actually very very little #ObjC++ in the project. I’m pretty much +0 on the idea of interop.
-
#Swift is a nice language. Having interop between Swift and #C++ would be neat, but with Socket Runtime we would lose out on a lot of code reuse, Windows and Linux are mostly C/C++ code bases, and our Android is mostly C++ via the #JNI, as a result there’s actually very very little #ObjC++ in the project. I’m pretty much +0 on the idea of interop.
-