-# This file is part of NIT ( http://www.nitlanguage.org )
#
# Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
#
var app_version = project.version
if app_version == null then app_version = "1.0"
+ var app_min_sdk = project.min_sdk
+ if app_min_sdk == null then app_min_sdk = 10
+
+ var app_target_sdk = project.target_sdk
+ if app_target_sdk == null then app_target_sdk = app_min_sdk
+
+ var app_max_sdk = ""
+ if project.max_sdk != null then app_max_sdk = "android:maxSdkVersion=\"{app_max_sdk}\""
+
# Clear the previous android project, so there is no "existing project warning"
# or conflict between Java files of different projects
if android_project_root.file_exists then android_project_root.rmdir
var args = ["android", "-s",
"create", "project",
"--name", short_project_name,
- "--target", "android-10",
+ "--target", "android-{app_target_sdk}",
"--path", android_project_root,
"--package", app_package,
"--activity", short_project_name]
android:versionName="{{{app_version}}}">
<!-- This is the platform API where NativeActivity was introduced. -->
- <uses-sdk android:minSdkVersion="9" />
+ <uses-sdk
+ android:minSdkVersion="{{{app_min_sdk}}}"
+ android:targetSdkVersion="{{{app_target_sdk}}}"
+ {{{app_max_sdk}}} />
<application
android:label="@string/app_name"
<!-- END_INCLUDE(manifest) -->
""".write_to_file("{dir}/AndroidManifest.xml")
- ### generate res/values/strings.xml
- dir = "{android_project_root}/res/"
- if not dir.file_exists then dir.mkdir
- dir = "{dir}/values/"
- if not dir.file_exists then dir.mkdir
- """<?xml version="1.0" encoding="utf-8"?>
-<resources>
- <string name="app_name">{{{app_name}}}</string>
-</resources>
- """.write_to_file("{dir}/strings.xml")
-
### Link to png sources
# libpng is not available on Android NDK
# FIXME make obtionnal when we have alternatives to mnit
toolcontext.exec_and_check(["ln", "-s", assets_dir, target_assets_dir], "Android project error")
end
end
+
+ ### copy resources (for android)
+ # This will be accessed from `android_project_root`
+ var res_dir
+ if compiler.mainmodule.location.file != null then
+ # it is a real file, use "{file}/../res"
+ res_dir = "{compiler.mainmodule.location.file.filename.dirname}/../res"
+ else
+ # probably used -m, use "."
+ res_dir = "res"
+ end
+ if res_dir.file_exists then
+ res_dir = res_dir.realpath
+ var target_res_dir = "{android_project_root}"
+ if target_res_dir.file_exists then
+ # copy the res folder to .nit_compile
+ toolcontext.exec_and_check(["cp", "-R", res_dir, target_res_dir], "Android project error")
+ end
+ end
+
end
redef fun write_makefile(compiler, compile_dir, cfiles)