android 构建失败:尝试执行时出错 .. execv:执行格式错误

android build failed with: error trying to exec .. execv: Exec format error

这是我的问题。 我已经设置了 cocos2d-x 3.3。 使用

创建了新项目
cocos new Test3 -p com.MyCompany.Test3 -l cpp -d /Users/rahadiankumang/Documents/GITS/Cocos2dX

并尝试使用

构建项目
cocos run -s Test3 -p android

结果如下:

Running command: compile
Building mode: debug
Android platform not specified, searching a default one...
running: '/Users/rahadiankumang/Documents/adt-bundle-mac-x86_64-20140702/sdk/tools/android update project -t android-20 -p /Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android'

Updated project.properties
Updated local.properties
Updated file /Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android/proguard-project.txt
Android platform not specified, searching a default one...
running: '/Users/rahadiankumang/Documents/adt-bundle-mac-x86_64-20140702/sdk/tools/android update lib-project -p /Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android/../cocos2d/cocos/platform/android/java -t android-20'

Updated project.properties
Updated local.properties
Updated file /Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android/../cocos2d/cocos/platform/android/java/proguard-project.txt
building native
NDK build mode: debug
NDK_TOOLCHAIN_VERSION: 4.9
running: '/Users/rahadiankumang/Documents/GITS/Cocos2d-x/android-ndk-r10d/ndk-build -C /Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android -j4 NDK_MODULE_PATH=/Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android/../cocos2d:/Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android/../cocos2d/cocos:/Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android/../cocos2d/external NDK_TOOLCHAIN_VERSION=4.9 NDK_DEBUG=1'

Android NDK: WARNING: APP_PLATFORM android-19 is larger than android:minSdkVersion 9 in ./AndroidManifest.xml    
make: Entering directory `/Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android'
[armeabi] Compile++ thumb: cocostudio_static <= WidgetReader.cpp
[armeabi] Compile++ thumb: cocostudio_static <= FlatBuffersSerialize.cpp
[armeabi] Compile++ thumb: cocostudio_static <= WidgetCallBackHandlerProtocol.cpp
[armeabi] Compile++ thumb: cocos_ui_static <= UILayoutComponent.cpp
arm-linux-androideabi-g++: error trying to exec '/Users/rahadiankumang/Documents/GITS/Cocos2d-x/android-ndk-r10d/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/as': execv: Exec format error
make: *** [obj/local/armeabi/objs-debug/cocos_ui_static/UILayoutComponent.o] Error 1
make: *** Waiting for unfinished jobs....
arm-linux-androideabi-g++: error trying to exec '/Users/rahadiankumang/Documents/GITS/Cocos2d-x/android-ndk-r10d/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/as': execv: Exec format error
make: *** [obj/local/armeabi/objs-debug/cocostudio_static/WidgetCallBackHandlerProtocol.o] Error 1
arm-linux-androideabi-g++: error trying to exec '/Users/rahadiankumang/Documents/GITS/Cocos2d-x/android-ndk-r10d/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/as': execv: Exec format error
make: *** [obj/local/armeabi/objs-debug/cocostudio_static/WidgetReader/WidgetReader.o] Error 1
/Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android/../cocos2d/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp: In member function 'std::string cocostudio::FlatBuffersSerialize::serializeFlatBuffersWithXMLFile(const string&, const string&)':
/Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android/../cocos2d/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp:153:93: warning: 'virtual unsigned char* cocos2d::FileUtils::getFileData(const string&, const char*, ssize_t*)' is deprecated (declared at /Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android/../cocos2d/cocos/./platform/CCFileUtils.h:101) [-Wdeprecated-declarations]
     std::string content =(char*)FileUtils::getInstance()->getFileData(inFullpath, "r", &size);
                                                                                             ^
/Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android/../cocos2d/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp: In member function 'flatbuffers::FlatBufferBuilder* cocostudio::FlatBuffersSerialize::createFlatBuffersWithXMLFileForSimulator(const string&)':
/Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android/../cocos2d/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp:974:93: warning: 'virtual unsigned char* cocos2d::FileUtils::getFileData(const string&, const char*, ssize_t*)' is deprecated (declared at /Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android/../cocos2d/cocos/./platform/CCFileUtils.h:101) [-Wdeprecated-declarations]
     std::string content =(char*)FileUtils::getInstance()->getFileData(inFullpath, "r", &size);
                                                                                             ^
At global scope:
cc1plus: warning: unrecognized command line option "-Wno-extern-c-compat"
cc1plus: warning: unrecognized command line option "-Wno-extern-c-compat"
arm-linux-androideabi-g++: error trying to exec '/Users/rahadiankumang/Documents/GITS/Cocos2d-x/android-ndk-r10d/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/as': execv: Exec format error
make: *** [obj/local/armeabi/objs-debug/cocostudio_static/FlatBuffersSerialize.o] Error 1
make: Leaving directory `/Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android'
Ndk build failed!

我能够将项目导入 Eclipse,运行 它。但它在使用这些 logcat 启动后立即崩溃:

