androidc++gradlejava-native-interface.so

Android Studio Error Message: Use Of Undeclared Identifier 'accept4'


the jni folder not appear in android studio and after build only java folder get build.

MAIN FOLDER FROM EXPLORER

MAIN FOLDER FROM ANDROID STUDIO

as you can see the jni folder appear in explorer but not inside android studio.

EDIT: so after i added this in my build.gradle

externalNativeBuild {
    ndkBuild {

        path 'src/main/jni/Android.mk'

    }
}

the jni folder appered as cpp folder name but when i compile i get this error from SocketServer.cpp:

use of undeclared identifier 'accept4'

This is the code :

bool SocketServer::Accept() {
    if ((acceptfd = accept4(listenfd, nullptr, nullptr, SOCK_CLOEXEC)) < 0) {
        Close();
        return false;
    }
    return true;
}

and headers is already includes:

#include <sys/types.h>
#include <sys/socket.h>

Solution

  • i get pass the error "use of undeclared identifier 'accept4'" by setting these :

    from compileSdkVersion 29       to compileSdkVersion 30
    from buildToolsVersion "29.0.3" to buildToolsVersion "30.0.3"
    from minSdkVersion 21           to minSdkVersion 22
    from targetSdkVersion 29        to targetSdkVersion 30