查詢專案的遊戲引擎版本

文章撰寫日期︰2014/12/30 11:30

一、問題

試圖編譯外來遊戲時,
因為不知道cocos2dx的遊戲引擎版本,
因此
$./build_native.sh
無法通過。

二、解決辦法

在開啟一個全新cocos2dx專案時,
其實會將cocos2dx引擎需要被編譯的相關程式整個原封不動的複製到新專案中。
因此在cocos2d.cpp檔裡會記錄著該專案的遊戲版本。

路徑如下︰
YourGameProject/libs/cocos2dx/cocos2d.cpp

打開來後,
就會看到cocos2dx所使用的引擎版本號了。


修復 cocos2dx v2.x 版 OpenSSL 過期的錯誤

文章撰寫日期︰2014/12/29 18:50
文章修改日期︰2014/12/30 10:20
文章修改次數︰1

一、問題

今天收到Google寄來的一封信,
跟我說我目前用的Cocos2d-x的OpenSSL協議版號過舊,
APK即將被強迫下架,
需要我盡快更新並重新上架。

內容如下︰
Your app is running an outdated version of OpenSSL, which has multiple security vulnerabilities. You should update OpenSSL as soon as possible.

The vulnerabilities were addressed in OpenSSL versions beginning with 1.0.1h, 1.0.0m, and 0.9.8za. To confirm your OpenSSL version, you can do a grep via ("$ unzip -p YourApp.apk | strings | grep "OpenSSL""). For more information about the vulnerability, please consult http://www.openssl.org/news/secadv_20140605.txt.

To confirm that you’ve upgraded correctly, upload the updated version to the Developer Console and check and after five hours.

This is the second warning we’ve sent you. Please note, while it's unclear whether these specific issues affect your application, applications with vulnerabilities that expose users to risk of compromise may be considered “dangerous products” and subject to removal from Google Play.

二、解決辦法

查了一下原來使cocos2dx引擎內建的OpenSSL版號使用過舊。

而前一陣子Google已經發表新聞稿(15年OpenSSL漏洞影響Android版Chrome,Google發布緊急更新),
因此也開始在抓OpenSSL過舊的APK。

請下載Cocos2dX v.2.x版更新檔並覆蓋取代底下的資料夾位置
/cocos2d-x/cocos2dx/platform/third_party/android/prebuilt/libcurl/libs

armeabi/libcurl.a覆蓋原來的armeabi/libcurl.a
armeabi-v7a/libcurl.a覆蓋原來的armeabi-v7a/libcurl.a
x86/libcurl.a覆蓋原來的x86/libcurl.a

如果下載連結失效,亦可至Github下載。

倘若用的是Cocos2dX v3.x版,請至此下載

更新完後,記得刪掉整個編譯出來的Android遊戲專案資料夾so檔,路徑如下
您的Android遊戲專案/proj.android/obj/local

並 $./build_native.sh 重新編譯您的遊戲專案即可修復問題。

三、其它

如果要知道現在apk使用OpenSSL的版號,
推薦一隻App︰Heartbleed Scanner

參考來源

1. cocos2dx官方論壇

將.so檔上傳至svn做版本控制

文章撰寫日期︰2014/09/16 17:40

SVN預設不會將.so等檔案上傳至SVN server,
因此在cocos2d-x裡使用build_native.sh檔編岀來的.so(C++靜態函式庫)不會被主動上傳至SVN Server。

如果需要上傳備份此檔案,
需下指令
$ svn add --no-ignore 欲添加至svn的檔案名稱

LOCAL_SRC_FILES points to a missing file

文章撰寫日期︰2014/09/15 16:11
cocos2d-x使用版本︰2.1.1-beta3

一、問題

今天在編譯cocos2dx時,
遇到

LOCAL_SRC_FILES points to a missing file 

cocos2dx/platform/third_party/android/prebuilt/libjpeg/libs/armeabi/libjpeg.a exists  or that its path is correct

的問題。



二、解決辦法


現在(2014/09/15,目前最新是cocos2dx3.2版)在Github上的cocos2dx,
在checkout到舊版(2.1.1-beta3)時,
cocos2dx/platform/third_party/android/prebuilt目錄底下的檔案已不齊全
這造成Android專案在build_native.sh時,
因為遺失相關檔案造成無法成功編譯遊戲成為.so檔。

