gradle externalNativeBuild with both cmake and ndk-build

443 views
Skip to first unread message

Panagiotis Apostolou

unread,
Sep 20, 2023, 10:52:22 AM9/20/23
to android-ndk
I want to use both cmake and ndk-build to build an android application.
I need cmake to run first, then ndk-build and then assemble the .apk file

To do that I have resolved by specifying only cmake in  externalNativeBuild and running ndk-build as an Exec task.

I invoke the task with:
beforeEvaluate { assembleRelease.finalizedBy { runNdkBuild } }

Unfortunately this seems that it calls the task after  the apk has been assembled so the .so files are not included. If i rerun gradlew then it updates the apk with the so files.

How can I make the task to run before assembling the apk but after cmake so that the generated binaries will be included in the apk?

Dan Albert

unread,
Sep 20, 2023, 2:36:10 PM9/20/23
to andro...@googlegroups.com
You need to make the dependency explicit. Use two gradle modules. Make the CMake one a library module, and have the ndk-build module depend on it. Alternatively set the dependency correctly on your ndk-build task, but you're fighting against AGP by doing it that way.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/f00106fd-c326-44db-9602-115cedc3863cn%40googlegroups.com.

Panagiotis Apostolou

unread,
Sep 21, 2023, 11:56:41 AM9/21/23
to android-ndk
Luckily I already have two gradle modules, one is a library one and the other is the application which depends on the first one. As you suggest I move the cmake to the library one and now it works. Thanks.
Reply all
Reply to author
Forward
0 new messages