Install cocos2d in ubuntu

Source: Internet
Author: User
After a long time, the source code has a bug. You can use the latest version of ubuntu12.10cocos2d-x to modify the environment. gitclonegithub. comcocos2dcocos2d-x.git download cocos2d-x Source Code 2. download ndk, my 64-bit version android-ndk-r8e3. download the sdk officially. My eclipse has been downloaded before.

Tossing for a long time, there are bugs in the source code, you can modify it yourself to use the environment ubuntu12.10 cocos2d-x Latest Version 1. git clonehttps: // github.com/cocos2d/cocos2d-x.gitdownload cocos2d-xsource Code 2. download ndk officially, my 64-bit version android-ndk-r8e 3. download the sdk officially. My eclipse has been downloaded before.

After a long time, the source code has bugs and can be used only after modification.

Environment ubuntu12.10 + cocos2d-x Latest Version

1. git clone https://github.com/cocos2d/cocos2d-x.gitdownload cocos2d-xsource code

2. Download ndk officially, my 64-bit version android-ndk-r8e

3. Download the sdk from the official website. I have already downloaded the sdk from eclipse and used it directly to use android-sdks.

4. Go to the cocos2d-x and start compiling, but the g ++ version needs to be modified to 4.6 or later.

5. Open the./make-all-linux-project.sh, modify the NDK and SDK paths, run the./make-all-linux-project.sh, wait a few minutes until compilation is complete

6. Run./create-android-project.sh to create a project as prompted

The problem occurs in step 6, always prompting:

Cp: Unable to get "/home/lsc/disk/cocos2d-x/cocos2d-x/samples/Cpp/HelloCpp/proj. android/{jni, src} "File status (stat): no file or directory
/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: unable to read/home/lsc/disk/cocos2d-x/cocos2d-x/Hello/proj. android/src/org/cocos2dx/hellocpp/HelloCpp. java: No that file or directory

An error occurred in template/android/copy_files.sh.

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

There is no way to separate them into two rows:

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

Save and compile. The problem is solved.

7. next, go to the created project directory. My name is firstdemo, which contains proj. go to the android directory and run the script. /build_native.sh. After two minutes, compile C ++ to generate libgame. so Library

8. To compile the android apk, open eclipse and import the project. Because the jar package is not added, some java classes cannot be found.

9. jar package path in cocos2d-x/cocos2dx/platform/android/java/bin/libcocos2dx. jar. At the beginning, I imported the jar package according to the online method. Right-click the project and choose Project> build path> configrue build path> add external JARs, in this way, no syntax error occurs and compilation is successful. However, the following log is always prompted when running the apk:

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 (0, 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. initialize mlaunchactivity (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)

Initially thought AndroidMainfest. the android: name of xml has a problem, but it cannot be modified. After carefully reading the log, we can find the Unable to resolve superclass of statement. Obviously, we cannot find the jar package class.

I suspect it is a jar package import problem. Then I will delete the newly imported jar package and copy libcocos2dx directly. jar file, right-click the libs folder in the eclipse window, select paste, and then run. The problem is solved. You can see

As shown in the following figure, a method is also found on the Internet to import the jar package correctly. The original Article is as follows:

I checked it online. Some people said that the above practice may fail. We recommend that you follow the steps below:

Right-click the project,
Build path,
Java build path, select libraries
Click "Add Library" in the button on the right"
Select "User library" and click "Next"
Click "User librarys ".
On the displayed page, click "New ...".
In the pop-up interface, enter a name and click "OK"
Click "Add jars" to select a third-party jar package and click "OK" to complete the operation.
In this case, the jar package will be packaged into the apk together, and the problem will be solved!


Then I found that C ++ must be compiled in shell every time, and then android must be compiled in eclipse. This is very troublesome. I found out if I have solved the problem on the Internet, I found a detailed description and used it directly. The original Article is as follows:

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

Compile the c ++ code by using the command script, and use eclipse to compile the java code after completion. This round-trip switching method is very cumbersome. If you can use eclipse to complete all the tasks, your life will be simpler.

Fortunately, we can tell eclipse that our android Project is a cross-language project integrating java/c ++!

To this end, select samplecocos2dxandroid in the left-side project tree, and select File \ New \ Other from the menu, then select C/C ++ \ Convert to a C/C ++ Project from the dialog box, as shown below:

Click Next. On the next screen, select your Project, select the c ++ radio button, and specify Makefile project \ Other Toolchain for the Project type, as shown below:

Click Finish. At this time, eclipse will ask you whether to open the C/C ++ view. When the dialog box appears, select NO.

The next step is to modify the Project Settings and specify how to run the make command. On the project tree on the left, right-click the samplecocos2dxandroid project, select Properties, and select C/C ++ build.

Deselect the "Use default build command" check box and enter the following command in the build text box:

 
 
  1. bash ${workspace_loc:/samplecocos2dxandroid}/build_native.sh NDK_DEBUG=1 V=1

Click Apply and click OK.

Return to eclipse and select Project \ Build All from the main menu. Then, you can see that c ++ make is running in the eclipse console output.

We still have some warnings to solve. Do you want to know what I mean? Open jni/helloworld/main. cpp and you will see a series of warnings as follows:

These warnings appear because we have not configured the correct c ++ inclusion path. To solve this problem, right-click the samplecocos2dxandroid project and select Properties \ C/C ++ General \ Path and Symbols \ gnu c ++.

Select Add... Select the following directory, and then click Apply and OK.

 
 
  1. $(NDKROOT)/platforms/android-9/arch-arm/usr/include $(COCOS2DX_HOME)/cocos2dx/include

Note: you do not need to forget to use the actual path to replace $ (NDKROOT) and $ (COCOS2DX_HOME ).

Click Apply, and you will be prompted whether to re-create the index. Click yes to continue.

Now, let's take a look at main. cpp, and you will see that most of the warnings have gone away.

However, the AppDelegate. h file still cannot be found. This is because AppDelegate. h is under the $ PROJECT_HOME \ Classes folder. This folder is very important to us because it contains portable c ++ classes in our project, such as HelloWorldScene. cpp.

When creating an eclipse project, You must select the $ PROJECT_HOME \ android folder because eclipse requires an AndroidManifest. xml file. However, in this case, our project does not include the key "Classes" folder, which is why we get so many warnings.

Let's fix it. Right-click the samplecocos2dxandroid project and select Properties \ C/C ++ General \ Paths and Symbols \ Source location. Click Link Folder, select Link to a folder in the file system, browse to the $ PROJECT_HOME Folder, point to the Classes directory, and click Apply and OK.

Now you can see the Classes directory in the file tree, And the # include "AppDelegate. h" warning in main. cpp should also disappear.

There are still many warnings in the Eclipse project, but this is because eclipse is not powerful in parsing c ++ header files. To eliminate these warnings, we need to set the project settings. (Right-click the project and select Properties), and disable the warnings in Code Analysis, as shown in:

Click Apply and OK. Then, you will get a project that can be edited in eclipse.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.