NDK-Samples | Collection of Code Samples to be used with the Native SDK | SDK library
kandi X-RAY | NDK-Samples Summary
kandi X-RAY | NDK-Samples Summary
The NDK-Samples repository holds Open Sourced samples for the BlackBerry 10 Native SDK. All APIs shared in this repository are Open Source under the Apache 2.0 License.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of NDK-Samples
NDK-Samples Key Features
NDK-Samples Examples and Code Snippets
Community Discussions
Trending Discussions on NDK-Samples
QUESTION
I've faced an issue that AndroidStudio has a problem with indexing files that are in the NDK package. So, for example, if we take the standard AndroidStudio example of the NativeActivity (code is also available on GitHub) and activate files indexing (for example by clicking Build->Refresh C++ Projects
) we obtain endless Scanning files to index...
It seems that AndroidStudio does not like the paths where native_app_glue
stuff is located, from CMakeLists.txt from mentioned example:
ANSWER
Answered 2020-Oct-30 at 18:14Was figured out that it is a known issue in Android Studio 4.1 (thanks @protossor for confirming) and currently under fixing: https://issuetracker.google.com/issues/171801044
So, it only remains to wait for a new Android Studio release to check whether the problem is fixed or not (results will be shared).
QUESTION
I am trying to interface with an MSI SDR dongle, using an android app
This device is a clone of the SDRPlay SDR device, and is compatible with it's software and drivers
I am trying to interface with this using an OTG cable and android phone
The android drivers for this can be downloaded from here https://www.sdrplay.com/downloads/
It is in the Android tab under the API/HW – V2.11 (15TH NOV 2017) link (https://www.sdrplay.com/anddl.php)
A possible sample code for this driver can be found here: https://www.sdrplay.com/docs/AndroidIntegrationNote.pdf
Before making the full android program it says the library (libmir_sdr_api.a) should be built into an .so library file using ndk-build
I currently have Android's hello-jni sample project from here: https://github.com/android/ndk-samples/tree/android-mk/hello-jni
I have replaced the jni folder using the Android.mk file, libmir_sdr_api.a, mir_sdr.h, initialization-jni.cpp, demod-jni.cpp and demod-jni.h files mentioned in section 3 of the AndroidIntegrationNote.pdf file I linked above
When I execute ndk-build from the hello-jni project folder, I get he following error:
...ANSWER
Answered 2020-Jun-04 at 09:25Regarding missing jni/initialisation-jni.cpp
, you probably have the file jni/initiali
zation-jni.cpp
instead.
Also, unfortunately, the document is wrong. You can only use $(call my-dir)
easily at the top of the file. Luckily, Android NDK adds the jni directory to includes path for you. Still, to be on the safe side, better write:
QUESTION
I have import and tested this project:
https://github.com/android/ndk-samples/tree/master/hello-jni
in Android Studio and worked well.
But when I copy the code for another new project I have the follow error:
“Incompatible point types jclass
and `jobject”
In this line:
...ANSWER
Answered 2020-Apr-26 at 17:26NewGlobalRef
always returns a jobject
even though you're giving it a jclass
(which is a subclass of jobject
).
You can solve this warning by explicitly downcasting to jclass
, either as
QUESTION
I'm using Android NDK and need access to assets. A requirement for asset access seems to be obtaining an AssetManager reference.
Looking at the NDK samples (https://github.com/android/ndk-samples), the pattern seems to be:
- A
JNIEnv*
is passed into the func when called directly from the JavaVM, along with somejobject
- Use these to get
AAssetManager*
and then use this to open assets
That seems simple enough, except in my case, the functions are being called from Unity so I don't have access to either a JNIEnv*
or jobject
. Getting the JNIEnv*
seems easy enough as I can make use of JNI_OnLoad
to get access to a JavaVM*
and then use that to get a JNIEnv*
via vm->GetEnv
. My questions about this are:
1) My understanding is that, an Android app can only have one instance of a Java VM. Am I safe to take the JavaVM*
passed into JNI_OnLoad
and save it for use in other function calls?
2) What about the JNIEnv*
? Can I grab that once during JNI_OnLoad
and save it, or should I grab a fresh one every time I need to use assets within a function? Is JNIEnv*
something I need to explicitly free? (i.e. what's the lifetime/ownership situation with JNIEnv*
?)
3) AAssetManager_fromJava also requires a jobject
with the documentation (https://developer.android.com/ndk/reference/group/asset#group___asset_1gadfd6537af41577735bcaee52120127f4) saying: "Note that the caller is responsible for obtaining and holding a VM reference to the jobject to prevent its being garbage collected while the native object is in use.". I've seem some examples that simply pass in an empty (native) string like AAssetManager_fromJava(env, "");
- is that ok? I'd only be using the AssetManager for the lifetime of that call, and I could get a fresh one each time. (Again, is AAssetManager*
a resource I need to manage, or am I just getting a reference to something owned elsewhere? The documentation seems to imply the latter.)
4) So given all the above, I'd probably do something like:
...ANSWER
Answered 2019-Nov-22 at 14:44Point-by point answer to your questions:
Yes, there can be only one VM in Android. You are allowed to store this pointer or use
JNI_GetCreatedJavaVMs
.JNIEnv
pointers are tightly coupled to the thread they were created on. In your situation you will first have to attach the thread to the VM usingAttachCurrentThread
. This will fill in aJNIEnv *
for you. Don't forget toDetachCurrentThread
when you're done.Also note the caveat about
FindClass
: you need to look up classes from the main thread or via the classloader of a class you looked up in the main thread.The implementation of
AAssetmanager_fromJava
is pretty clear: passing it anything other than anAssetManager
object is undefined behavior. This answer shows one approach to grabbing the asset manager, another might be to call your own JNI function with a reference to the AssetManager object. Make sure to keep a global reference so it does not get GCed.Given the above, it would probably look more like this:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install NDK-Samples
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page