Skip to content

Commit d0d84ae

Browse files
committed
Some fixes to build for android on windows
1 parent 4278770 commit d0d84ae

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

nimx/naketools.nim

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ let appName = "MyGame"
66
let bundleId = "com.mycompany.MyGame"
77
let javaPackageId = "com.mycompany.MyGame"
88

9-
let androidSdk = "~/Library/Android/sdk"
10-
let androidNdk = "~/Library/Android/sdk/ndk-bundle"
11-
let sdlRoot = "~/Projects/SDL"
9+
when defined(windows):
10+
let androidSdk = "D:\\Android\\android-sdk"
11+
let androidNdk = "D:\\Android\\android-ndk-r10e"
12+
let sdlRoot = "D:\\Android\\SDL2-2.0.3"
13+
14+
# This should point to the Nim include dir, where nimbase.h resides.
15+
# Needed for android only
16+
let nimIncludeDir = "C:\\Nim\\lib"
17+
else:
18+
let androidSdk = "~/Library/Android/sdk"
19+
let androidNdk = "~/Library/Android/sdk/ndk-bundle"
20+
let sdlRoot = "~/Projects/SDL"
1221

13-
# This should point to the Nim include dir, where nimbase.h resides.
14-
# Needed for android only
15-
let nimIncludeDir = "~/Projects/nim/lib"
22+
# This should point to the Nim include dir, where nimbase.h resides.
23+
# Needed for android only
24+
let nimIncludeDir = "~/Projects/nim/lib"
1625

1726
let macOSSDKVersion = "10.11"
1827
let macOSMinVersion = "10.6"
@@ -70,6 +79,7 @@ proc trySymLink(src, dest: string) =
7079
try:
7180
createSymlink(expandTilde(src), dest)
7281
except:
82+
echo "ERROR: Could not create symlink from ", src, " to ", dest
7383
discard
7484

7585
proc runAppInSimulator() =
@@ -114,8 +124,12 @@ proc makeAndroidBuildDir(): string =
114124
let buildDir = "android"/javaPackageId
115125
if not dirExists buildDir:
116126
copyDir "android/template", buildDir
117-
trySymLink(sdlRoot/"src", buildDir/"jni/SDL/src")
118-
trySymLink(sdlRoot/"include", buildDir/"jni/SDL/include")
127+
when defined(windows):
128+
copyDir sdlRoot/"src", buildDir/"jni"/"SDL"/"src"
129+
copyDir sdlRoot/"include", buildDir/"jni"/"SDL"/"include"
130+
else:
131+
trySymLink(sdlRoot/"src", buildDir/"jni"/"SDL"/"src")
132+
trySymLink(sdlRoot/"include", buildDir/"jni"/"SDL"/"include")
119133

120134
let mainActivityPath = javaPackageId.replace(".", "/")
121135
createDir(buildDir/"src"/mainActivityPath)
@@ -196,12 +210,12 @@ task "droid", "Build for android and install on the connected device":
196210
runNim "--compileOnly", "--cpu:arm", "--os:linux", "-d:android", "-d:SDL_Static", "--nimcache:" & droidSrcDir
197211

198212
# Copy resources. TODO: This is a quick mock of how it should work.
199-
direShell "mkdir", "-p", buildDir / "assets"
200-
direShell "cp", "-vR", "res/*", buildDir / "assets"
213+
createDir buildDir / "assets"
214+
try: copyDir "res", buildDir / "assets" except: discard
201215

202216
cd buildDir
203217
putEnv "NIM_INCLUDE_DIR", expandTilde(nimIncludeDir)
204-
direShell androidSdk/"tools/android", "update", "project", "-p", ".", "-t", "android-22"
218+
direShell androidSdk/"tools/android", "update", "project", "-p", ".", "-t", "android-22" # try with android-16
205219
direShell androidNdk/"ndk-build"
206220
#putEnv "ANDROID_SERIAL", "12345" # Target specific device
207221
direShell "ant", "debug", "install"
@@ -213,5 +227,6 @@ task "js", "Create Javascript version.":
213227
let settings = newSettings(staticDir = getCurrentDir())
214228
routes:
215229
get "/": redirect "main.html"
216-
openDefaultBrowser "http://localhost:5000"
230+
when not defined(windows):
231+
openDefaultBrowser "http://localhost:5000"
217232
runForever()

0 commit comments

Comments
 (0)