Cocos2d-x 3.x 如何编译成安卓程序

1.安装JDK

2.安装eclipse,安卓官方现在不提供eclipse for android,只好自己配置了。首先安装一个eclipse,在Help——Install New SoftWare中安装ADT

地址为http://dl-ssl.google.com/android/eclipse

可能需要漫长的等待。

3.创建AVD。根据http://www.cocos2d-x.org/boards/6/topics/12563 所说,需要安装4.0.3以上的虚拟机。

4.在eclipse中导入proj.android工程,会自动编译,需要等待几分钟。

编译完成后,发现有一个错误提示,从工程——cocos2d——cocos——platform——android——java——src中将org和com文件夹拷贝到当前工程中,错误提示消失。

5.在虚拟机运行的时候,又遇到了另一个错误:

java.lang.IllegalArgumentException: No configs match configSpec

解决方法:

①在AndroidMainfest文件中将<uses-feature android:glEsVersion="0x00020000">改为
<uses-feature android:glEsVersion="0x00020000" android:required="true" />

②在android-sdk安装目录下的 \samples\android-16\ApiDemos\src\com\example\android\apis\graphics里

GLES20Activity.java中的方法detectOpenGLES20,修改成

复制代码
import android.os.Build;  
private boolean detectOpenGLES20() {  
        ActivityManager am =  
            (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);  
        ConfigurationInfo info = am.getDeviceConfigurationInfo();  
        return (info.reqGlEsVersion >= 0x20000 || Build.FINGERPRINT.startsWith('generic'));  
    }  
复制代码

 

③在AVD设置中勾选Use Host GPU

6.终于正常运行了!另:在manifest中修改为android:screenOrientation="portrait"可以设为竖屏,默认为横屏。

posted @ 2015-03-30 22:15  滴水瓦  阅读(353)  评论(0编辑  收藏  举报