Skip to content

Commit

Permalink
linux work
Browse files Browse the repository at this point in the history
  • Loading branch information
halfnelson committed Mar 27, 2016
1 parent cf6c288 commit 7777e03
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 56 deletions.
10 changes: 5 additions & 5 deletions scripts/build-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ PITO_ROOT=$(cd `dirname $0`/.. && pwd)
#----- Build libmoai using sdk methods -----

export PATH=$ANDROID_NDK:$PATH

echo $PATH
echo "Builing libmoai"

pushd $MOAI_SDK_HOME/ant
if [ "$1" == "--clean" ]; then
./libmoai-clean.sh
if [ "$1" == "--clean" ]; then
./libmoai-clean.sh
fi

./libmoai-build.sh || ( echo "Android NDK build failed" && exit 1)

mkdir -p $PITO_ROOT/lib/android/libs
Expand All @@ -22,4 +22,4 @@ mkdir -p $PITO_ROOT/lib/android/obj
cp -a libmoai/libs/ $PITO_ROOT/lib/android/libs
(cd libmoai/obj && find . -type f -name \*.a -exec tar cf - {} +) | (cd $PITO_ROOT/lib/android/obj && tar xf -)

popd
popd
3 changes: 1 addition & 2 deletions scripts/env-local.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ echo "Importing local env"
# MOAI_SDK_HOME=/Users/moaiuser/moai-dev

## Path to the Android NDK
#NDK_PATH=/Users/moaiuser/Downloads/android-ndk-r11b
NDK_PATH=/home/david/Downloads/android-ndk-r11b

## Path to Emscripten SDK
#EMSDK_PATH=/Users/moaiuser/Downloads/emsdk_portable

102 changes: 53 additions & 49 deletions util/host-android-studio/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,33 @@ local hostconfig = {


function findAndroidSdk()

local fromenv = os.getenv("ANDROID_SDK_ROOT") or os.getenv("ANDROID_HOME") or os.getenv("ANDROID_SDK_HOME")
if fromenv then return fromenv end

local isWindows = MOAIEnvironment.osBrand == 'Windows'
if isWindows then
local appdata = os.getenv("LOCALAPPDATA")
if (appdata and MOAIFileSystem.checkPathExists(appdata.."\\android\\sdk")) then
return appdata.."\\android\\sdk"
return appdata.."\\android\\sdk"
end
end

if MOAIEnvironment.osBrand == "OSX" then
local home = os.getenv("HOME")
if (home and MOAIFileSystem.checkPathExists(home.."/Library/Android/sdk")) then
return home.."/Library/Android/sdk"
end
end

if MOAIEnvironment.osBrand == "linux" then
local home = os.getenv("HOME")
local sdkpath = home.."/android-sdk-linux"
if (home and MOAIFileSystem.checkPathExists(sdkpath)) then
return sdkpath
end
end

return false
end

Expand All @@ -70,7 +70,7 @@ for i, escape, param, iter in util.iterateCommandLine ( arg or {}) do
if escape == 'l' or escape == 'lib-source' then
config.LIB_SOURCE = MOAIFileSystem.getAbsoluteDirectoryPath(param)
end

if escape == 'c' or escape == 'config' then
configFile = MOAIFileSystem.getAbsoluteFilePath(param)
end
Expand All @@ -81,22 +81,22 @@ end
-- actions
--==============================================================

local copyhostfiles
local copyhostfiles
local validateConfig
local copylib
local linklib
local applyConfigFile
local configureHost

copyhostfiles = function()
copyhostfiles = function()
local output = config.OUTPUT_DIR
print("Creating ",output)
MOAIFileSystem.affirmPath(output)
local ANDROID_LIBS = config.LIB_SOURCE
print("Copying from ", PITO_HOME..'host-templates/android/', "to", output)

print("Copying from ", PITO_HOME..'host-templates/android/', "to", output)
MOAIFileSystem.copy ( PITO_HOME..'host-templates/android/', output )

MOAIFileSystem.deleteFile ( output.."moai/src/main/jni/Android.mk")
MOAIFileSystem.copy ( PITO_HOME..'host-templates/android/Android-prebuilt.mk', output.."moai/src/main/jni/Android.mk" )
MOAIFileSystem.copy ( PITO_HOME..'host-templates/android/gradle/local.properties', output.."local.properties")
Expand All @@ -106,11 +106,11 @@ getAbsoluteLuaRoot = function()
local oldworkingdir = MOAIFileSystem.getWorkingDirectory()
--get lua path relative to config file as absolute
MOAIFileSystem.setWorkingDirectory(INVOKE_DIR)

local luasrc = MOAIFileSystem.getAbsoluteDirectoryPath(hostconfig['LuaSrc'])

MOAIFileSystem.setWorkingDirectory(oldworkingdir)

return luasrc
end

Expand All @@ -119,21 +119,21 @@ end
applyConfigFile = function(configFile)
print("reading config from "..configFile)
util.dofileWithEnvironment(configFile, hostconfig)

--copy host specific settings to main config
if (hostconfig["HostSettings"] and hostconfig["HostSettings"]["android"]) then
for k,v in pairs(hostconfig["HostSettings"]["android"]) do
hostconfig[k] = v
end
end

hostconfig["HostSettings"] = nil

end

validateConfig = function()
--validation

--validate lua path
local luapath = getAbsoluteLuaRoot()
if not MOAIFileSystem.checkFileExists(luapath.."main.lua") then
Expand All @@ -152,50 +152,54 @@ configureHost = function()
else
print("\n\nUsing default config ")
end

for k,v in pairs(hostconfig) do
print (k..": ", v)
end

local modules = hostconfig['Modules'] or {}

local modulestr = ""

for _,v in pairs(modules) do
if modulestr == "" then
modulestr = v
else
modulestr = modulestr..','..v
end
end

print("configuring lua source root")

local luasrc = getAbsoluteLuaRoot()

--now get lua path (currently absolute) as relative to gradle.properties
luasrc = MOAIFileSystem.getRelativePath(luasrc, output..'moai/' )

if (not luasrc) then
error("Error configuring lua source folder as relative "..hostconfig['LuaSrc'])
end
local patternFor = function(name)

local patternFor = function(name)
return '(<string name="'..name..'">)(.-)(</string>)'
end
--gradle windows paths need to be double escaped

--gradle windows paths need to be double escaped
local escGradlePath = function(dir)
return dir:gsub("\\","\\\\"):gsub(":","\\:")
end

local sdkdir = escGradlePath(hostconfig['SdkDir'])


local sdkdir = ""
if (hostconfig['SdkDir']) then
sdkdir = escGradlePath(hostconfig['SdkDir'])
end
print("updating template values")


--libroot
util.replaceInFiles ({

[ output .. 'moai/build.gradle'] = {
[ 'applicationId "[^"]+"']= 'applicationId "'..hostconfig['ApplicationId']..'"',
[ '//assets.srcDirs' ] = 'assets.srcDirs',
Expand All @@ -209,33 +213,33 @@ configureHost = function()
[patternFor("scheme_name")] = '%1'..hostconfig['SchemeName']..'%3',
[patternFor("fb_app_id")] = '%1'..hostconfig['FBAppId']..'%3',
[patternFor("gms_app_id")] = '%1'..hostconfig['GMSAppId']..'%3'
},
},

[ output .. 'local.properties' ] = {
[ 'sdk.dir=[^\n]+' ]= "sdk.dir="..sdkdir,
}
})
--enable modules

