JDK版本错误
* What went wrong:
Execution failed for task ':FirstCocos:externalNativeBuildDebug'.
> Build command failed.
63 actionable tasks: 5 executed, 58 up-to-date
Error while executing process /Users/admin/Library/Android/sdk/ndk/19.2.5345600/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/admin/ITCode/FirstCocosProject/build/jsb-link/frameworks/runtime-src/proj.android-studio/app/jni/Android.mk NDK_APPLICATION_MK=/Users/admin/ITCode/FirstCocosProject/build/jsb-link/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk APP_ABI=arm64-v8a NDK_ALL_ABIS=arm64-v8a NDK_DEBUG=1 APP_PLATFORM=android-16 NDK_OUT=/Users/admin/ITCode/FirstCocosProject/build/jsb-link/frameworks/runtime-src/proj.android-studio/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=/Users/admin/ITCode/FirstCocosProject/build/jsb-link/frameworks/runtime-src/proj.android-studio/app/build/intermediates/ndkBuild/debug/lib NDK_TOOLCHAIN_VERSION=clang NDK_MODULE_PATH=/Applications/CocosCreator/Creator/2.4.9/CocosCreator.app/Contents/Resources/cocos2d-x:/Applications/CocosCreator/Creator/2.4.9/CocosCreator.app/Contents/Resources/cocos2d-x/cocos:/Applications/CocosCreator/Creator/2.4.9/CocosCreator.app/Contents/Resources/cocos2d-x/external -j8 NDK_DEBUG=1 cocos2djs}
ERROR: Unknown host CPU architecture: arm64
原因
出现上面的错误的可能原因有两个:
- 当前设备的JDK版本不是JDK8(1.8.x),Cocos2.4.9只支持JDK8
- 当前用的是openjdk Jre环境,而不是Java SE
解决方案
去Java Downloads下载官网下载完整的JDK8版本。
缺少tools.jar
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':libcocos2dx:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation.
MAC电脑会出现此问题,JDK8安装到设备上会有个插件。设备会默认使用插件内到JDK环境。
而插件内到JDK是缺少tools.jar的。
解决方案
找到你的JDK8安装目录/Contents/Home/lib
中拷贝一份tools.jar
默认在/Library/Java/JavaVirtualMachines
复制tools.jar粘贴到/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib