Home Database Mysql Tutorial ubuntu下安装cocos2d

ubuntu下安装cocos2d

Jun 07, 2016 pm 03:08 PM
ubuntu long time Install source code

折腾了半天,源代码有bug,自己修改了一下才可以用 环境ubuntu12.10 cocos2d-x最新版本 1. git clonehttps://github.com/cocos2d/cocos2d-x.git下载cocos2d-x源代码 2. 官方下载ndk,我的是64位版本android-ndk-r8e 3. 官方下载sdk,我的eclipse之前已经下载过

折腾了半天,源代码有bug,自己修改了一下才可以用

环境ubuntu12.10 + cocos2d-x最新版本

1. git clone https://github.com/cocos2d/cocos2d-x.git下载cocos2d-x源代码

2. 官方下载ndk,我的是64位版本android-ndk-r8e

3. 官方下载sdk,我的eclipse之前已经下载过了,直接拿来用android-sdks

4. 进入cocos2d-x,开始编译,不过g++版本要修改为4.6或以上

5. 打开./make-all-linux-project.sh, 修改NDK和SDK的路径,运行 ./make-all-linux-project.sh,等待几分钟即可编译完成

6. 运行./create-android-project.sh来根据提示创建一个工程

问题就出现在第六步,总是提示:

cp: 无法获取"/home/lsc/disk/cocos2d-x/cocos2d-x/samples/Cpp/HelloCpp/proj.android/{jni,src}" 的文件状态(stat): 没有那个文件或目录
/home/lsc/disk/cocos2d-x/cocos2d-x/template/android/gamemk.sh: 32: /home/lsc/disk/cocos2d-x/cocos2d-x/template/android/gamemk.sh: cannot create /home/lsc/disk/cocos2d-x/cocos2d-x/Hello/proj.android/jni/Android.mk: Directory nonexistent
sed: 无法读取 /home/lsc/disk/cocos2d-x/cocos2d-x/Hello/proj.android/src/org/cocos2dx/hellocpp/HelloCpp.java: 没有那个文件或目录

发现在template/android/copy_files.sh中出错在这一行

cp -rf $HELLOWORLD_ROOT/proj.android/{jni,src} $APP_DIR/proj.android

没办法,把他们分开写成两行去:

     cp -rf $HELLOWORLD_ROOT/proj.android/jni $APP_DIR/proj.android
     cp -rf $HELLOWORLD_ROOT/proj.android/src $APP_DIR/proj.android 

保存再编译,问题解决了

7. 接着进入刚才创建好的工程目录下,我的名字叫firstdemo,该工程下有proj.android目录,进入运行脚本./build_native.sh,这样过了两分钟,编译C++生成libgame.so库

8.我们好要编译android apk,所以打开eclipse,导入该工程,这时候由于没有加入jar包,所以会提示有些java类找不到

9.jar包路径在cocos2d-x/cocos2dx/platform/android/java/bin/libcocos2dx.jar,我刚开始的时候是按照网上的方法导入jar包的,就是右键项目->build path ->configrue build path-> add external JARs, 这样是没有语法错误了,编译也成功了, 可是运行apk的时候总是提示如下log:

W/dalvikvm( 4677): Unable to resolve superclass of Lcom/android/cocos2dx/demo/firstdemo; (21)
W/dalvikvm( 4677): Link of class 'Lcom/android/cocos2dx/demo/firstdemo;' failed
D/AndroidRuntime( 4677): Shutting down VM
W/dalvikvm( 4677): threadid=1: thread exiting with uncaught exception (group=0x40aa5930)
I/SurfaceFlinger( 1076): GraphicBufferAlloc::createGraphicBuffer
E/AndroidRuntime( 4677): FATAL EXCEPTION: main
E/AndroidRuntime( 4677): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.android.cocos2dx.demo/com.android.cocos2dx.demo.firstdemo}: java.lang.ClassNotFoundException: Didn't find class "com.android.cocos2dx.demo.firstdemo" on path: /data/app/com.android.cocos2dx.demo-2.apk
E/AndroidRuntime( 4677):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
E/AndroidRuntime( 4677):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
E/AndroidRuntime( 4677):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime( 4677):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
E/AndroidRuntime( 4677):     at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 4677):     at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 4677):     at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime( 4677):     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 4677):     at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 4677):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime( 4677):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime( 4677):     at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 4677): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.android.cocos2dx.demo.firstdemo" on path: /data/app/com.android.cocos2dx.demo-2.apk
E/AndroidRuntime( 4677):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)

刚开始以为AndroidMainfest.xml的 android:name有问题,可是怎么修改都不行,仔细看了log才发现Unable to resolve superclass of这一句,很明显是找不到jar包的类了

果断怀疑是jar包导入的问题,接着把刚导入的jar包删除,直接复制libcocos2dx.jar文件,在eclipse窗口中右击libs文件夹,直接选择粘帖,再运行,问题解决,可以看到

