Cocos2d-x 桥接Android 原生文件配置问题

那你试下 在androi-studio 里打开项目,使用android-studio编译一下,看看可不可以正常编译

还是不行,会有下面的异常

Execution failed for task ':MyCppGame:externalNativeBuildDebug'.

Build command failed.
Error while executing process /Users/yuejz/Library/Android/sdk/ndk/android-ndk-r16b/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/MyCppGame/proj.android/app/jni/Android.mk NDK_APPLICATION_MK=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/MyCppGame/proj.android/app/jni/Application.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=1 APP_PLATFORM=android-16 NDK_OUT=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/MyCppGame/proj.android/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/MyCppGame/proj.android/app/build/intermediates/ndkBuild/debug/lib NDK_TOOLCHAIN_VERSION=clang -j4 NDK_MODULE_PATH=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/MyCppGame/cocos2d:/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/MyCppGame/cocos2d/cocos:/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/MyCppGame/cocos2d/external NDK_DEBUG=1 MyGame}

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

你的项目路径可能太长了,,,,

我将目录只在 Classes 下,只保留了一级,还是不行

我说的是你整个项目的路径

我放在了我的目录下,还是不行


你看一下编译过程,别只看最后
还有 往上看看 有没有error 等信息
是编译c++出了问题还是连接问题,还是其他问题,往上找找

NDK_PROJECT_PATH=null
这个没有问题

你的jar包 加到lib里了么?

试试 在android-studio里
xxx.jar 右击选择add as library

注:
一般是在android-studio里 把需要的都配置好,最好是可以使用android-studio里可以打包了,再用命令行打包
建议你也这样(android-studio 提示等还是挺方便的,报错信息等也很清晰)

我现在完全新建了一个项目,运行没有问题,但是将 gradle.properties 中的 PROP_BUILD_TYPE 修改问 ndk-build,使用 Android Studio 编译,仍然编译不过,会有下面的提示

如果用 cocos compile -p android --build-type ndk-build 命令行构建,会出现以下的错误,我发现将 3.17.2 更改为 ndk-build 会有 .cxx 目录,但如果用 3.15 编译,会创建 .externalNativeBuild,而按照日志提示,是创建 .externalNativeBuild 目录失败,可能是这个原因嘛?我应该怎么配置?

> Task :MyCppGame:externalNativeBuildDebug FAILED

Task :MyCppGame:externalNativeBuildDebug in libcocos2dx Starting
Caching disabled for task ‘:MyCppGame:externalNativeBuildDebug’ because:
Build cache is disabled
Task ‘:MyCppGame:externalNativeBuildDebug’ is not up-to-date because:
Task.upToDateWhen is false.
starting build
reading expected JSONs
WARNING: This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
WARNING: This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
done reading expected JSONs
WARNING: This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
WARNING: This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
executing build commands for targets: ‘MyGame’
evaluate miniconfig
WARNING: This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
WARNING: This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
evaluate library ext_vorbisidec (armeabi-v7a)
not building target ext_vorbisidec because it isn’t in targets set
evaluate library cc_core (armeabi-v7a)
not building target cc_core because it isn’t in targets set
evaluate library ui (armeabi-v7a)
not building target ui because it isn’t in targets set
evaluate library spine (armeabi-v7a)
not building target spine because it isn’t in targets set
evaluate library net (armeabi-v7a)
not building target net because it isn’t in targets set
evaluate library recast (armeabi-v7a)
not building target recast because it isn’t in targets set
evaluate library c3d (armeabi-v7a)
not building target c3d because it isn’t in targets set
evaluate library flatbuffers (armeabi-v7a)
not building target flatbuffers because it isn’t in targets set
evaluate library ccandroid (armeabi-v7a)
not building target ccandroid because it isn’t in targets set
evaluate library audio (armeabi-v7a)
not building target audio because it isn’t in targets set
evaluate library cpufeatures (armeabi-v7a)
not building target cpufeatures because it isn’t in targets set
evaluate library MyGame (armeabi-v7a)
evaluate library ets (armeabi-v7a)
not building target ets because it isn’t in targets set
evaluate library ccs (armeabi-v7a)
not building target ccs because it isn’t in targets set
evaluate library ccb (armeabi-v7a)
not building target ccb because it isn’t in targets set
evaluate library ext_pvmp3dec (armeabi-v7a)
not building target ext_pvmp3dec because it isn’t in targets set
evaluate library ccds (armeabi-v7a)
not building target ccds because it isn’t in targets set
WARNING: This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
about to build targets MyGame
Executable : /Users/yuejz/Library/Android/sdk/ndk/android-ndk-r14b/ndk-build
arguments :
NDK_PROJECT_PATH=null
APP_BUILD_SCRIPT=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app/jni/Android.mk
NDK_APPLICATION_MK=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app/jni/Application.mk
APP_ABI=armeabi-v7a
NDK_ALL_ABIS=armeabi-v7a
NDK_DEBUG=1
APP_PLATFORM=android-16
NDK_OUT=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app/build/intermediates/ndkBuild/debug/obj
NDK_LIBS_OUT=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app/build/intermediates/ndkBuild/debug/lib
NDK_TOOLCHAIN_VERSION=clang
-j4
NDK_MODULE_PATH=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/cocos2d:/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/cocos2d/cocos:/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/cocos2d/external
NDK_DEBUG=1
MyGame
jvmArgs :

