Search code examples
android-ndkndk-build

Method to make ndk-build delete only those libs folder for which build is being triggered


We have two separate Application.mk file one which has APP_ABI := armeabi armeabi-v7a and other which has APP_ABI := x86. The reason for doing this is we don't always want to build for X86 platform but only when certain conditions are met. So, the arm build is triggered unconditionally by a shell script, which then triggers ndk-build again for X86 if the conditions are met. The problem I am facing is everytime ndk-build is triggered, it does the below thing: rm -f ./libs/arm64-v8a/lib*.so ./libs/armeabi/lib*.so ./libs/armeabi-v7a/lib*.so ./libs/armeabi-v7a-hard/lib*.so ./libs/mips/lib*.so ./libs/mips64/lib*.so ./libs/x86/lib*.so ./libs/x86_64/lib*.so and if now X86 build is triggered and the build completes, I see armeabi and armeabi-v7a libs folders deleted. Shouldn't ndk-build delete only those libs folder that we are currently targeting for via APP_ABI? If not, is there a way to get around this?

I think build-all.mk in the NDK distribution has this clean: clean-intermediates clean-installed-binaries that might be cleaning up all the libraries.


Solution

  • Not the best answer, but ended up with the following hack

    run ndk-build for arm platform
    cp -r ./libs/ /tmp/libs/
    condition passes
    run ndk-build for x86 platform
    cp -r /tmp/libs/armeabi/ ./libs/armeabi/
    cp -r /tmp/libs/armeabi-v7a/ ./libs/armeabi-v7a/
    rm -rf /tmp/libs