[FIXED] Android NDK Build: ld: error: failed to write to the output file: Permission denied

Issue

I could build my project in windows 7 until I updated the NDK version to latest (23.1.7779620).
I put the NDK files beside my Android SDK folder:

local.properties
sdk.dir=F\:\\Programming\\AndroidSdk
ndk.dir=F\:\\Programming\\AndroidNdk\\ndk-r23b

Now when I want to build APK, I got this error:

> Task :app:externalNativeBuildDebug FAILED
Build gdx-audio_armeabi-v7a
[armeabi-v7a] SharedLibrary  : libgdx-audio.so
ld: error: failed to write to the output file: Permission denied
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [F:/Programming/AndroidNdk/ndk-r23b/build//../build/core/build-binary.mk:715: F:/Projects/Android/myProject/app/build/intermediates/ndkBuild/debug/obj/local/armeabi-v7a/libgdx-audio.so] Error 1

ld: error: failed to write to the output file: Permission denied

My app build.gradle:

android {
    ...
    ndkVersion "23.1.7779620"
    externalNativeBuild {
        ndkBuild {
            path "jni/Android.mk"
        }
    }


    defaultConfig {
        ...
        externalNativeBuild {
            ndkBuild {
                arguments "NDK_APPLICATION_MK:=jni/Application.mk", "APP_PLATFORM:=android-16", "-j8"
                abiFilters "armeabi-v7a", "arm64-v8a"
            }
        }
    }
}

}

Solution

You are correct. ProcessMonitor seems to indicate that in NDK version 23.1.7779620 the ld.exe is using a newer API calls that are not supported on Win7.

enter image description here

It looks like ld erroneously interprets the failed API call as a "permission denied" error. The same happens in NDK version 23.0.7599858.

The last NDK that seems to work on Win7 is 22.1.7171670.

After the system was upgraded to Win10 ld started to work normally for the 23.x NDK versions.

Answered By – omahena

Answer Checked By – Marilyn (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published