Skip to content

Commit

Permalink
update android building
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethosa committed Dec 29, 2023
1 parent 430d3b7 commit b33a92b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
2 changes: 1 addition & 1 deletion happyx_native.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

description = "Macro-oriented web-framework compiles to native written with ♥"
author = "HapticX"
version = "0.3.0"
version = "0.3.1"
license = "MIT"
srcDir = "src"
installExt = @["nim", "gradle", "properties"]
Expand Down
73 changes: 36 additions & 37 deletions src/happyx_native/cli/build.nim
Original file line number Diff line number Diff line change
Expand Up @@ -99,38 +99,37 @@ proc buildCommandAux*(target: string = OS, release: bool = false, opt: string =
copyDir(getAndroidFolder(), getCurrentDir() / "android")
createDir("android" / "app" / "src" / "main" / "res" / "drawable")

# Setup app data
var img: string
withOpen(getCurrentDir() / cfg.appDirectory / "favicon.png", fmRead):
img = fileVar.readAll()
discard tryRemoveFile("android" / "app" / "src" / "main" / "res" / "drawable" / "ic_launcher.png")
withOpen("android" / "app" / "src" / "main" / "res" / "drawable" / "ic_launcher.png", fmWrite):
fileVar.write(img)

var buildGradle: string
withOpen("android" / "app" / "build.gradle", fmRead):
buildGradle = fileVar.readAll()
# Version name
buildGradle = buildGradle.replace("versionName \"1.0\"", fmt"""versionName "{cfg.version}" """)
# package
buildGradle = buildGradle.replace("com.hapticx.tmpl", cfg.androidPackage)
withOpen("android" / "app" / "build.gradle", fmWrite):
fileVar.write(buildGradle)

var strings = loadXml("android" / "app" / "src" / "main" / "res" / "values" / "strings.xml")
# Setup app data
var img: string
withOpen(getCurrentDir() / cfg.appDirectory / "favicon.png", fmRead):
img = fileVar.readAll()
discard tryRemoveFile("android" / "app" / "src" / "main" / "res" / "drawable" / "ic_launcher.png")
withOpen("android" / "app" / "src" / "main" / "res" / "drawable" / "ic_launcher.png", fmWrite):
fileVar.write(img)
var buildGradle: string
withOpen("android" / "app" / "build.gradle", fmRead):
buildGradle = fileVar.readAll()
# Version name
buildGradle = buildGradle.replace("versionName \"1.0\"", fmt"""versionName "{cfg.version}" """)
# package
buildGradle = buildGradle.replace("com.hapticx.tmpl", cfg.androidPackage)
withOpen("android" / "app" / "build.gradle", fmWrite):
fileVar.write(buildGradle)
var strings = loadXml("android" / "app" / "src" / "main" / "res" / "values" / "strings.xml")

for str in strings.mitems:
if str.attr("name") == "app_name":
str[0].text = cfg.name
withOpen("android" / "app" / "src" / "main" / "res" / "values" / "strings.xml", fmWrite):
fileVar.write($strings)
# Java files
var
mainActivity: string
native: string
settingsGradle: string
for str in strings.mitems:
if str.attr("name") == "app_name":
str[0].text = cfg.name
withOpen("android" / "app" / "src" / "main" / "res" / "values" / "strings.xml", fmWrite):
fileVar.write($strings)

if ("android" / "app" / "src" / "main" / "java" / "com" / "hapticx" / "tmpl").dirExists():
# Java files
var
mainActivity: string
native: string
settingsGradle: string
withOpen("android" / "app" / "src" / "main" / "java" / "com" / "hapticx" / "tmpl" / "MainActivity.java", fmRead):
mainActivity = fileVar.readAll()
mainActivity = mainActivity.replace("com.hapticx.tmpl", cfg.androidPackage)
Expand All @@ -154,13 +153,13 @@ proc buildCommandAux*(target: string = OS, release: bool = false, opt: string =
if not dirExists(directoryTmp):
createDir(directoryTmp)

# Replace package
withOpen("android" / "app" / "src" / "main" / "java" / cfg.androidPackage.replace(".", $DirSep) / "MainActivity.java", fmWrite):
fileVar.write(mainActivity)
withOpen("android" / "app" / "src" / "main" / "java" / cfg.androidPackage.replace(".", $DirSep) / "Native.java", fmWrite):
fileVar.write(native)
withOpen("android" / "settings.gradle", fmWrite):
fileVar.write(settingsGradle)
# Replace package
withOpen("android" / "app" / "src" / "main" / "java" / cfg.androidPackage.replace(".", $DirSep) / "MainActivity.java", fmWrite):
fileVar.write(mainActivity)
withOpen("android" / "app" / "src" / "main" / "java" / cfg.androidPackage.replace(".", $DirSep) / "Native.java", fmWrite):
fileVar.write(native)
withOpen("android" / "settings.gradle", fmWrite):
fileVar.write(settingsGradle)

# compile .so libraries
var
Expand Down

0 comments on commit b33a92b

Please sign in to comment.