这两天搞跨平台的东西,发现cocos2dx不能在模拟器上运行,在网上查了查竟然没有这样的问题,最后还是靠stackoverflow定位到cocos2dx英文论坛中,最终找到了解决方案。
1.使用的引擎版本 cocos2d-2.0-rc0a-x-2.0
2.创建一个android工程后,打开项目,比如项目名称为test,就打开test.java
修改如下(默认有detectOpenGLES20函数,在return中添加Build.FINGERPRINT.startsWith("generic") )
- private boolean detectOpenGLES20()
- {
- ActivityManager am =
- (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
- ConfigurationInfo info = am.getDeviceConfigurationInfo();
- return (info.reqGlEsVersion >= 0x20000|| <span style="color:#ff0000;">Build.FINGERPRINT.startsWith("generic")</span>);
- }
3.编辑AndroidManifest.xml如下,在最后添加
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.sx.test3"
- android:versionCode="1"
- android:versionName="1.0">
- <uses-sdk android:minSdkVersion="8"/>
- <application android:label="@string/app_name"
- android:debuggable="true"
- android:icon="@drawable/ic_launcher">
- <activity android:name=".test3"
- android:label="@string/app_name"
- android:screenOrientation="landscape"
- android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
- android:configChanges="orientation">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- <supports-screens android:largeScreens="true"
- android:smallScreens="true"
- android:anyDensity="true"
- android:normalScreens="true"/>
- <span style="color:#ff0000;"><uses-feature android:glEsVersion="0x00020000" android:required="true" /></span>
- </manifest>
4.编辑Emulator,如下需要开启GPU
5.运行cocos2dx的android工程,如下
参考地址:
http://www.cocos2d-x.org/boards/6/topics/12563 (最终解决方案)
http://stackoverflow.com/questions/12203918/failure-in-running-helloworld-cocos2dx?rq=1
https://github.com/cocos2d/cocos2d-x/issues/1080