Is it possible to build a native extension that fetch local songs and a mediaplayer in android?
Yes, I donât see why that shouldnât be possible. If you can do it in a normal Java based Android app, then you should also be able to do it using a native extension.
Thanks britzl.
Also, I want to ask whether there is tutorial for me to follow.
It would be great if it is steps by steps.
I want to know more about the flow of making native extensions for android.
Have you read the native extension manual? https://www.defold.com/manuals/extensions/
I have read the manual but it is not enough for me .
So, in my case, what I need is coding my own java first, and then write a extension.cpp to link them together?
Yes.
Here is an example to get you going: extension-android
Thanks Mathias.
I have written a small one to test, but it comes out with âattempt to index global âmediaplayerâ (a nil value)â when I build and run.
Does I miss something important?
You mean when you build and run on desktop? Or on device? Itâs likely that thereâs an ifdef making the extension only available on Android. Like this: extension-android/androidnative/src/extension.cpp at master ¡ defold/extension-android ¡ GitHub
I use dmengine to test.
What does your code look like?
Itâs difficult to help unless we get some more info.
When you say dmengine
, do you mean you selected âBuild and Runâ from the menu?
Or do you mean the dmengine.apk
on your Android?
If you chose âBuild And Runâ, you are running on either OSX/Windows/Linux, and none of those have DM_PLATFORM_ANDROID
defined (Just as BjĂśrn mentioned above). See the code he linked
dmengine.apk on my android.
And, did you bundle it yourself?
Or, did you download the vanilla engine from dmengine.apk?
If you downloaded the .apk file from the download page, beware itâs the vanilla engine. It is uploaded every two weeks, with each release. It will not contain your extension.
You have to bundle your app for Android, and use that .apk instead.