02-05 16:53:15.276: E/AndroidRuntime(12156): java.lang.UnsatisfiedLinkError: Couldn't load cocos2dcpp from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.MyCompany.Test3-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.MyCompany.Test3-1, /vendor/lib, /system/lib, /system/lib/arm]]]: findLibrary returned null
02-05 16:53:15.276: E/AndroidRuntime(12156):    at java.lang.Runtime.loadLibrary(Runtime.java:358)
02-05 16:53:15.276: E/AndroidRuntime(12156):    at java.lang.System.loadLibrary(System.java:526)
02-05 16:53:15.276: E/AndroidRuntime(12156):    at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:85)
02-05 16:53:15.276: E/AndroidRuntime(12156):    at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:99)
02-05 16:53:15.276: E/AndroidRuntime(12156):    at android.app.Activity.performCreate(Activity.java:5411)
02-05 16:53:15.276: E/AndroidRuntime(12156):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-05 16:53:15.276: E/AndroidRuntime(12156):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
02-05 16:53:15.276: E/AndroidRuntime(12156):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
02-05 16:53:15.276: E/AndroidRuntime(12156):    at android.app.ActivityThread.access0(ActivityThread.java:139)
02-05 16:53:15.276: E/AndroidRuntime(12156):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
02-05 16:53:15.276: E/AndroidRuntime(12156):    at android.os.Handler.dispatchMessage(Handler.java:102)
02-05 16:53:15.276: E/AndroidRuntime(12156):    at android.os.Looper.loop(Looper.java:149)
02-05 16:53:15.276: E/AndroidRuntime(12156):    at android.app.ActivityThread.main(ActivityThread.java:5268)
02-05 16:53:15.276: E/AndroidRuntime(12156):    at java.lang.reflect.Method.invokeNative(Native Method)
02-05 16:53:15.276: E/AndroidRuntime(12156):    at java.lang.reflect.Method.invoke(Method.java:515)
02-05 16:53:15.276: E/AndroidRuntime(12156):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-05 16:53:15.276: E/AndroidRuntime(12156):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
02-05 16:53:15.276: E/AndroidRuntime(12156):    at dalvik.system.NativeStart.main(Native Method)

我尝试用 build_native.py 构建项目,但也失败了。

这是结果

We will remove this script next version,you should use cocos console to build android project.

The Selected NDK toolchain version was 4.9 !
Android NDK: WARNING: APP_PLATFORM android-19 is larger than android:minSdkVersion 9 in ./AndroidManifest.xml    
make: Entering directory `/Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android'
[armeabi] Compile++ thumb: cocos2dcpp_shared <= AppDelegate.cpp
[armeabi] Compile++ thumb: cocos2dcpp_shared <= HelloWorldScene.cpp
[armeabi] Compile++ thumb: cocos2dcpp_shared <= main.cpp
[armeabi] StaticLibrary  : libcocos2d.a
/Users/rahadiankumang/Documents/GITS/Cocos2d-x/android-ndk-r10d/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ar: line 1: ../../bin/arm-linux-androideabi-ar: No such file or directory
make: *** [obj/local/armeabi/libcocos2d.a] Error 127
make: *** Waiting for unfinished jobs....
arm-linux-androideabi-g++: error trying to exec '/Users/rahadiankumang/Documents/GITS/Cocos2d-x/android-ndk-r10d/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/as': execv: Exec format error
make: *** [obj/local/armeabi/objs-debug/cocos2dcpp_shared/__/__/Classes/AppDelegate.o] Error 1
arm-linux-androideabi-g++: error trying to exec '/Users/rahadiankumang/Documents/GITS/Cocos2d-x/android-ndk-r10d/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/as': execv: Exec format error
make: *** [obj/local/armeabi/objs-debug/cocos2dcpp_shared/hellocpp/main.o] Error 1
arm-linux-androideabi-g++: error trying to exec '/Users/rahadiankumang/Documents/GITS/Cocos2d-x/android-ndk-r10d/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/as': execv: Exec format error
make: *** [obj/local/armeabi/objs-debug/cocos2dcpp_shared/__/__/Classes/HelloWorldScene.o] Error 1
make: Leaving directory `/Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android'
Traceback (most recent call last):
  File "./build_native.py", line 149, in <module>
    build(opts.ndk_build_param,opts.android_platform,opts.build_mode)
  File "./build_native.py", line 134, in build
    do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,android_platform,build_mode)
  File "./build_native.py", line 70, in do_build
    raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")
Exception: Build dynamic library for project [ /Users/rahadiankumang/Documents/GITS/Cocos2dX/Test3/proj.android ] fails!

我今天刚开始使用 cocos2d-x,对 Android NDK 不是很熟悉。

有人遇到过这个吗? 我一直在寻找类似的问题,但还没有结果。

NDK r10d
SDK API 20

谢谢。

基本上,我将 NDK 更改为 r9d,一切正常。

"cocos run -s Test3 -p android" 命令不再失败。