search
HomeDatabaseMysql Tutorialubuntu下安装cocos2d

ubuntu下安装cocos2d

Jun 07, 2016 pm 03:08 PM
ubuntulong timeInstallsource 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>

   点击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>

注意: 不用忘了使用实际的路径来替换掉$(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
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
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

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

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download

Atom editor mac version download

The most popular open source editor