画面了,网上也找到一个据说是正确导入jar包的方法,原文如下:

在网上查了一下,有人说上面的做法有可能会出错,建议采用下面的步骤:

     右键工程,
     Build path,
    java build path,选择libraries
     在右边的按钮中点击“Add Library”
     选择“User library”,点击“下一步”
     点击“User librarys”按钮
     在出现的界面中点击“New..”按钮
     在弹出的界面中随便起一个名字,点击“确定”
     点击“Add jars”按钮选择第三方jar包,点击“确定”完成操作。
这样的话该jar包会被一起打包到apk中,问题也就解决了!


接着我发现这样子每次都要先在shell中编译C++部分,然后在eclipse中编译android部分,很麻烦,网上找了一下,有没有解决,找到了一篇比较详细的说明,直接拿来用,发现没问题,原文如下:

http://www.ityran.com/archives/1062

通过命令脚本来编译c++代码,完了之后用eclipse来编译java代码,这种来回切换的做法非常笨重。如果全部可以用eclipse来完成的话,那么生活会更简单一些。

    幸运的是,我们可以告诉eclipse,我们的android项目是一个集成java/c++的跨语言项目!

   为此,我们在左边的项目树上选择samplecocos2dxandroid,然后从菜单里面选择File\New\Other,然后从对话框里面选择C/C++\Convert to a C/C++ Project,如下所示:

ubuntu下安装cocos2d

   点击Next。在下一个屏幕里面,选中你的项目,然后选择c++单选按钮,然后为Project type指定Makefile project\Other Toolchain,如下所示:

ubuntu下安装cocos2d

    点击完成。这时eclipse会询问你是否打开C/C++视图,当对话框出现的时候,选择NO。

   接下来的步骤就是修改项目设置,指定如何运行我们的make命令。在左边的项目树上,右击samplecocos2dxandroid工程,选择Properties,然后选择C/C++ build

ubuntu下安装cocos2d

    取消“Use default build command”复选框,然后在build文本框中输入下面的命令:

<ol><li value="1">bash ${workspace_loc:/samplecocos2dxandroid}/build_native.sh NDK_DEBUG=1 V=1</li></ol>
Copy after login

   点击Apply,然后点OK。

   回到eclipse,从主菜单中选择Project\Build All,这时你可以在eclipse的控制台输出中看到c++ make在运行。

ubuntu下安装cocos2d

   我们仍然有一些警告需要解决。想知道我是什么意思吗,你打开jni/helloworld/main.cpp,这里你会看到一系列的警告,如下所示:

ubuntu下安装cocos2d

    这些警告之所以会出现,是因为我们没有配置正确的c++包含路径。为了解决它,我们右击samplecocos2dxandroid工程,然后选择Properties\C/C++ General\Path and Symbols\GNU C++

   选择Add按钮来选择下面的目录,之后点击Apply和OK。

<ol><li value="1">$(NDKROOT)/platforms/android-9/arch-arm/usr/include $(COCOS2DX_HOME)/cocos2dx/include</li></ol>
Copy after login

注意: 不用忘了使用实际的路径来替换掉$(NDKROOT)$(COCOS2DX_HOME)

ubuntu下安装cocos2d

   点击Apply,这时会提示你是否重建索引。直接点击yes继续就可以了。

   现在,你再看看main.cpp,你会看到大部分警告已经消失了。

ubuntu下安装cocos2d

    但是,AppDelegate.h文件还是找不到。这是因为AppDelegate.h是在$PROJECT_HOME\Classes文件夹下面。这个文件夹对我们来说非常重要,因为它包含了我们工程里面的可移植的c++类,比如HelloWorldScene.cpp等。

    当我们创建eclipse项目的时候,我们必须选择$PROJECT_HOME\android文件夹,因为eclipse需要一个AndroidManifest.xml文件。但是,这样的话,我们的工程就不包括关键的“Classes”文件夹了,这也是为什么我们会得到这么多警告的原因。

   让我们来修正它吧。右击samplecocos2dxandroid项目,选择Properties\C/C++ General\Paths and Symbols\Source location。点击Link Folder,然后复选中Link to a folder in the file system,接着浏览到$PROJECT_HOME文件夹,并指向Classes目录,最后点Apply和OK。

ubuntu下安装cocos2d

   你现在可以在文件树里面看到Classes目录了,而且在main.cpp里面的#include “AppDelegate.h”警告也应该消失了。

   Eclipse工程里面还会有许多警告,但是,这是因为eclipse对于解析c++头文件的能力并不强大。为了消除这些警告,我们又需要设置一下项目设置。(右键点工程,然后选择Properties),把Code Analysis部分的warnings关闭,如下图所示:

