Fixes for Android
This commit is contained in:
@@ -149,7 +149,7 @@ bool DeployDataStep::Perform(CookingData& data)
|
||||
{
|
||||
// Ask Flax.Build to provide .Net Host Runtime location for the target platform
|
||||
String sdks;
|
||||
const Char* platformName, *archName;
|
||||
const Char *platformName, *archName;
|
||||
data.GetBuildPlatformName(platformName, archName);
|
||||
String args = String::Format(TEXT("-log -logMessagesOnly -logFileWithConsole -logfile=SDKs.txt -printDotNetRuntime -platform={} -arch={}"), platformName, archName);
|
||||
bool failed = ScriptsBuilder::RunBuildTool(args, data.CacheDirectory);
|
||||
@@ -176,7 +176,24 @@ bool DeployDataStep::Perform(CookingData& data)
|
||||
FileSystem::CopyFile(dstDotnet / TEXT("THIRD-PARTY-NOTICES.TXT"), packFolder / TEXT("THIRD-PARTY-NOTICES.TXT"));
|
||||
failed |= FileSystem::CopyDirectory(dstDotnet / TEXT("shared/Microsoft.NETCore.App"), srcDotnet / TEXT("../lib/net7.0"), true);
|
||||
failed |= FileSystem::CopyFile(dstDotnet / TEXT("shared/Microsoft.NETCore.App") / TEXT("System.Private.CoreLib.dll"), srcDotnet / TEXT("System.Private.CoreLib.dll"));
|
||||
// TODO: copy .so/.dll files to native data files (eg. libSystem.IO.Compression.Native.so, libSystem.Native.so, libSystem.Security.Cryptography.Native.Android.so)
|
||||
switch (data.Platform)
|
||||
{
|
||||
case BuildPlatform::AndroidARM64:
|
||||
#define DEPLOY_NATIVE_FILE(filename) failed |= FileSystem::CopyFile(data.NativeCodeOutputPath / TEXT(filename), srcDotnet / TEXT(filename));
|
||||
if (data.Configuration != BuildConfiguration::Release)
|
||||
{
|
||||
DEPLOY_NATIVE_FILE("libmono-component-debugger.so");
|
||||
DEPLOY_NATIVE_FILE("libmono-component-diagnostics_tracing.so");
|
||||
DEPLOY_NATIVE_FILE("libmono-component-hot_reload.so");
|
||||
}
|
||||
DEPLOY_NATIVE_FILE("libmonosgen-2.0.so");
|
||||
DEPLOY_NATIVE_FILE("libSystem.IO.Compression.Native.so");
|
||||
DEPLOY_NATIVE_FILE("libSystem.Native.so");
|
||||
DEPLOY_NATIVE_FILE("libSystem.Security.Cryptography.Native.Android.so");
|
||||
#undef DEPLOY_NATIVE_FILE
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
if (failed)
|
||||
{
|
||||
data.Error(TEXT("Failed to copy .Net runtime data files."));
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <coreclr_delegates.h>
|
||||
#include <hostfxr.h>
|
||||
#elif DOTNET_HOST_MONO
|
||||
#include "Engine/Engine/CommandLine.h"
|
||||
#include <mono/jit/jit.h>
|
||||
#include <mono/jit/mono-private-unstable.h>
|
||||
#include <mono/utils/mono-logger.h>
|
||||
|
||||
@@ -188,7 +188,7 @@ public class GameActivity extends NativeActivity {
|
||||
return new String(buffer, encoding);
|
||||
}
|
||||
|
||||
void extractMonoFiles() throws IOException
|
||||
void extractDotnetFiles() throws IOException
|
||||
{
|
||||
String filesDir = getFilesDir().getAbsolutePath();
|
||||
AssetManager am = getAssets();
|
||||
@@ -196,13 +196,13 @@ public class GameActivity extends NativeActivity {
|
||||
|
||||
// Skip if extracted has is the same as in the package
|
||||
String hashFile = "hash.txt";
|
||||
File monoHashFile = new File(filesDir + "/" + hashFile);
|
||||
if (monoHashFile.exists()) {
|
||||
File currentHashFile = new File(filesDir + "/" + hashFile);
|
||||
if (currentHashFile.exists()) {
|
||||
for (int i = 0; i < amRootFiles.length; i++) {
|
||||
if (amRootFiles[i].equals(hashFile)) {
|
||||
String monoHash = readFileText(new FileInputStream(monoHashFile), StandardCharsets.US_ASCII);
|
||||
String currentHash = readFileText(new FileInputStream(currentHashFile), StandardCharsets.US_ASCII);
|
||||
String hash = readFileText(am.open(hashFile), StandardCharsets.US_ASCII);
|
||||
if (monoHash.equals(hash)) {
|
||||
if (currentHash.equals(hash)) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -211,9 +211,9 @@ public class GameActivity extends NativeActivity {
|
||||
}
|
||||
|
||||
// Extract files
|
||||
Log.i("Flax", "Extracting Mono files");
|
||||
new File(filesDir + "/Mono").mkdir();
|
||||
copyAssetDir(am, "Mono", filesDir + "/Mono");
|
||||
Log.i("Flax", "Extracting Dotnet files");
|
||||
new File(filesDir + "/Dotnet").mkdir();
|
||||
copyAssetDir(am, "Dotnet", filesDir + "/Dotnet");
|
||||
for (int i = 0; i < amRootFiles.length; i++) {
|
||||
String fromFile = amRootFiles[i];
|
||||
if (!fromFile.endsWith(".dll") && !fromFile.equals(hashFile))
|
||||
@@ -239,9 +239,9 @@ public class GameActivity extends NativeActivity {
|
||||
protected void onCreate(Bundle instance) {
|
||||
_activity = this;
|
||||
|
||||
// Extract Mono files and other bundled C# libraries from APK (Mono uses unix file access API which doesn't work with AAssetManager API)
|
||||
// Extract Dotnet files and other bundled C# libraries from APK (Mono uses unix file access API which doesn't work with AAssetManager API)
|
||||
try {
|
||||
extractMonoFiles();
|
||||
extractDotnetFiles();
|
||||
} catch (Exception e) {
|
||||
Log.i("Flax", "Error", e);
|
||||
}
|
||||
|
||||
6
Source/ThirdParty/nethost/nethost.Build.cs
vendored
6
Source/ThirdParty/nethost/nethost.Build.cs
vendored
@@ -66,7 +66,11 @@ public class nethost : ThirdPartyModule
|
||||
options.OutputFiles.Add(Path.Combine(hostRuntime.Path, "libnethost.a"));
|
||||
//options.OutputFiles.Add(Path.Combine(hostRuntime.Path, "libhostfxr.a"));
|
||||
break;
|
||||
case TargetPlatform.Android: break;
|
||||
case TargetPlatform.Android:
|
||||
options.PublicDefinitions.Add("USE_MONO_DYNAMIC_LIB");
|
||||
options.DependencyFiles.Add(Path.Combine(hostRuntime.Path, "libmonosgen-2.0.so"));
|
||||
options.Libraries.Add(Path.Combine(hostRuntime.Path, "libmonosgen-2.0.so"));
|
||||
break;
|
||||
default: throw new InvalidPlatformException(options.Platform.Target);
|
||||
}
|
||||
options.DependencyFiles.Add(Path.Combine(FolderPath, "FlaxEngine.CSharp.runtimeconfig.json"));
|
||||
|
||||
@@ -157,7 +157,7 @@ namespace Flax.Build
|
||||
var outputPath = Path.GetDirectoryName(buildData.Target.GetOutputFilePath(buildOptions));
|
||||
var outputFile = Path.Combine(outputPath, name + ".dll");
|
||||
var outputDocFile = Path.Combine(outputPath, name + ".xml");
|
||||
string monoRoot, monoPath = null, cscPath, referenceAssemblies, referenceAnalyzers;
|
||||
string monoRoot, monoPath = null, cscPath, referenceAssemblies, referenceAnalyzers, dotnetPath = "dotnet";
|
||||
switch (buildPlatform)
|
||||
{
|
||||
case TargetPlatform.Windows:
|
||||
@@ -172,6 +172,7 @@ namespace Flax.Build
|
||||
if (dotnetSdk.IsValid)
|
||||
{
|
||||
// Use dotnet
|
||||
dotnetPath = Path.Combine(dotnetSdk.RootPath, "dotnet.exe");
|
||||
cscPath = Path.Combine(dotnetSdk.RootPath, @$"sdk\{dotnetSdk.VersionName}\Roslyn\bincore\csc.dll");
|
||||
referenceAssemblies = Path.Combine(dotnetSdk.RootPath, @$"shared\Microsoft.NETCore.App\{dotnetSdk.RuntimeVersionName}\");
|
||||
referenceAnalyzers = Path.Combine(dotnetSdk.RootPath, @$"packs\Microsoft.NETCore.App.Ref\{dotnetSdk.RuntimeVersionName}\analyzers\dotnet\cs\");
|
||||
@@ -315,7 +316,7 @@ namespace Flax.Build
|
||||
// https://github.com/dotnet/roslyn/blob/main/docs/compilers/Compiler%20Server.md
|
||||
|
||||
#if USE_NETCORE
|
||||
task.CommandPath = "dotnet";
|
||||
task.CommandPath = dotnetPath;
|
||||
task.CommandArguments = $"exec \"{cscPath}\" /noconfig /shared @\"{responseFile}\"";
|
||||
#else
|
||||
task.CommandPath = cscPath;
|
||||
|
||||
Reference in New Issue
Block a user