Build a native lib for each project

I have the following android project layout.

| root-project

Each time i am building the project i want to rebuild the native lib for App1 and App2. This is necessary because each app configures the library with different settings.
Using the library as a dependency in App1 and App2 doesn’t work as desired because externalNativeBuild is called only once.
An approach would be to generate a GradleBuild task for App1 and another task for App2. Each task will perform a nested build, building the library with a different configuration each time.
Is there a more elegant solution?