Skip to content

Commit

Permalink
Simplified Android prebuild no longer requires cygwin.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nat Weiss committed Jan 27, 2016
1 parent e4829e0 commit 1637898
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 1,416 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ libexepath.txt
msbuildpath.txt
vctargetspath.txt
RapidGame.xcodeproj
/current

10 changes: 8 additions & 2 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
Version 0.9.14 - January 12, 2015
Version 1.0.0 - January 26, 2016

Linux support.
Can specify cocos2d-x source folder.
Simplified Android prebuild so it doesn't require cygwin on Windows.

Version 0.9.14 - January 12, 2016

Fixed prebuild on Windows.
Started automatic detection of whether to prebuild Javascript bindings by checking cocos/base/ccConfig.h.

Version 0.9.13 - January 10, 2015
Version 0.9.13 - January 10, 2016

Updated to cocos2d-x 3.9.

Expand Down
29 changes: 10 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,21 @@ Windows: [Visual Studio](https://www.visualstudio.com/en-us/products/free-develo

Linux: run `cocos2d-x/build/install-deps-linux.sh` and that [Git](http://git-scm.com/downloads) and [Node.js](https://nodejs.org/en/download/) are installed.

Android (any platform): please read the [Android README](http://htmlpreview.github.io/?https://github.com/NatWeiss/RapidGame/blob/master/templates/cocos2dx/TwoScene/Projects/android/README.html) or [watch the video](https://www.youtube.com/watch?v=5PWEtjvhX1k) to find out what you will need for Android development.
Android (any platform): you'll need to install the Android [SDK](http://developer.android.com/sdk/installing/) and [NDK](http://developer.android.com/tools/sdk/ndk/), then run the SDK Manager and install the latest *Tools*, *Platform Tools* and *Build-tools*. Finally, make sure that the environment variable `NDK_ROOT` is the path to the NDK.


Windows Notes
-------------

1. **The `rapidgame create` or `rapidgame prebuild` command must be run as administrator.** This allows symlinks to be properly created.
2. If you have freshly installed Visual Studio, then you will need to run it once in order for it to download the necessary build tools.
3. To prebuild Android libraries, please set the `NDK_ROOT` environment variable. You can do this permanently for all command prompt sessions by going: Computer > Properties > Advanced System Settings > Environment System Variables. Confirm this with `echo %PATH%` or just try to run `ndk-build` from any directory.


Updates
-------

* Coming soon: Linux support. Also can specify cocos2d-x source folder.
* Jan 27, 2016: Linux support. Can specify cocos2d-x source folder. Simplified Android prebuild so it doesn't require cygwin on Windows.
* Jan 10, 2016: Updated to cocos2d-x 3.9.
* Aug 17, 2015: Fixes for Visual Studio 2015.
* Aug 11, 2015: On Windows, the path to MSBuild.exe, Lib.exe and VCTargetsPath can be set manually in case they cannot be automatically located.
Expand All @@ -138,23 +146,6 @@ Updates
* Aug 14, 2014: Prebuilder updated for cocos2d-js 3.0 rc2 / cocos2d-x 3.2.


Windows Notes
-------------

1. **The `rapidgame create` or `rapidgame prebuild` command must be run as administrator.** This allows symlinks to be properly created.
2. If you have freshly installed Visual Studio, then you will need to run it once in order for it to download the necessary build tools.
3. To compile the Android libraries successfully, `rapidgame prebuild` must be run via [Cygwin](https://www.cygwin.com). Read about all the specific requirements in the [Android README](http://htmlpreview.github.io/?https://github.com/NatWeiss/RapidGame/blob/master/templates/cocos2dx/TwoScene/Projects/android/README.html), or [watch the video](https://www.youtube.com/watch?v=5PWEtjvhX1k) instead.
4. Windows cannot build the cocos2d-x libraries or cocos2d-js bindings for iOS and Mac. If you want to use RapidGame to develop for these platforms, you must use a Mac.

Thanks to [Samuel Ørsnæs](https://github.com/samoersnaes) for originally getting the Android build working in Windows.


Android Notes
-------------

A detailed guide has been written specifically for how to build Android projects using RapidGame. You can read it [here](http://htmlpreview.github.io/?https://github.com/NatWeiss/RapidGame/blob/master/templates/cocos2dx/TwoScene/Projects/android/README.html), or alternatively find it in your cocos2d-x/js project as `[APPNAME]/Projects/android/README.html`.


Eliminate Grunt Work
--------------------

Expand Down
146 changes: 70 additions & 76 deletions rapidgame.js
Original file line number Diff line number Diff line change
Expand Up @@ -1080,16 +1080,11 @@ var linkWin = function(config, callback) {
// prebuild android
//
var prebuildAndroid = function(platform, config, arch, callback) {
var i, j, src, dest, command, args = [], func, funcArg,
var i, j, src, dest, command, args = [], func, funcArg, ndkToolchainVersion = "",
configs = (config ? [config] : (cmd.minimal ? ["Debug"] : ["Debug", "Release"])),
archs = (cmd.minimal ? ["armeabi"] : ["armeabi", "armeabi-v7a", "x86"]);
archs = (cmd.minimal ? ["armeabi"] : ["armeabi", "armeabi-v7a", "x86"]),
toolchains = ["4.9", "4.8", "4.7"];

// Windows requires TERM environment variable (means running from cygwin)
if (process.platform === "win32" && !("TERM" in process.env)) {
logBuild("Can only build Android on Windows using a cygwin terminal", true);
callback();
return;
}
// All platforms require NDK_ROOT environment variable.
if (!("NDK_ROOT" in process.env)) {
logBuild("Can only build Android with a proper SDK and NDK installation.", true);
Expand All @@ -1098,6 +1093,20 @@ var prebuildAndroid = function(platform, config, arch, callback) {
callback();
return;
}

// Determine which toolchain to use.
for (i = 0; i < toolchains.length; i += 1) {
if (dirExists(path.join(process.env["NDK_ROOT"], "toolchains", "arm-linux-androideabi-" + toolchains[i]))) {
ndkToolchainVersion = toolchains[i];
break;
}
}
if (ndkToolchainVersion.length <= 0) {
logBuild("No suitable toolchain version found in: " + path.join(process.env["NDK_ROOT"], "toolchains"), true);
logBuild("Acceptable versions: " + toolchains.join(", "), true);
callback();
return;
}

// create builds array
builds = [];
Expand All @@ -1106,61 +1115,30 @@ var prebuildAndroid = function(platform, config, arch, callback) {
src = path.join(cmd.prefix, "src", "proj.android");
dest = path.join(cmd.src, "build", configs[i] + "-Android");

// Always copy latest jni and build.sh and makefile.
// Always copy latest Android build files.
logBuild("Copying " + src + " to " + dest, true);
wrench.mkdirSyncRecursive(dest);
copyGlobbed(src, dest, "build.sh");
copyGlobbed(src, dest, "makefile");
//copyGlobbed(src, dest, "build.sh");
//copyGlobbed(src, dest, "makefile");
copyGlobbed(path.join(src, "jni"), path.join(dest, "jni"), "*");

// Set func.
func = linkAndroid;
funcArg = configs[i];

if (process.platform === "win32") {
// win32 uses make
command = "make";
args = [];
if (cmd.minimal) {
args.push(cmd.nostrip ? ["minimal-nostrip"] : ["minimal"]);
} else {
args.push(cmd.nostrip ? ["nostrip"] : []);
}
if (!doJSB) {
args.push("nojs");
}
for (j = 0; j < archs.length; j += 1) {
// Run the ndk-build.
command = path.join(process.env["NDK_ROOT"], "ndk-build" + (process.platform === "win32" ? ".cmd" : ""));
args = [
"-C", dest,
"NDK_TOOLCHAIN_VERSION=" + ndkToolchainVersion,
"NDK_MODULE_PATH=" + cmd.src,
"APP_PLATFORM=" + "android-18",
"APP_ABI=" + archs[j],
"CONFIG=" + configs[i],
"DO_JS=" + (doJSB ? "1" : "0")
];
funcArg = configs[i] + "-" + archs[j];
builds.push([configs[i], command, dest, args, func, funcArg]);

//if (cmd.minimal) {
// if (cmd.nostrip) {
// builds.push([command, "non-stripped minimal (Debug armeabi)"]);
// } else {
// builds.push(["minimal (Debug armeabi)"]);
// }
//} else {
// if (cmd.nostrip) {
// builds.push(["non-stripped libraries for all platforms"]);
// } else {
// builds.push(["libraries for all platforms"]);
// }
//}
} else {
for (j = 0; j < archs.length; j += 1) {
// Mac and Linux use build.sh
command = path.join(dest, "build.sh");
args = [
archs[j],
configs[i]
];
if (cmd.nostrip) {
args.push("nostrip");
}
if (!doJSB) {
args.push("nojs");
}

builds.push([configs[i], command, dest, args, func, funcArg]);
}
}
}
nextBuild("Android", callback);
Expand All @@ -1169,16 +1147,48 @@ var prebuildAndroid = function(platform, config, arch, callback) {
//
// link android
//
var linkAndroid = function(config, callback) {
var dest;
var linkAndroid = function(configArch, callback) {
var a, src, dest, config = "", arch = "";

// Copy these prebuilt files.
a = configArch.split("-");
if (a.length >= 2) {
config = a[0];
arch = a[1];

src = path.join(cmd.src, "build", config + "-Android", "obj", "local", arch);
dest = path.join(cmd.dest, "cocos2d", "x", "lib", config + "-Android", arch);

logBuild("Copying Android libraries from " + src + " to " + dest, true);
copyGlobbed(src, dest, "*.a");
} else {
logBuild("Failed to link Android because couldn't get config and arch from: " + configArch, true);
}

// Copy other prebuilt libs.
dest = path.join(cmd.dest, "cocos2d", "x", "lib", "Debug-Android");
copyGlobbed(cmd.src, dest, "*.a", "android", 1);

copyGlobbed(path.join(cmd.src, "external"), dest, "*.a", "android", 1);
dest = path.join(cmd.dest, "cocos2d", "x", "lib", "Release-Android");
copyGlobbed(cmd.src, dest, "*.a", "android", 1);
copyGlobbed(path.join(cmd.src, "external"), dest, "*.a", "android", 1);

callback();

// build.sh used to combine all the .a files into one libcocos2dx-prebuilt.a like this:
/*
ar=$(ndk-which ar)
strip=$(ndk-which strip)
lib="libcocos2dx-prebuilt.a"
rm -f ${dest}/${lib}
for dir in audioengine_static cocos2dx_internal_static cocos_extension_static cocos_ui_static cocostudio_static spine_static \
box2d_static cocos2dxandroid_static cocos_flatbuffers_static cocosbuilder_static bullet_static cocos3d_static \
cocos_network_static cocosdenshion_static recast_static
do
${ar} rs ${dest}/${lib} $(find ${src}/${dir} -name *.o)
if [ "$3" != "nostrip" ]; then
${strip} -x ${dest}/${lib}
fi
done
*/
};

//
Expand Down Expand Up @@ -1745,22 +1755,6 @@ var isWriteableDir = function(dir) {
return false;
};

//
// a function to make paths cygwin-friendly
//
var cygwinDir = function(str) {
// cygwin needs c:\something => /cygdrive/c/something
if (process.platform === "win32" && ("TERM" in process.env)) {
str = str.replace(/\\/g, "/");
str = str.replace(/c:/i, "/cygdrive/c");
str = str.replace(/d:/i, "/cygdrive/d");
str = str.replace(/e:/i, "/cygdrive/e");
str = str.replace(/f:/i, "/cygdrive/f");
str = str.replace(/g:/i, "/cygdrive/g");
}
return str;
};

//
// reporting feature no longer used
//
Expand Down
Loading

0 comments on commit 1637898

Please sign in to comment.