ubuntu下安装cocos2d

   然后点击Apply和OK,这时,你就得到一个工程可以在eclipse里面进行编辑了。





Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution to the problem that Win11 system cannot install Chinese language pack Solution to the problem that Win11 system cannot install Chinese language pack Mar 09, 2024 am 09:48 AM

Solution to the problem that Win11 system cannot install Chinese language pack With the launch of Windows 11 system, many users began to upgrade their operating system to experience new functions and interfaces. However, some users found that they were unable to install the Chinese language pack after upgrading, which troubled their experience. In this article, we will discuss the reasons why Win11 system cannot install the Chinese language pack and provide some solutions to help users solve this problem. Cause Analysis First, let us analyze the inability of Win11 system to

Unable to install guest additions in VirtualBox Unable to install guest additions in VirtualBox Mar 10, 2024 am 09:34 AM

You may not be able to install guest additions to a virtual machine in OracleVirtualBox. When we click on Devices>InstallGuestAdditionsCDImage, it just throws an error as shown below: VirtualBox - Error: Unable to insert virtual disc C: Programming FilesOracleVirtualBoxVBoxGuestAdditions.iso into ubuntu machine In this post we will understand what happens when you What to do when you can't install guest additions in VirtualBox. Unable to install guest additions in VirtualBox If you can't install it in Virtua

Log in to Ubuntu as superuser Log in to Ubuntu as superuser Mar 20, 2024 am 10:55 AM

In Ubuntu systems, the root user is usually disabled. To activate the root user, you can use the passwd command to set a password and then use the su- command to log in as root. The root user is a user with unrestricted system administrative rights. He has permissions to access and modify files, user management, software installation and removal, and system configuration changes. There are obvious differences between the root user and ordinary users. The root user has the highest authority and broader control rights in the system. The root user can execute important system commands and edit system files, which ordinary users cannot do. In this guide, I'll explore the Ubuntu root user, how to log in as root, and how it differs from a normal user. Notice

What should I do if Baidu Netdisk is downloaded successfully but cannot be installed? What should I do if Baidu Netdisk is downloaded successfully but cannot be installed? Mar 13, 2024 pm 10:22 PM

If you have successfully downloaded the installation file of Baidu Netdisk, but cannot install it normally, it may be that there is an error in the integrity of the software file or there is a problem with the residual files and registry entries. Let this site take care of it for users. Let’s introduce the analysis of the problem that Baidu Netdisk is successfully downloaded but cannot be installed. Analysis of the problem that Baidu Netdisk downloaded successfully but could not be installed 1. Check the integrity of the installation file: Make sure that the downloaded installation file is complete and not damaged. You can download it again, or try to download the installation file from another trusted source. 2. Turn off anti-virus software and firewall: Some anti-virus software or firewall programs may prevent the installation program from running properly. Try disabling or exiting the anti-virus software and firewall, then re-run the installation

Tutorial on updating curl version under Linux! Tutorial on updating curl version under Linux! Mar 07, 2024 am 08:30 AM

To update the curl version under Linux, you can follow the steps below: Check the current curl version: First, you need to determine the curl version installed in the current system. Open a terminal and execute the following command: curl --version This command will display the current curl version information. Confirm available curl version: Before updating curl, you need to confirm the latest version available. You can visit curl's official website (curl.haxx.se) or related software sources to find the latest version of curl. Download the curl source code: Using curl or a browser, download the source code file for the curl version of your choice (usually .tar.gz or .tar.bz2

How to install Android apps on Linux? How to install Android apps on Linux? Mar 19, 2024 am 11:15 AM

Installing Android applications on Linux has always been a concern for many users. Especially for Linux users who like to use Android applications, it is very important to master how to install Android applications on Linux systems. Although running Android applications directly on Linux is not as simple as on the Android platform, by using emulators or third-party tools, we can still happily enjoy Android applications on Linux. The following will introduce how to install Android applications on Linux systems.

How to install Angular on Ubuntu 24.04 How to install Angular on Ubuntu 24.04 Mar 23, 2024 pm 12:20 PM

Angular.js is a freely accessible JavaScript platform for creating dynamic applications. It allows you to express various aspects of your application quickly and clearly by extending the syntax of HTML as a template language. Angular.js provides a range of tools to help you write, update and test your code. Additionally, it provides many features such as routing and form management. This guide will discuss how to install Angular on Ubuntu24. First, you need to install Node.js. Node.js is a JavaScript running environment based on the ChromeV8 engine that allows you to run JavaScript code on the server side. To be in Ub

Android TV Box gets unofficial Ubuntu 24.04 upgrade Android TV Box gets unofficial Ubuntu 24.04 upgrade Sep 05, 2024 am 06:33 AM

For many users, hacking an Android TV box sounds daunting. However, developer Murray R. Van Luyn faced the challenge of looking for suitable alternatives to the Raspberry Pi during the Broadcom chip shortage. His collaborative efforts with the Armbia

See all articles