1

I covert a ADT project to Android Studio. however, i kept getting the error when building this project:

Error:(687) Android NDK: Module MediaEncoder depends on undefined modules: cutils gnustl dl

This is what is in the Android.mk. I am new to NTK, anybody can advise the issue here?

 # building application library 
#
include $(CLEAR_VARS)
LOCAL_MODULE := libMediaEncoder
LOCAL_CPP_EXTENSION := .cc .cpp
LOCAL_CPPFLAGS := -O2 -Werror -Wall 
LOCAL_C_INCLUDES :=  $(MY_LOCAL_PATH)
LOCAL_SRC_FILES := main_jni.cpp \
                   h264encoder.cpp \
                   g72x/g726_32.c \
                   g72x/g711.c \
                   g72x/g72x.c 

LOCAL_LDLIBS += -llog -lz
LOCAL_SHARED_LIBRARIES := libcutils\
                          libgnustl\
                          libdl
Lingzhi Zhang
  • 883
  • 1
  • 8
  • 10

2 Answers2

2

I believe that you use a project that was configured to be built in the context of AOSP build, not by NDK. But it could still work with a very old version of NDK.

The current version, r14 which is integrated into Android Studio 2.3, requires some changes to Android.mk.

include $(CLEAR_VARS)
LOCAL_MODULE := libMediaEncoder
LOCAL_CPPFLAGS := -O2 -Werror -Wall 
LOCAL_C_INCLUDES :=  $(MY_LOCAL_PATH)
LOCAL_SRC_FILES := main_jni.cpp \
                   h264encoder.cpp \
                   g72x/g726_32.c \
                   g72x/g711.c \
                   g72x/g72x.c 
LOCAL_LDLIBS += -llog -lz -ldl
LOCAL_SHARED_LIBRARIES := libcutils_prebuilt
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libcutils_prebuilt
LOCAL_SRC_FILES := {full-path-to}/libcutils.so
include $(PREBUILT_SHARED_LIBRARY)

To resolve the dependency on gnustl, run ndk-build APP_STL=gnustl_static, or define APP_STL in your Application.mk file.


Note that your project uses non-public system library libcutils.so. This library was once included in NDK (see https://stackoverflow.com/a/22017733/192373), but for the last 3 years Google has been struggling to discourage linking to it.

You can build libcutils.so yourself as part of AOSP, or you can adb pull it from your device or even from a compatible emulator. You can also find this binary somewhere on the Web (e.g. GitHub).

The final blow comes with the announced changes to system linking for Android 7.0 Nougat. TL;NR: any app that depends on this library will not work on future Android versions.

Community
  • 1
  • 1
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
1

You need to install an older version of ndk Android NDK, Revision 10e (May 2015) worked for me and then use that ndk-build

Justin
  • 98
  • 1
  • 5