Jelajahi Sumber

Android build enhancements.

woollybah 9 tahun lalu
induk
melakukan
62984a00e7
5 mengubah file dengan 85 tambahan dan 10 penghapusan
  1. 6 5
      bmk.bmx
  2. 30 4
      bmk_make.bmx
  3. 43 1
      bmk_util.bmx
  4. 4 0
      custom.bmk
  5. 2 0
      resources/android/android-project/project.properties

+ 6 - 5
bmk.bmx

@@ -426,11 +426,7 @@ Function MakeApplication( args$[],makelib )
 			
 		EndIf
 	End If
-	
-	' "android-project" check and copy
-	If processor.Platform() = "android" Then
-		DeployAndroidProject()
-	End If
+
 	
 	If processor.Platform() = "emscripten" Then
 		If ExtractExt(opt_outfile).ToLower()<>"html" opt_outfile:+".html"
@@ -442,6 +438,11 @@ Function MakeApplication( args$[],makelib )
 
 	Local buildManager:TBuildManager = New TBuildManager
 
+	' "android-project" check and copy
+	If processor.Platform() = "android" Then
+		DeployAndroidProject()
+	End If
+
 	buildManager.MakeApp(Main, makelib)
 	buildManager.DoBuild(True)
 

+ 30 - 4
bmk_make.bmx

@@ -71,12 +71,12 @@ Function ConfigureAndroidPaths()
 	Local toolchainDir:String = processor.Option("android.ndk", "") + "/toolchains/" + ..
 			toolchain + processor.Option("android.toolchain.version", "") + "/prebuilt/" + native
 	
-	' look for 64 bit build first, then x86
+	' look for 64 bit build first, then x86, then fallback to no architecture (generally on 32-bit dists)
 	If FileType(toolchainDir + "-x86_64") = FILETYPE_DIR Then
 		toolchainDir :+ "-x86_64"
 	Else If FileType(toolchainDir + "-x86") = FILETYPE_DIR Then
 		toolchainDir :+ "-x86"
-	Else
+	Else If FileType(toolchainDir) <> FILETYPE_DIR Then
 		Throw "Cannot determine toolchain dir for '" + native + "', at '" + toolchainDir + "'"
 	End If
 
@@ -112,7 +112,7 @@ Function ConfigureAndroidPaths()
 	Local platformDir:String = processor.Option("android.ndk", "") + "/platforms/android-" + ..
 			processor.Option("android.platform", "") + "/" + arch
 
-	If Not FileType(platformDir)Then
+	If Not FileType(platformDir) Then
 		Throw "Cannot determine platform dir for '" + arch + "' at '" + platformDir + "'"
 	End If
 	
@@ -122,6 +122,20 @@ Function ConfigureAndroidPaths()
 	
 	' abi
 	globals.SetVar("android.abi", abi)
+	
+	' sdk target
+	Local target:String = GetAndroidSDKTarget()
+
+	If Not target Or Not FileType(processor.Option("android.sdk", "") + "/platforms/android-" + target) Then
+		Local sdkPath:String = processor.Option("android.sdk.target", "")
+		If sdkPath Then
+			Throw "Cannot determine SDK target for '" + sdkPath + "'"
+		Else
+			Throw "Cannot determine SDK target dir. ANDROID_SDK_TARGET or android.sdk.target option is not set, and auto-lookup failed."
+		End If
+	End If
+
+	globals.SetVar("android.sdk.target", target)
 
 End Function
 
@@ -187,6 +201,19 @@ Function CheckAndroidPaths()
 		globals.SetVar("android.platform", androidPlatform)
 	End If
 
+	Local androidSDKTarget:String = getenv_("ANDROID_SDK_TARGET")
+	If Not androidSDKTarget Then
+		androidSDKTarget = processor.Option("android.sdk.target", "")
+		
+		If androidSDKTarget Then
+			putenv_("ANDROID_SDK_TARGET=" + androidSDKTarget.Trim())
+		End If
+		
+		' NOTE : if not set, we'll try to determine the actual target later, and fail if required then.
+	Else
+		globals.SetVar("android.sdk.target", androidSDKTarget)
+	End If
+
 	Local antHome:String = getenv_("ANT_HOME")
 	If Not antHome Then
 		antHome = processor.Option("ant.home", "")
@@ -265,7 +292,6 @@ Type TBuildManager
 	End Method
 
 	Method MakeApp(main_path:String, makelib:Int)
-
 		app_main = main_path
 
 		Local source:TSourceFile = GetSourceFile(app_main, False, opt_all)

+ 43 - 1
bmk_util.bmx

@@ -660,6 +660,12 @@ Function DeployAndroidProject()
 	'     update build.xml
 	MergeFile(projectDir, "build.xml", projectSettings)
 
+	' set the sdk target
+	Local projectPropertiesFile:String = projectDir + "/project.properties"
+	Local projectProperties:String = LoadString( projectPropertiesFile )
+	projectProperties = ReplaceBlock( projectProperties, "sdk.target","target=android-" + processor.option("android.sdk.target", ""), "~n#")
+	SaveString(projectProperties, projectPropertiesFile)
+
 	' copy resources to assets
 	CopyAndroidResources(buildDir, assetsDir)
 End Function
@@ -741,6 +747,42 @@ Function DefaultAndroidSettings:TMap()
 	Return settings
 End Function
 
+Function GetAndroidSDKTarget:String()
+	Local sdkPath:String = processor.Option("android.sdk", "") + "/platforms"
+	Local target:String = processor.Option("android.sdk.target", "")
+	
+	Local targetPath:String
+	
+	If target Then
+		targetPath = sdkPath + "/android-" + target
+		
+		If FileType(targetPath) = FILETYPE_DIR Then
+			Return target
+		End If
+		
+	End If
+	
+	' find highest numbered target platform dir
+	Local dirs:String[] = LoadDir(sdkPath, True)
+	Local high:Int
+	
+	For Local dir:String = EachIn dirs
+	
+		Local index:Int = dir.Find("android-")
+		
+		If index >= 0 Then
+			Local value:Int = dir[index + 8..].ToInt()
+			high = Max(value, high)
+		End If
+	
+	Next
+	
+	If high > 0 Then
+		Return high
+	End If
+	
+End Function
+
 Function PathFromPackage:String(package:String)
 	Return package.Replace(".", "/")
 End Function
@@ -862,7 +904,7 @@ Function PackageIOSApp( path$, lnk_files:TList, opts$ )
 	
 	Local projectPath:String = appProjectDir + "/project.pbxproj"
 	
-	Local uuid:String = "5CABBIEFACE"
+	Local uuid:String = "5CABB1EFACE"
 
 	Local fileMap:TFileMap = New TFileMap
 	

+ 4 - 0
custom.bmk

@@ -21,6 +21,10 @@
 #addoption android.toolchain.version "4.9"
 #addoption android.platform "12"
 
+# ** Optional SDK target **
+#    Will try to determine valid target to update project.properties, if not set.
+#addoption android.sdk.target "23"
+
 # ** optional ant location **
 # ** defaults to resources/apache-ant **
 

+ 2 - 0
resources/android/android-project/project.properties

@@ -11,4 +11,6 @@
 #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
 
 # Project target.
+#${start.sdk.target}
 target=android-19
+#${end.sdk.target}