--enable modules
for _,v in pairs(modules) do
if modulestr == "" then
modulestr = v
else
modulestr = modulestr..','..v
end
end


print("copying icons")
--icons
MOAIFileSystem.setWorkingDirectory(INVOKE_DIR)

if (hostconfig['Icons']) then
for k,v in pairs(hostconfig['Icons']) do
if v == "" then
print("Removing default icon ",k)
MOAIFileSystem.deleteDirectory(config.OUTPUT_DIR.."moai/src/main/res/drawable-"..k, true)
else
else
if MOAIFileSystem.checkFileExists(v) then
MOAIFileSystem.copy(v, config.OUTPUT_DIR.."moai/src/main/res/drawable-"..k.."/icon.png")
else
Expand All @@ -248,23 +252,23 @@ end



copylib = function()
copylib = function()
local output = config.OUTPUT_DIR
local ANDROID_LIBS = config.LIB_SOURCE
MOAIFileSystem.copy ( MOAI_SDK_HOME.."ant/libmoai/jni", output.."moai/src/main/jni" )
MOAIFileSystem.copy ( ANDROID_LIBS.."/libs", output.."moai/src/main/libs" )
end

linklib = function()
linklib = function()
local isWindows = MOAIEnvironment.osBrand == 'Windows'
local cmd = isWindows and 'mklink /D "'..config.OUTPUT_DIR..'moai/src/main/libs" "'..config.LIB_SOURCE..'/libs"'
local cmd = isWindows and 'mklink /D "'..config.OUTPUT_DIR..'moai/src/main/libs" "'..config.LIB_SOURCE..'/libs"'
or 'ln -s "'..config.LIB_SOURCE..'/libs" "'..config.OUTPUT_DIR..'moai/src/main/libs"'
if os.execute(cmd) > 0 then
print ("Error creating link, try running as administrator")
end

local isWindows = MOAIEnvironment.osBrand == 'Windows'
local cmd = isWindows and 'mklink /D "'..config.OUTPUT_DIR..'moai/src/main/jni" "'..MOAISDK_HOME..'ant/libmoai/jni"'
local cmd = isWindows and 'mklink /D "'..config.OUTPUT_DIR..'moai/src/main/jni" "'..MOAISDK_HOME..'ant/libmoai/jni"'
or 'ln -s "'..MOAI_SDK_HOME..'ant/libmoai/jni" "'..config.OUTPUT_DIR..'moai/src/main/jni"'
if os.execute(cmd) > 0 then
print ("Error creating link, try running as administrator")
Expand All @@ -276,8 +280,8 @@ if configFile then
applyConfigFile(configFile)
end

if (not hostconfig['SdkDir']) or (hostconfig['SdkDir'] == "") then
hostconfig['SdkDir'] = findAndroidSdk()
if (not hostconfig['SdkDir']) or (hostconfig['SdkDir'] == "") then
hostconfig['SdkDir'] = findAndroidSdk()
end


Expand Down

0 comments on commit 7777e03

Please sign in to comment.