Modify android.mk error android studio

Modify android.mk error android studio
0

help me!!
i use cocos2dx 3.17.2 , android-ndk-r16b , gradle 4.5
and run helloworld successfully
but i can’t modify
LOCAL_SRC_FILES := $(LOCAL_PATH)/hellocpp/main.cpp
$(LOCAL_PATH)/…/…/…/Classes/AppDelegate.cpp
$(LOCAL_PATH)/…/…/…/Classes/HelloWorldScene.cpp
in anroid.mk
when i put my .cpp class i will get error


Build command failed.
Error while executing process E:\cc\SDK_NDK\sdk_components_of_androidstudio\cmake\3.10.2.4988404\bin\cmake.exe with arguments {--build E:\cocos2dx-3172\project3172cc\testmygame\proj.android\app\.externalNativeBuild\cmake\debug\arm64-v8a --target MyGame}
[1/724] Building CXX object engine/cocos/core/CMakeFiles/cocos2d.dir/2d/CCParallaxNode.cpp.o
[2/724] Building CXX object engine/cocos/core/CMakeFiles/cocos2d.dir/2d/CCParticleExamples.cpp.o
[3/724] Building CXX object engine/cocos/core/CMakeFiles/cocos2d.dir/2d/CCNodeGrid.cpp.o
[4/724] Building CXX object engine/cocos/core/CMakeFiles/cocos2d.dir/2d/CCProtectedNode.cpp.o
[5/724] Building CXX object engine/cocos/core/CMakeFiles/cocos2d.dir/2d/CCParticleBatchNode.cpp.o
[6/724] Building CXX object engine/cocos/core/CMakeFiles/cocos2d.dir/2d/CCProgressTimer.cpp.o
[7/724] Building CXX object engine/cocos/core/CMakeFiles/cocos2d.dir/2d/CCParticleSystem.cpp.o
[8/724] Building CXX object engine/cocos/core/CMakeFiles/cocos2d.dir/2d/CCSprite.cpp.o
[9/724] Building CXX object engine/cocos/core/CMakeFiles/cocos2d.dir/2d/CCParticleSystemQuad.cpp.o
[10/724] Building CXX object engine/cocos/core/CMakeFiles/cocos2d.dir/2d/CCNode.cpp.o
[11/724] Building CXX object engine/cocos/core/CMakeFiles/cocos2d.dir/2d/CCAutoPolygon.cpp.o
.
.
.
.
[717/724] Building CXX object engine/cocos/platform/CMakeFiles/cpp_android_spec.dir/CCDevice-android.cpp.o
[718/724] Building CXX object engine/cocos/platform/CMakeFiles/cpp_android_spec.dir/jni/Java_org_cocos2dx_lib_Cocos2dxEngineDataManager.cpp.o
[719/724] Building CXX object engine/cocos/platform/CMakeFiles/cpp_android_spec.dir/jni/Java_org_cocos2dx_lib_Cocos2dxAccelerometer.cpp.o
[720/724] Building CXX object engine/cocos/platform/CMakeFiles/cpp_android_spec.dir/jni/Java_org_cocos2dx_lib_Cocos2dxBitmap.cpp.o
[721/724] Building CXX object engine/cocos/platform/CMakeFiles/cpp_android_spec.dir/jni/Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp.o
[722/724] Linking CXX static library engine\cocos\platform\libcpp_android_spec.a
[723/724] Linking CXX static library lib\libcocos2d.a
[724/724] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\arm64-v8a\libMyGame.so
FAILED: ../../../../build/intermediates/cmake/debug/obj/arm64-v8a/libMyGame.so 
cmd.exe /C "cd . && E:\cc\SDK_NDK\ndk_r16b_for_android_studio\android-ndk-r16b\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-android --gcc-toolchain=E:/cc/SDK_NDK/ndk_r16b_for_android_studio/android-ndk-r16b/toolchains/aarch64-linux-android-4.9/prebuilt/windows-x86_64 --sysroot=E:/cc/SDK_NDK/ndk_r16b_for_android_studio/android-ndk-r16b/sysroot -fPIC -isystem E:/cc/SDK_NDK/ndk_r16b_for_android_studio/android-ndk-r16b/sysroot/usr/include/aarch64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -frtti -fexceptions -fsigned-char -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a --sysroot E:/cc/SDK_NDK/ndk_r16b_for_android_studio/android-ndk-r16b/platforms/android-21/arch-arm64 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -LE:/cc/SDK_NDK/ndk_r16b_for_android_studio/android-ndk-r16b/sources/cxx-stl/llvm-libc++/libs/arm64-v8a -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libMyGame.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\arm64-v8a\libMyGame.so CMakeFiles/MyGame.dir/Classes/AppDelegate.cpp.o CMakeFiles/MyGame.dir/Classes/HelloWorldScene.cpp.o CMakeFiles/MyGame.dir/proj.android/app/jni/hellocpp/main.cpp.o  -Wl,--whole-archive engine/cocos/platform/libcpp_android_spec.a -Wl,--no-whole-archive lib/libcocos2d.a lib/libexternal.a ../../../../../../cocos2d/external/Box2D/prebuilt/android/arm64-v8a/libbox2d.a ../../../../../../cocos2d/external/chipmunk/prebuilt/android/arm64-v8a/libchipmunk.a ../../../../../../cocos2d/external/freetype2/prebuilt/android/arm64-v8a/libfreetype.a lib/libext_recast.a ../../../../../../cocos2d/external/jpeg/prebuilt/android/arm64-v8a/libjpeg.a ../../../../../../cocos2d/external/webp/prebuilt/android/arm64-v8a/libwebp.a ../../../../../../cocos2d/external/bullet/prebuilt/android/arm64-v8a/libLinearMath.a ../../../../../../cocos2d/external/bullet/prebuilt/android/arm64-v8a/libBulletDynamics.a ../../../../../../cocos2d/external/bullet/prebuilt/android/arm64-v8a/libBulletCollision.a ../../../../../../cocos2d/external/bullet/prebuilt/android/arm64-v8a/libLinearMath.a ../../../../../../cocos2d/external/bullet/prebuilt/android/arm64-v8a/libBulletMultiThreaded.a ../../../../../../cocos2d/external/bullet/prebuilt/android/arm64-v8a/libMiniCL.a ../../../../../../cocos2d/external/tiff/prebuilt/android/arm64-v8a/libtiff.a ../../../../../../cocos2d/external/websockets/prebuilt/android/arm64-v8a/libwebsockets.a ../../../../../../cocos2d/external/uv/prebuilt/android/arm64-v8a/libuv_a.a ../../../../../../cocos2d/external/openssl/prebuilt/android/arm64-v8a/libssl.a ../../../../../../cocos2d/external/openssl/prebuilt/android/arm64-v8a/libcrypto.a lib/libext_tinyxml2.a lib/libext_xxhash.a lib/libext_xxtea.a lib/libext_clipper.a lib/libext_edtaa3func.a lib/libext_convertUTF.a lib/libext_poly2tri.a lib/libext_md5.a ../../../../../../cocos2d/external/curl/prebuilt/android/arm64-v8a/libcurl.a ../../../../../../cocos2d/external/png/prebuilt/android/arm64-v8a/libpng.a engine/external/android-specific/cpufeatures/libext_cpufeatures.a -ldl lib/libext_pvmp3dec.a lib/libext_tremolo.a ../../../../../../cocos2d/external/zlib/prebuilt/android/arm64-v8a/libz.a lib/libext_unzip.a -lGLESv2 -lEGL -llog -landroid -lOpenSLES -latomic -lm "E:/cc/SDK_NDK/ndk_r16b_for_android_studio/android-ndk-r16b/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++.a" && cd ."
CMakeFiles/MyGame.dir/Classes/HelloWorldScene.cpp.o: In function `HelloWorld':
E:\cocos2dx-3172\project3172cc\testmygame\proj.android\app\.externalNativeBuild\cmake\debug\arm64-v8a/../../../../../../Classes/HelloWorldScene.h:32: undefined reference to `GG_SceneBase::GG_SceneBase()'
CMakeFiles/MyGame.dir/Classes/HelloWorldScene.cpp.o:(.data.rel.ro+0x330): undefined reference to `GG_test::onEnter()'
CMakeFiles/MyGame.dir/Classes/HelloWorldScene.cpp.o:(.data.rel.ro+0x340): undefined reference to `GG_test::onExit()'
CMakeFiles/MyGame.dir/Classes/HelloWorldScene.cpp.o:(.data.rel.ro+0x560): undefined reference to `typeinfo for GG_test'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

You can easily modify Android.mk in any text editor,

you have to add this line in your Android.mk for every cpp file you add in your project
$(LOCAL_PATH)/…/…/…/Classes/GG_SceneBase.cpp

1 Like

This does not seem to be problem with Android.mk, now cocos uses CMake by default and Android.mk file is used only with ndk-build, you need to modify CMakeLists.txt and add your source file there, this should resolve this issue, or use ndk-build by setting property in proj.android/gradle.properties PROP_BUILD_TYPE=ndk-build instead of PROP_BUILD_TYPE=cmake.

1 Like

thank repy
i mean i can modify Android.mk but after modify when i run it will error

thank for help me !
so where is CMakeLists.txt and how to modify to add one class .cpp
sorry i am newbie!

You should be able to find CMakeLists.txt at top level directory besides cocos2dx.

list(APPEND GAME_SOURCE
     Classes/AppDelegate.cpp
     Classes/HelloWorldScene.cpp
     )
list(APPEND GAME_HEADER
     Classes/AppDelegate.h
     Classes/HelloWorldScene.h
     )

Add your source files just below line containing “Classes/HelloWorldScene.cpp” and add your header files below “Classes/HelloWorldScene.h”

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.