這裡提供的檔案解壓縮覆蓋掉libcurl、libjpeg、libpng、libtiff四個檔即可解決問題。

build_native.sh 無法執行

文章撰寫日期︰2014/09/12 17:06

一、問題

今天在編譯(build_native.sh)國外的cocos2dx源碼時,
遇到程式報錯,格式在token{usage(){附近有誤。

/Users/lp43/cocos2d-x/Vitalify_Games/android/WareWolf_android_Source/proj.android/build_native.sh:
line 3: : command not found

/Users/lp43/cocos2d-x/Vitalify_Games/android/WareWolf_android_Source/proj.android/build_native.sh: line 5: : command not found

/Users/lp43/cocos2d-x/Vitalify_Games/android/WareWolf_android_Source/proj.android/build_native.sh: line 7: : command not found

/Users/lp43/cocos2d-x/Vitalify_Games/android/WareWolf_android_Source/proj.android/build_native.sh: line 8: syntax error near unexpected token `{ ' 

/Users/lp43/cocos2d-x/Vitalify_Games/android/WareWolf_android_Source/proj.android/build_native.sh: line 8: `usage(){ '

二、解決辦法

這是因為國外公司的cocos2dx用的是windows在開發,
而我用的是mac,
雖然build_native.sh檔看似沒問題,
但其實文字的encode已經大亂,
所以需要對build_native.sh檔下指令重新編碼,
$ dos2unix build_native.sh build_native.sh

即可解決這個bug。

而如果要查看原來檔案encode的樣子,
可以下指令
$ cat -v build_native.sh

查看。
你會看到很多不該存在的亂碼格式。

Cannot find module with tag 'Box2D' in import path

文章撰寫日期︰2014/08/23 21:29
cocos2d-x使用版本︰2.0.4

一、問題

今天在重build cocos2d-x專案時,
遇到以下問題

Android NDK: /Users/lp43/cocos2d-x/cocos2d-x2.0.4/external/Box2D/Android.mk: Cannot find module with tag 'Box2D' in import path

Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?

二、解決辦法

cocos2dx在使用ndk編譯時,
會去讀Android.mk腳本。

因為腳本裡宣告了該專案會使用者Box2D重力引擎模組
$(call import-module,Box2D)

因此在NDK make時,
程式去找cocos2dx根目錄底下的Box2D資料夾,
試圖將該目錄編譯成靜態C函式庫,
但因為在cocos2dx 2.0.4 Box2D的預設路徑並不在cocos2dx目錄底下,
而是在cocos2dx/external/Box2D
因此要將import-module更改如下

$(call import-module,external/Box2D)

這樣子ndk就找的到Box2D資源並可順利編譯。

使用ccb綁定JS執行遇到Assertion failed: CCNodeLoaderLibrary.cpp, line 67.

文章撰寫日期︰2014/01/25 19:22
cocos2d-x使用版本︰2.2.2
文章來源︰小鰻的cocos2d-x學習筆記

一、問題

使用ccb綁定JS執行遇到
Assertion failed: (ccNodeLoadersIterator != this->mCCNodeLoaders.end()), function getCCNodeLoader, file /Users/lp43/cocos2d-x/cocos2d-x2.2.2/extensions/CCBReader/CCNodeLoaderLibrary.cpp, line 67.


二、解決辦法

這是因為有時候cocosbuilder有個bug,會預設是要和c++綁定,因此js class找不到。
需將[Document]-->[Javascript Controlled]勾選起來。

CocosBuilder for Cocos2d-html5 v.2.2.2

文章撰寫日期︰2014/01/20 17:44
cocos2d-x使用版本︰2.2.2
文章來源︰小鰻的cocos2d-x學習筆記

今天在使用cocos2d-html5時,
發現boot-html5.js檔裡預設讀取jsloader.js的存放路徑改變了
因此我重做了CocosBuilder。
I discovered the jsloarder.js path has been changed on cocos2d-html5 2.2.2,
so I modified boot-html5.js template in Cocosbuilder project.
cocos2d/platform/jsloader.js --> cocos2d/jsloader.js


提供下載點如果你需要的話
Download cocosBuilder that I modified file if you need.

甚至你也可以自行修改boot-html5.js的template輸岀檔,
請參考這篇
Moreover you can modified boot-html5.js template by yourself,
please refer to this document.

[cocos2d-x JSB]Communicate with Cpp and Javascript easily - EasyJSB

Wrote date︰2014/01/16 10:40
cocos2d-x used version︰2.2.2
Data from︰小鰻的cocos2d-x學習筆記

如果您是中文用戶,請切換至此篇文章。

1. Before

Writing cross-platform project by Javascript usually need take a lot of time to communicate with Cpp and native(iosAndroid). The developer have to learn how to use parameter or method within SpiderMonkey by JSB-binding to approach this task.

It is painful the developer have to learn SpiderMonkey(ps.1) and is time-consuming. So EasyJSB  born!

EasyJSB is based on EasyNDK, you need to understand how to use EasyNDK as possible.






[ps.1]
SpiderMonkey is Mozilla's Javascript engine written in C/C++. It is used in various Mozilla products, including Firefox. For the target of building one game to cross-platform, cocos2d-x team binding C++ to javascript to let Javascript developers can use Cocos2d-x easily.

2. Start

Step1 Download EasyJSB from Github

Go to Github and download EasyJSB library or go to the path cocos2dx\projects and input command under terminal as below:
$git clone https://github.com/lp43/EasyJSB.git

Open EasyJSB Project in Xcode

Take about ten minutes,
the project download done.
You can open Xcode project under proj.ios folder directly.

Open EasyJSB Project in Eclipse


When you imported the project,
you will see EasyJsbSample in your eclipse workspace.
Remove all files under obj folder and rebuild project,
you will see how EasyJSB work on Android。

[cocos2d-x JSB篇]輕易從Javascript跟cpp與Native溝通的工具︰「EasyJSB」

文章撰寫日期︰2014/01/15 12:29
文章更新日期︰2014/01/20 11:32
文章更新次數︰2
cocos2d-x使用版本︰2.2.2
文章來源︰小鰻的cocos2d-x學習筆記

If you famillar with english, please turn to this essay.

一、前言

圖片說明了在cocos2d-JSB的開發環境中,
EasyNDK及EasyJSB各自的定位與角色。


在攢寫跨平臺專案狀況下,
使用Javascript來開發cocos2d以實務面來看常需要跟Cpp與Native(ios/Android)溝通
以此開發者必須學會如何使用JSB-Binding將Javascript與cocos2d彼此傳遞資訊。

雖然官方已提供cxx-generator讓我們將Javascript與C++自動綁定的solution,但多學一套SpiderMonkey環境和相關變數[註1]是一件令開發者痛苦又費時的事,因此筆者試著寫岀了套件EasyJSB。

該套件架構在EasyNDK底下,
因此使用EasyJSB的同時,
也需要同時候用EasyNDK套件。






[註1]
SpiderMonkey是Firefox解譯Javascript的核心,
Cocos2d-x團隊為了讓一套語法能同時在HTML5(Web) / Obj-c(ios) / Java(Android) 運作,
因此將原本C++為主的cocos2d-x做了binding,
讓不懂C++的開發者也能輕易使用Javascript來攢寫cocos2d-x遊戲。

二、文章開始

第1步 至Github下載EasyJSB

先到Github下載EasyJSB套件或至cocos2dx\projects目錄底下,
打上指令
$git clone https://github.com/lp43/EasyJSB.git

在Xcode中開啟EasyJSB專案

約過10分鐘後專案下載完成,
即可直接至底下proj.ios目錄開啟Xcode專案。

在Eclipse中開啟EasyJSB專案

 

匯入後,
就會在Ecipse裡看到EasyJSB專案了。
將obj資料夾底下全部檔案刪除並重新編譯cocos2d-x。
完成後即可執行專案。

[Xcode篇]編譯ios-jsb-project時遇到'generated/jsb_cocos2dx_auto.hpp' file not found

文章撰寫日期︰2014/01/11 17:34
cocos2d-x使用版本︰2.2.2

一、問題

今天在下載並將cocos2d-x版本切換至2.2.2時,
使用create_project的方式創建一個新的Javascript專案並編譯執行時,
遇到
AppDelegate.cpp:6:10: 'generated/jsb_cocos2dx_auto.hpp' file not found
的問題。

二、解決辦法

去到官方的cocos2d-x Github網站查到jsb_cocos2dx_auto.hpp這個檔是次模組資源下的檔案。
因此要使用terminal終端機工具到cocos2d-x下載目錄底下打上指令︰
$git submodule update --init --recursive

將次模組檔下載下來,
才能解決無法編譯執行的問題。
將次模組下載下來後,project就能正常執行了。

[Xcode篇]Apple Mach-O Linker Error cocos2dx

文章撰寫日期︰2014/01/11 16:11
cocos2d-x使用版本︰2.1.4
Xcode使用版本︰5.0.2
文章來源︰wk3368的專檔

一、問題

今天在創建一個新的Javascript-cocos2dx專案並且在ios實機執行時,
遇到了一個從未見過的錯誤︰
Apple Mach-O Linker Error cocos2dx

二、解決辦法

Google了一下,
發現事情嚴重了
照著stack overflow的辦法,
怎樣都解決不了。

後來在wk3368的專檔這位朋友的博客中看到他也有此經驗︰

xcode升级到5.0.2之后,cocos2d-x-2.2下的所有工程,不管是旧的,还是新建的,第一次用xcode打开xxx.xcodeproj之后,
1.要project->clean先!
否则会出现“.../cocos2d-x-2.2/cocos2dx/platform/third_party/ios/curl /curlrules.h:143:6: '__curl_rule_01__' declared as an array with a negative size”和“Icon-72.png copy error”的错误提示。

2.xcode会出现如图提示,大概意思就是要修改cocos2dx的Architecture,此时必须点Cancel,不能点Perform Changes
否则之后编译会出现100多个“Apple Mach-O Linker Error”的错误。
然后google查都是要去修改armv7s什么的,都是误导。解决不了问题!
更要命的是,这个cocos2dx的target是被其他projects下的项目和samples下的例子共同引用的,结果就是所有工程都会同样报错!

所以一开始这个弹窗,就不要点"Perform Changes"!

我無言了...
現在重新下載cocos2d-x包中...

[cocos2dx-IOS篇]在Xcode中,替Cocos2D-X專案添加Admob廣告

文章撰寫日期︰2014/01/04 12:36
cocos2d-x使用版本︰2.1.4

一、前言

廣告是app開發商的獲利方式之一,
Google的Admob更是眾多開發者的選擇。
因此學會如何串接Admob也變得非常重要。

二、文章開始

第1步 下載ios-Admob套件

先到Google Admob網站下載Admob


第2步 添加Admob Library檔至遊戲專案

我們將下載後的檔案解壓縮,
放在常收納套件的收藏資料夾底下。
(我放在ios/third-party/目錄底下)
解壓縮下載完後的Admob套件
在Xcode的遊戲專案,
按右鍵,選擇Add Files to "您的專案"。
選擇Admob套件剛才存放的地方
新增後,在專案資料夾就看到Admob的套件檔添加進來了。

第3步 添加Admob需要用到的Framework

依照Admob官方的說明,
在使用Admob我們需要下列這些Framework
  • AdSupport
  • AudioToolbox
  • AVFoundation
  • CoreGraphics
  • MessageUI
  • StoreKit
  • SystemConfiguration
添加Framework的方式

第4步 設定-ObjC屬性

  1. In Xcode's project navigator, press the blue top-level project icon.
  2. Click on your target, then the Build Settings tab.
  3. Under Other Linker Flags, add -ObjC to both Debug and Release.

第5步 添加Admob code到程式裡

如果你接下來想照著官方教學繼續這麼做,
我會建議不要。

為什麼?
如果你剛才一直照著我說的,
跟著官方step by step加入Admob,
那麼你現在可以試看看按Run來啟動專案。

第6步 error解除

啟動後,
Shit!無法執行!
 
你會發現編譯器告訴你︰
Admob裡有一個叫GoogleAnalytics的東西,
main.m檔要求compiler在編譯這份文件時,
這個m檔需要使用ios的ARC機制!

我的經驗是不要干脆不要使用GoogleAnalytics,
因為我花了一天還是處理不完,
沒完沒了。
所以就把它刪掉了。
再次執行,
仍然無法編譯成功。
這次的錯誤是找不到Library。

第7步 重設並整理Library路徑

Target選擇我們的專案,
選擇[Build Settings] 找到Search Paths後,
在Debug列表點擊2下。
發現原本的路徑全跑掉了,
只好重設。
因為我是用Javasript來寫cocos2d-x,
因此上面的library看的到有使用spidermonkeyscripting/javascript/spidermonkey-ios/lib\。 將上面3個路徑改到實体路徑
\"$(SRCROOT)/../../../scripting/javascript/spidermonkey-ios/lib\"
變成
/Users/lp43/cocos2d-x/cocos2d-x2.1.4/scripting/javascript/spidermonkey-ios/lib
依此類推。

然後,
因為剛才我們已經將Google Analytics(Google追蹤)套件拿掉了,
因此上面紅框的部份都可以刪掉。

第8步 確認專案已修復並可執行

這時候再重新run一次專案,
發現專案又復活了,可以正常執行。

第9步 添加Admob code

現在可以回到官方的admob教學流程了,
在RootViewController.h添加code如下
#import 

#import "GADBannerViewDelegate.h"//加入這行
@class GADBannerView;//加入這行
@class GADRequest;//加入這行

@interface RootViewController : UIViewController//加入這個Delegate
- (void) SampleSelector:(NSObject *)prms;

@property(nonatomic, strong) GADBannerView *adBanner;//加入這行
- (GADRequest *)request;//加入這行
@end

然後, 在RootViewController.mm加入
#import "RootViewController.h"
#include "IOSNDKHelper.h"

#import "GADBannerView.h"//加入這行
#import "GADRequest.h"//加入這行

@implementation RootViewController

// Override to allow orientations other than the default portrait orientation.
// This method is deprecated on ios6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return UIInterfaceOrientationIsLandscape( interfaceOrientation );
}

// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
- (NSUInteger) supportedInterfaceOrientations{
#ifdef __IPHONE_6_0
    return UIInterfaceOrientationMaskAllButUpsideDown;
#endif
}

- (BOOL) shouldAutorotate {
    return YES;
}

//fix not hide status on ios7
- (BOOL)prefersStatusBarHidden
{
    return YES;
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        
        // 告訴NDKHelper說 RootViewController會回應來自C++的message
        [IOSNDKHelper SetNDKReciever:self];
        
    }
    return self;
}
- (void) SampleSelector:(NSObject *)prms
{
    NSLog(@"Objective-C端的SampleSelector被呼叫了");
    //加入底下
    // Initialize the banner at the bottom of the screen.
    self.adBanner = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
    // Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID before compiling.
    self.adBanner.adUnitID = @"填上你的admob_id";
    self.adBanner.delegate = self;
    self.adBanner.rootViewController = self;
    [self.view addSubview:self.adBanner];
    [self.adBanner loadRequest:[self request]];
}
//加入底下函式
- (GADRequest *)request {
    GADRequest *request = [GADRequest request];
    
    // Make the request for a test ad. Put in an identifier for the simulator as well as any devices
    // you want to receive test ads.
    request.testDevices = @[
                            // TODO: Add your device/simulator test identifiers here. Your device identifier is printed to
                            // the console when the app is launched.
                            GAD_SIMULATOR_ID,
                            @"如果你要在實機上測試admob,從console裡會有一串實機的編碼,填進這裡"
                            ];
    return request;
}
@end

完成了!

重新執行專案,
會發現Admob完美的岀現在我們cocos2dx的專案上。

三、結論

由於Admob套件裡的Google Analytics使用了ARC機制,
而cocos2d-x專案預設是沒有ARC的,
為了避免ARC與您的專案間改寫與設定上的麻煩,
我直接將Google Analytics套件從Admob中拆掉。

上面的教學我個人覺得已經是最快實作Admob的途徑,
也將整個步驟鉅細靡疑的交待岀來。
希望在看這篇文章的您從中受益,
縮短冤枉的時間。

謝謝您的閱讀。