Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle AssetManager using JavaCpp? #792

Open
Clement-Devevey opened this issue Jan 23, 2025 · 7 comments
Open

How to handle AssetManager using JavaCpp? #792

Clement-Devevey opened this issue Jan 23, 2025 · 7 comments

Comments

@Clement-Devevey
Copy link

Clement-Devevey commented Jan 23, 2025

I have a c++ library that needs access to the java Android AssetManager. (android.content.res.AssetManager)
To pass it to the library, I am using a custom JNI that takes this AssetManager as a jobect and then converts it to the equivalent c++ class AAssetManager (defines in android/asset_manager.h) using AAssetManager_fromJava(jobject*)

I was wondering how to handle this using javacpp?

I tried to do infoMap.put(new Info("AAssetManager").javaNames("AssetManager").define())
but the generated NativeLibrary.java doesn't define the AssetManager class.

@saudet
Copy link
Member

saudet commented Jan 23, 2025

How are you including asset_manager.h?

@Clement-Devevey
Copy link
Author

Clement-Devevey commented Jan 23, 2025

#include <android/asset_manager.h>
#include <android/asset_manager_jni.h>

@saudet
Copy link
Member

saudet commented Jan 23, 2025

You'll also need to include it in Java

@Clement-Devevey
Copy link
Author

Ok looks like I've been able to build by doing so:

  • include the files in java (android_manager.h and android_manager_jni.h, need to check if both are required)
  • add infoMap.put(new Info("off64_t").javaNames("long").define())
  • add infoMap.put(new Info("AAssetManager_fromJava").skip()
  • add infoMap.put(new Info("AAsset_openFileDescriptor64").skip()

I had to skip AAssetManager_fromJava otherwise it would have require to also include the whole jni.h file which seems to be so overkill?
But I am not sure I'll be able to create a AAssetManager without AAssetManager_fromJava ...

The c++ method I'm trying to call is a static one, so I think I will stick to the old way for this method only as it seems overkill to include all jni.h, what do you think?

@saudet
Copy link
Member

saudet commented Jan 23, 2025

Well JavaCPP is based on JNI. To use those objects, use the @Raw annotation:
http://bytedeco.org/javacpp/apidocs/org/bytedeco/javacpp/annotation/Raw.html

@Clement-Devevey
Copy link
Author

Thanks for the pointer!
I am sorry I couldn't find any usage example, could you explain how is it intended to be used please? 🙏

@saudet
Copy link
Member

saudet commented Jan 24, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants