All Questions
Tagged with java-native-interface android-ndk
1,865 questions
1
vote
1
answer
33
views
What could cause ART (Android Runtime) to deadlock while unloading a native library?
I have been trying to debug a non user perceivable crash in my app (I think it happens in the background) that originated from the Android Runtime due to possibly a deadlock/thread contention.
...
0
votes
0
answers
132
views
How to Reference Custom AIDL HAL Service in JNI Code (Android.bp)?
I have a custom setup where I need to interact with a custom HAL through IPC in an Android JNI service. The flow I am working on is:
HMI -> CustomSensorManager -> AIDL -> Custom System ...
-1
votes
1
answer
159
views
Android App using C++ for serial USB access
I'm developing an Android application that needs to access a third-party library written in C that accesses the serial port through the command (*pSerialHandle) = open(deviceName, O_RDWR | O_NOCTTY | ...
0
votes
0
answers
27
views
No implementation found for Int when i use .so file android
I want to use .so file, i've success to load the library but the function is not working. Below is the code
Structure
MainActivity.java
JniLoader.java
package com.example.testapps;
public class ...
3
votes
1
answer
161
views
Why SIGSEGV behaves differently from other Exception codes in Android?
I am building an Android application with Native code. I want to handle the exceptions such as SIGSEGV, SIGFPE, SIGILL, etc.
My objective is that in the unlikely scenario that one of them occurs, I am ...
0
votes
1
answer
208
views
I don't know how to solve "local reference table overflow" error in android JNI
I am experiencing a local reference overflow error when running my algorithm written in JNI. The code works fine up to 2000-3000 iterations, but after that, it crashes with the error message "...
1
vote
1
answer
36
views
What is the exactly time that JNI release the LocalReference automatically?
Think about this situation in jni:
I first call a native function1 in java
The native function1 calls the java function2
The java function2 calls the native function3
What I need to know is when ...
1
vote
0
answers
95
views
Limiting the access of JNI file access to "just" one folder
If I launch some C code with the JNI in my Android application, is there a way I could limit that C code to access only a specific folder in my application folder, so sandboxing it to just a specific ...
1
vote
0
answers
79
views
Opening a file with AAssetManager crashes
Sometimes AAssetManager crashes on me. The exact trace is below.
#00 pc 00000000000cdd91 /apex/com.android.runtime/lib64/bionic/libc.so (pthread_mutex_lock+1) (BuildId: ...
1
vote
1
answer
210
views
C code in Android JNI - Where does the printf() output go?
I'm porting a C code App into Android and I'm using the Java Native Interface to mix C and Java code.
I got the following code that compiles and runs without problems.
I would like to know where the ...
1
vote
1
answer
241
views
Reading json file from assets in Android's Native Library [duplicate]
I am trying to read a JSON file from assets folder in the apk using (Asset NDK apis)
I am using AAssetManager_fromJava to use Dalvik AssetManager object on native side.
But since I need to load the ...
0
votes
0
answers
121
views
Why does FindLibrary return 0?
I'm trying to create a launcher for SAMP Android. Everything was going well until the integration of SAMP itself (build69). libsamp.so cannot find the address of the neighboring libGTASA.so library.
...
1
vote
0
answers
252
views
UnsatisfiedLinkError: dlopen failed: "**.lib.so" has unexpected e_version: 65725
Process: example.some.ed4.di, PID: 13990
java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/example.some.ed4.di-X5PrLl2fWMuTOoeqKz3DaQ==/base.apk!/lib/arm64-v8a/libgeneraldecryptjni.so&...
1
vote
0
answers
131
views
Unable to run android app with prebuilt native library
I have a library written in c++, and it is pre built by Androi NDK clang++ with Makefile command, like this:
libfoo.so:
$(CXX) -c -Wall -Werror -fpic ${SRC_PATH}foo.cpp
$(CXX) -shared -o ...
0
votes
1
answer
109
views
Why my Java class methods are not being called from the native code? JNI, NDK/SDK
I am developing an app NDK/SDK in Android Studio and want the Android while running my app to show the menu of the write permissions so the user can activate it. But my Java class methods(MainActivity....
1
vote
1
answer
855
views
How to use JNI_GetCreatedJavaVMs in C++ to call Java Code
I have an Android application which contains the Java and C++ code. The C++ code I have is bundled into different .so files and can be invoked either from Java or other .so files. From some of the .so ...
1
vote
0
answers
51
views
Android UnsatisfiedLinkError when load /lib/arm/libpolarssl.so
I implement the native library in my Android application. And get some crashes like below:
Fatal Exception: java.lang.UnsatisfiedLinkError: dlopen failed:
/data/user/0/com.gbox.android/_root/data/...
1
vote
1
answer
312
views
JNI callback to Java
Need some help in understanding when the java string is deleted. On the c side the string is deleted after the call to onCandidates and on the java side setRemoteDescription may take some time to ...
0
votes
0
answers
62
views
Freetype2 returning pointers with negative value when seen as long
I am trying out FreeType2 with NDK in an android app.
The workflow I used is
download freetype, unzip into my cpp folder
2.included freetype in the Cmakelists
3.It all compiles and sucessfully ran on ...
0
votes
2
answers
170
views
webrtc static android library can't export jni functions
I planning to use webrtc native in our library. The my library will be used by Android.
I've success build libwebrtc.a for android, using https://webrtc.github.io/webrtc-org/native-code/android/ link.
...
0
votes
0
answers
80
views
Are there any Android NDK examples, on how to pass a file from Java to C++ using JNI?
I am not sure, if this is the right place to ask, but I am curious, if there are any Android NDK examples (apks), on how to read a file with Java and pass it over to C/ C++ using JNI.
Currently I am ...
0
votes
0
answers
827
views
Android 13: How to check PackageManager.getPackageInfo(String, PackageInfoFlags) in JNI C?
PackageManager.getPackageInfo(String, Int) is deprecated starting from Android 13 (SDK 33).
The documentation says to use PackageManager.getPackageInfo(String, PackageInfoFlags) instead.
So I tried to ...
0
votes
1
answer
104
views
run QApplication in android studio ,native c++ , cmake
I try to use qt in android studio with cmake ,the starting point is create a native c++ project in androind studio ,then I revise the CMakeLits.txt like this :
cmake_minimum_required(VERSION 3.18.1)
...
0
votes
1
answer
142
views
Java functions, but without java (jni)?
I have one library 'libFOO.so ' which has java functions (JNI). Can I access these functions on a pure NDK?
I.e. for example we have a function (in this library, from IDA PRO):
void ...
1
vote
1
answer
108
views
Why can only int be calculated in return when using ndk build?
I am trying to make a project using jni into aar. However, simple int calculation seems to be possible with return in the cpp part, but I don't know why an error occurs when I try to use the if ...
2
votes
0
answers
1k
views
C/C++ does not see Java method in JNI via Android NDK
I am trying to call Java method from C class file, built using NDK.
It constantly throws usual "no non-static method found" error and crashes whole Android App.
Code pieces below (some stuff ...
0
votes
0
answers
36
views
Native lib in c for Android app on Galaxy A13 returns different value depending on build type (debug or release)
I've an app that uses a native library to run some pretty simple calculations, mainly converting jbyteArray into char *, doing some vector calculations, and returning the result back into jbyteArray
...
0
votes
0
answers
185
views
How to load and use a lib.a file in an android project
I am trying to use nng library in my android project
I have built a library "libnng.a" using the guide here.
But when I am trying to load this .a file into the android project, I am getting ...
0
votes
1
answer
173
views
Android JNI GetMethodID for sharedPreferences.getString
I'm trying to get a string from sharedPreferences on Android from C++ code using JNI. I can successfully get the MethodID for getBoolean with this code:
jmethodID getBooleanMethodID = JEnv->...
0
votes
0
answers
117
views
How to create so file for x64 using android NDK. custom tool chain?
I am very new to android and here is what I want to do:
I have some cpp files and want to create so file which will be later used in another android project. Now, I tried with cmake and using linux ...
0
votes
0
answers
45
views
Android C++ how to read library installed at os level
For security reason, I want to read jni library installed at the OS level from the same library within the package. This is to check by comparing checksum whether installed library at the OS level is ...
0
votes
1
answer
836
views
How to pass/recevice data from java/Kotlin to C++ code or vice versa in android
I am working on AOSP11/12(Android) and want to communicate data from java/Kotlin to C++ code or vice versa.
Is that better way to create new service and communicate data or need to create NDK ...
1
vote
1
answer
239
views
Add pre-built NDK library (.so file) to Android project
I inherited an Android project which includes a sub-project to build a JNI library from C source. I want to remove the C source and include pre-built library instead. Based on tips I found here and ...
0
votes
1
answer
374
views
boost 1.74+ jni ndk compilation cmake project
I would like to compile boost for Android JNI CMake project.
I tried with this repo
https://github.com/moritz-wundke/Boost-for-Android
but fail build for boost v1.78 with ndk23..
Is there any tutorial ...
0
votes
1
answer
596
views
Access Java class object methos from JNI
I have an Android app in which I have implemented the connection with a WebSocket in the C++ code.
Now I would like to invoke a method of an object initialized in the Java class, via C++ code with JNI....
1
vote
0
answers
916
views
How to use ndk-stack in Android Studio?
I need to debug my native C code. (I'm a newbie in C and ndk). I get this error, but i don't know exactly from where the bug come from:
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x38
I ...
3
votes
1
answer
1k
views
Unable to refer Kotlin data class field in JNI
I have a JNI code that intends to modify a field value present in a data class.
I'm unable to reference the data class method to do so. Any help is deeply appreciated.
data class User(val name: String,...
2
votes
1
answer
1k
views
Very slow debugging of native code in Android Studio
I put a breakpoint to my native code.
However when I attach the debugger, the app becomes inactive and it takes a while (10-15 minutes) until Android Studio stops at the breakpoint and allow me to do ...
0
votes
1
answer
4k
views
Android NDK/JNI -- shared library incompatible with armelf_linux_eabi
I'm trying to use Android NDK and JNI to call a C++ function from Kotlin in my Android Studio project.
Here's my Android project structure:
myproject/app/src/main
│
└───java
│ │
│ └───com....
0
votes
0
answers
96
views
Android ndk native app enviroment variable runtime
Anybody know how could i set the PATH within the application that is calling native c++ code, which in terms uses system popen call to WGET and CURL etc...
I get permission denied setting the ...
0
votes
0
answers
124
views
OPENSSL Rand DRBG Andorid crashed when is used many times: A/libc: Fatal signal 7 (SIGBUS)
I'm trying the use the OpenSSL Rand library with DRBG in an android app, this library is implemented in native code of NDK. At starting, the OpenSSL works fine but in many times the app crashed and ...
0
votes
2
answers
252
views
Does callback copy jnienv, jinstance inside a JNI function?
The lambda that I pass to builder is populated into className object, and called at regular intervals (every hour) of time to refresh the other members. It gets called the first time successfully. I'm ...
0
votes
1
answer
185
views
access xml part from c++ android
i have a textview in xml file with "tv" id
if i declare
TextView tv ;
tv= findViewByID(R.id.tv);
then i can call setText Method with this part
extern "C"
...
1
vote
0
answers
269
views
How to use ndk file_descriptor_jni.h?
I want to create a Java FileDescriptor object on C!
There are too few related instructions.
It has been tried for a long time and cannot be called successfully.
AFileDescriptor_create(JNIEnv *env)
...
0
votes
0
answers
132
views
Can I convert FILE* to FileInputStream/FileOutputStream in android-jni?
I've tried the code and it's feasible on Android.
Is there a simpler way?
I hope it can be realized in a simpler and faster way
This is my code, I hope it can be realized more simply.
//C Lang Code
...
0
votes
1
answer
669
views
How to pass an object or delegate using JNI/Kotlin callback?
I'm new to JNI development. What I'm trying to achieve is that I need to capture a snapshot using JNI. I'm able to achieve the same using Kotlin/Java.
I'm using the following code to capture the ...
0
votes
0
answers
190
views
Android jni framework internal class init and use help need
i am using c++ for target to build android internal framework api.
api is accessible i tested with frida hooking methods.
for reference link https://github.com/frida/frida/issues/1867
java code here.
...
0
votes
1
answer
2k
views
Calling C external library (.so) from android java
I am writing an example android app to demonstrate the use of our (university research) C/C++ library.
I know that, using jni, we can call C functions from java.
However, I have not found a step by ...
0
votes
0
answers
203
views
How use sqlcipher in android native NDK using JNI (Java Native interface)
I am using this method of sqlcipher to create encrypted sqlite database in my android studio project by java code.
package net.sqlcipher.database;
.
.
public static SQLiteDatabase ...
2
votes
0
answers
111
views
How can I call java functions from native code (using JNI)?
I want to implement a JNI function that calls a function in Java from native C code. Currently the JNI_createJavaVM method does not exist in my libjvm.so. So i cannot use the JNI API of the form (*env)...