So I spent last week and this weekend writing my game in Win32, and then I am ready to test it on Android and guess what… I run the create-android-project.bat and I used the same name for my folder, now Guess what happened? I erased my project, Now I get a Hello World example wend I build… So i guess that script erases all files in the folder, right?
Fortunately I am using GIT, but so I don’t screw this up again, how do I create a project that can run both Win32 and Android? I want to use the same code source and same folder, and simply Build the game using Visual Studio for fast compilation and and Compile using Eclipse for Android. How do I do this? Because now wend I try to load my old solution in Visual Studio there is no vcxproj file.
…cocos2d-1.0.1-x-0.9.2\MarsVillans\MarsVillans.win32.vcxproj" could not be found.
Is there a simple way to create this kind of project, where I simply have 3 folders for each platform? Thanks!
Oh, so sorry about that. I create issue #910 to improve this script.
You can refer this blog to create hybird project http://gameit.ro/2011/08/creating-an-iphone-and-android-cocos2d-x-hybrid-project/, but win32 solution is not involved.
Visual Studio Wizard restrict the folder relationship between .sln, .vcproj and source files, we cannot create a folder structure from wizard and get the result like HelloWorld, whose vcproj is in a subfolder.
My solution is:
Before run ‘create~~project.bat’, rename your project folder ’MarsVillans’ to ’MarsVillans1’, then run ’create~~project.bat’, after that copy ‘MarsVillans/android’ or ‘MarsVillans/bada’ to ‘MarsVillans1’, delete MarsVillans folder, rename MarsVillans1 to MarsVillans at the end.
I know this is a ugly solution. But for now, this is the simplest way I found. Maybe there is another better way?
Thanks for the tip James. If that works then it should be very simple to make a script that automates the copy paste procedures. Ill try to come up with something that makes multiple platform management easy. If it works ill post it. I was under the impression that it was just a couple of commands and my win32 project would be made into an Android project or iPhone project. Ill have to explore this a bit more. I tried to put my old code in my android folder and errors everywhere related to JNI. So ill have to check that out again.
Created my Win32 “winand” Project using the Wizard on Visual Studio 2010. Sound and Box2D (default settings).
Changed one string “Hello World” to “Hello World WinANDROID” and size to 32.
Build my Win32 project
Test by Run project. Works perfect.
Android Project
Rename Win32 Folder to “winand_TEMP”
Use script: create-android-project.bat to create a folder with the previous name
package name: org.cocos2d.winand
project name: winand
copy android folder into winand_TEMP
remove winand
rename winand_TEMP to winand
open Cygwin batch shell and navigate to …/winand/android folder
build project using ./build_native.sh
ERRORS:
Compile thumb : stlport_static <= c_locale.c
Compile thumb : stlport_static <= cxa.c
StaticLibrary : libstdc++.a
make: Circular /cygdrive/c/Users/dan/Downloads/cocos2d-1.0.1-x-0.9.2/cocos2d-1.0
.1-x-0.9.2/winand/android/obj/local/armeabi/libstlport_static.a <- /cygdrive/c/U
sers/dan/Downloads/cocos2d-1.0.1-x-0.9.2/cocos2d-1.0.1-x-0.9.2/winand/android/ob
j/local/armeabi/libstlport_static.a dependency dropped.
StaticLibrary : libstlport_static.a
SharedLibrary : libcocos2d.so
Install : libcocos2d.so => libs/armeabi/libcocos2d.so
Compile++ thumb : cocosdenshion <= SimpleAudioEngine.cpp
Compile++ thumb : cocosdenshion <= SimpleAudioEngineJni.cpp
SharedLibrary : libcocosdenshion.so
Install : libcocosdenshion.so => libs/armeabi/libcocosdenshion.so
Compile++ thumb : game <= main.cpp
Compile++ thumb : game <= AppDelegate.cpp
In file included from C:/Users/dan/Downloads/cocos2d-1.0.1-x-0.9.2/cocos2d-1.0.1
-x-0.9.2/winand/android/jni/helloworld/../../../Classes/AppDelegate.cpp:8:
C:/Users/dan/Downloads/cocos2d-1.0.1-x-0.9.2/cocos2d-1.0.1-x-0.9.2/winand/androi
d/jni/helloworld/../../../Classes/HelloWorldScene.h:6:25: error: Box2D/Box2D.h:
No such file or directory
make: *** [/cygdrive/c/Users/dan/Downloads/cocos2d-1.0.1-x-0.9.2/cocos2d-1.0.1-x
-0.9.2/winand/android/obj/local/armeabi/objs-debug/game/../../../Classes/AppDele
gate.o] Error 1
make: Leaving directory `/cygdrive/c/Users/dan/Downloads/cocos2d-1.0.1-x-0.9.2/c
ocos2d-1.0.1-x-0.9.2/winand/android'
It appears that Box2D can’t be found. OK looking at the error code it wants Box2D inside the …/winand/Classes. OK let’s do that!
8) Copy Box2D folder from root cocos2d-x into …/winand/Classes.
9) Start Eclipse, create New Android Project, create project from existing source, point it to …/winand/android and select the SDK API level.
10) Build the package
11) Connect USB Device.
12) Run as Android Application.
Application starts but there are some issues, the application runs upside down.
Made the mistake of updating my ndk, sdk and adt to R7, and R16 respectively it made everything break. tried cocos2d-x 0.10.0 no luck. That was insensate I finally had a working solution. Back to zero.
Edit: Fixed by passing android.mk and fixing LOCAL_CFLAGS := DUSE_FILE32APIDGL_GLEXT_PROTOTYPES=1
It seems that you have modified the codes generated by create-android-project.bat.
Because the label content is “Hello World xxx”.
Could you please not modify the codes, run and see the result?