Build MyGame_armeabi-v7a
WARNING: This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
WARNING: This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
This app only has 32-bit [armeabi-v7a] native libraries. Beginning August 1, 2019 Google Play store requires that all apps that include native libraries must provide 64-bit versions. For more information, visit https://g.co/64-bit-requirement
Executable : /Users/yuejz/Library/Android/sdk/ndk/android-ndk-r14b/ndk-build
arguments :
NDK_PROJECT_PATH=null
APP_BUILD_SCRIPT=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app/jni/Android.mk
NDK_APPLICATION_MK=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app/jni/Application.mk
APP_ABI=armeabi-v7a
NDK_ALL_ABIS=armeabi-v7a
NDK_DEBUG=1
APP_PLATFORM=android-16
NDK_OUT=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app/build/intermediates/ndkBuild/debug/obj
NDK_LIBS_OUT=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app/build/intermediates/ndkBuild/debug/lib
NDK_TOOLCHAIN_VERSION=clang
-j4
NDK_MODULE_PATH=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/cocos2d:/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/cocos2d/cocos:/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/cocos2d/external
NDK_DEBUG=1
MyGame
jvmArgs :

Starting process ‘command ‘/Users/yuejz/Library/Android/sdk/ndk/android-ndk-r14b/ndk-build’’. Working directory: /Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app Command: /Users/yuejz/Library/Android/sdk/ndk/android-ndk-r14b/ndk-build NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app/jni/Android.mk NDK_APPLICATION_MK=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app/jni/Application.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=1 APP_PLATFORM=android-16 NDK_OUT=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app/build/intermediates/ndkBuild/debug/lib NDK_TOOLCHAIN_VERSION=clang -j4 NDK_MODULE_PATH=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/cocos2d:/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/cocos2d/cocos:/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/cocos2d/external NDK_DEBUG=1 MyGame
Successfully started process ‘command ‘/Users/yuejz/Library/Android/sdk/ndk/android-ndk-r14b/ndk-build’’
make: *** No rule to make target `MyGame’. Stop.
Task :MyCppGame:externalNativeBuildDebug in libcocos2dx Finished
:MyCppGame:externalNativeBuildDebug (Thread[Execution worker for ‘:’,5,main]) completed. Took 1.35 secs.

Task :MyCppGame:processDebugManifestForPackage
Task :MyCppGame:processDebugManifestForPackage in libcocos2dx Starting
Caching disabled for task ‘:MyCppGame:processDebugManifestForPackage’ because:
Build cache is disabled
Task ‘:MyCppGame:processDebugManifestForPackage’ is not up-to-date because:
Input property ‘mergedManifests’ file /Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app/build/intermediates/merged_manifests/debug/AndroidManifest.xml has changed.
Task :MyCppGame:processDebugManifestForPackage in libcocos2dx Finished
:MyCppGame:processDebugManifestForPackage (Thread[Daemon worker Thread 6,5,main]) completed. Took 1.365 secs.

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:MyCppGame:externalNativeBuildDebug’.

Build command failed.
Error while executing process /Users/yuejz/Library/Android/sdk/ndk/android-ndk-r14b/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app/jni/Android.mk NDK_APPLICATION_MK=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app/jni/Application.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=1 APP_PLATFORM=android-16 NDK_OUT=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/proj.android/app/build/intermediates/ndkBuild/debug/lib NDK_TOOLCHAIN_VERSION=clang -j4 NDK_MODULE_PATH=/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/cocos2d:/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/cocos2d/cocos:/Users/yuejz/cocos2d/workspace/Cocos2dx-3172/Cocos2dxDemo1/MyCppGame/cocos2d/external NDK_DEBUG=1 MyGame}

make: *** No rule to make target `MyGame’. Stop.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 2s
45 actionable tasks: 5 executed, 40 up-to-date
执行命令出错,返回值:1。
➜ MyCppGame cocos compile -p android --build-type ndk-build

你用的ndk14???
我记得某个版本之后
要ndk16以上了。。。

我尝试了 android-ndk-r16b 和 android-ndk-r18b,仍然不行