Skip to content

Commit c73edaa

Browse files
authored
Merge pull request 20tab#5 from crazytuzi/master
Add support for Android
2 parents f2de7ff + fc9f0c8 commit c73edaa

File tree

242 files changed

+5552
-36828
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+5552
-36828
lines changed

Source/UnrealEnginePython/Private/UnrealEnginePython.cpp

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const char *ue4_module_options = "linux_global_symbols";
6363
#endif
6464

6565
#if PLATFORM_ANDROID
66+
#include "Misc/LocalTimestampDirectoryVisitor.h"
6667
#include "Android/AndroidJNI.h"
6768
#include "Android/AndroidApplication.h"
6869
#endif
@@ -464,52 +465,50 @@ void FUnrealEnginePythonModule::StartupModule()
464465
#if PY_MAJOR_VERSION >= 3
465466
init_unreal_engine_builtin();
466467
#if PLATFORM_ANDROID
467-
extern FString GOBBFilePathBase;
468-
extern FString GFilePathBase;
468+
FString InDirectory = FString(TEXT("PythonScripts"));
469+
469470
extern FString GExternalFilePath;
470-
extern FString GPackageName;
471-
extern int32 GAndroidPackageVersion;
472-
FString OBBDir1 = GOBBFilePathBase + FString(TEXT("/Android/obb/") + GPackageName);
473-
FString OBBDir2 = GOBBFilePathBase + FString(TEXT("/obb/") + GPackageName);
474-
FString MainOBBName = FString::Printf(TEXT("main.%d.%s.obb"), GAndroidPackageVersion, *GPackageName);
475-
FString PatchOBBName = FString::Printf(TEXT("patch.%d.%s.obb"), GAndroidPackageVersion, *GPackageName);
476-
FString UnrealEnginePython_OBBPath;
477-
if (FPaths::FileExists(*(OBBDir1 / MainOBBName)))
478-
{
479-
UnrealEnginePython_OBBPath = OBBDir1 / MainOBBName / FApp::GetProjectName() / FString(TEXT("Content/PythonScripts"));
480-
}
481-
else if (FPaths::FileExists(*(OBBDir2 / MainOBBName)))
482-
{
483-
UnrealEnginePython_OBBPath = OBBDir2 / MainOBBName / FApp::GetProjectName() / FString(TEXT("Content/PythonScripts"));
484-
}
485-
if (FPaths::FileExists(*(OBBDir1 / PatchOBBName)))
486-
{
487-
UnrealEnginePython_OBBPath = OBBDir1 / PatchOBBName / FApp::GetProjectName() / FString(TEXT("Content/PythonScripts"));
488-
}
489-
else if (FPaths::FileExists(*(OBBDir2 / PatchOBBName)))
490-
{
491-
UnrealEnginePython_OBBPath = OBBDir1 / PatchOBBName / FApp::GetProjectName() / FString(TEXT("Content/PythonScripts"));
492-
}
493471

494-
if (!UnrealEnginePython_OBBPath.IsEmpty())
495-
{
496-
ScriptsPaths.Add(UnrealEnginePython_OBBPath);
497-
}
472+
FString DirectoryPath = FPaths::ProjectContentDir() / InDirectory;
473+
474+
IFileManager* FileManager = &IFileManager::Get();
498475

499-
FString FinalPath = GFilePathBase / FString("UE4Game") / FApp::GetProjectName() / FApp::GetProjectName() / FString(TEXT("Content/PythonScripts"));
500-
ScriptsPaths.Add(FinalPath);
476+
// iterate over all the files in provided directory
477+
FLocalTimestampDirectoryVisitor Visitor(FPlatformFileManager::Get().GetPlatformFile(), TArray<FString>(),
478+
TArray<FString>(), false);
501479

502-
FString BasePythonPath = FinalPath / FString(TEXT("stdlib.zip")) + FString(":") + FinalPath;
480+
FileManager->IterateDirectoryRecursively(*DirectoryPath, Visitor);
503481

504-
if (!UnrealEnginePython_OBBPath.IsEmpty())
482+
FString Prefix = FApp::GetProjectName() / FString(TEXT("Content/PythonScripts/"));
483+
484+
for (TMap<FString, FDateTime>::TIterator TimestampIt(Visitor.FileTimes); TimestampIt; ++TimestampIt)
505485
{
506-
BasePythonPath += FString(":") + UnrealEnginePython_OBBPath;
486+
FString Path = TimestampIt.Key();
487+
488+
Path.RemoveFromStart(Prefix);
489+
490+
// read the file contents and write it if successful to external path
491+
TArray<uint8> MemFile;
492+
493+
const FString SourceFilename = TimestampIt.Key();
494+
495+
if (FFileHelper::LoadFileToArray(MemFile, *SourceFilename, 0))
496+
{
497+
FString DestFilename = GExternalFilePath / InDirectory / Path;
498+
499+
FFileHelper::SaveArrayToFile(MemFile, *DestFilename);
500+
}
507501
}
508502

509-
UE_LOG(LogPython, Warning, TEXT("Setting Android Base Path to %s"), *BasePythonPath);
503+
FString PyScriptsSearchPath = GExternalFilePath / InDirectory;
510504

511-
Py_SetPath(Py_DecodeLocale(TCHAR_TO_UTF8(*BasePythonPath), NULL));
512-
505+
ScriptsPaths.Reset();
506+
507+
ScriptsPaths.Add(PyScriptsSearchPath);
508+
509+
UE_LOG(LogPython, Warning, TEXT("Setting Android Python Scripts Search Path to %s"), *PyScriptsSearchPath);
510+
511+
Py_SetPath(Py_DecodeLocale(TCHAR_TO_UTF8(*PyScriptsSearchPath), NULL));
513512
#elif PLATFORM_IOS
514513
FString IOSContentPath = IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*IFileManager::Get().GetFilenameOnDisk(*FPaths::ConvertRelativePathToFull(PROJECT_CONTENT_DIR)));
515514
FString PyScriptsSearchPath = IOSContentPath / FString(TEXT("lib")) + FString(":") +

Source/UnrealEnginePython/UnrealEnginePython.Build.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,19 +258,41 @@ public UnrealEnginePython(TargetInfo Target)
258258
PublicAdditionalLibraries.Add(items[1]);
259259
}
260260
}
261-
#if WITH_FORWARDED_MODULE_RULES_CTOR
262261
else if (Target.Platform == UnrealTargetPlatform.Android)
263262
{
264-
PublicIncludePaths.Add(System.IO.Path.Combine(ModuleDirectory, "../../android/python35/include"));
265-
PublicAdditionalLibraries.Add(System.IO.Path.Combine(ModuleDirectory, "../../android/armeabi-v7a"));
266-
PublicAdditionalLibraries.Add("python3.5m");
263+
string PythonAndroidLibsDirectory = Path.Combine(PluginDirectory, "android");
264+
265+
string includePath = Path.Combine(PythonAndroidLibsDirectory, "include", "python3.7m");
266+
PublicIncludePaths.Add(includePath);
267+
268+
PublicSystemLibraryPaths.AddRange(
269+
new string[] {
270+
Path.Combine(PythonAndroidLibsDirectory, "libs", "arm64-v8a")
271+
});
267272

273+
string[] libraryPaths = new string[] {
274+
Path.Combine(PythonAndroidLibsDirectory, "libs", "arm64-v8a", "libbz2.so"),
275+
Path.Combine(PythonAndroidLibsDirectory, "libs", "arm64-v8a", "libcrypto.so"),
276+
Path.Combine(PythonAndroidLibsDirectory, "libs", "arm64-v8a", "libcrypto1.1.so"),
277+
Path.Combine(PythonAndroidLibsDirectory, "libs", "arm64-v8a", "libffi.so"),
278+
Path.Combine(PythonAndroidLibsDirectory, "libs", "arm64-v8a", "liblzma.so"),
279+
Path.Combine(PythonAndroidLibsDirectory, "libs", "arm64-v8a", "libpython3.7m.so"),
280+
Path.Combine(PythonAndroidLibsDirectory, "libs", "arm64-v8a", "librubicon.so"),
281+
Path.Combine(PythonAndroidLibsDirectory, "libs", "arm64-v8a", "libsqlite3.so"),
282+
Path.Combine(PythonAndroidLibsDirectory, "libs", "arm64-v8a", "libssl.so"),
283+
Path.Combine(PythonAndroidLibsDirectory, "libs", "arm64-v8a", "libssl1.1.so"),
284+
};
285+
286+
foreach (string libraryPath in libraryPaths)
287+
{
288+
PublicAdditionalLibraries.Add(libraryPath);
289+
}
290+
268291
string APLName = "UnrealEnginePython_APL.xml";
269292
string RelAPLPath = Utils.MakePathRelativeTo(ModuleDirectory, Target.RelativeEnginePath);
270293
AdditionalPropertiesForReceipt.Add("AndroidPlugin", Path.Combine(RelAPLPath, APLName));
271294

272295
}
273-
#endif
274296
else if (Target.Platform == UnrealTargetPlatform.IOS)
275297
{
276298
string PythonIOSLibsDirectory = Path.Combine(PluginDirectory, "python", "python36", "ios");

Source/UnrealEnginePython/UnrealEnginePython_APL.xml

Lines changed: 86 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,95 @@
88

99
<!-- optional files or directories to copy to Intermediate/Android/APK -->
1010
<resourceCopies>
11-
<log text="python APL copying files for $S(Architecture)/"/>
12-
<copyFile src="$S(PluginDir)/../../android/armeabi-v7a/libcrystax.so"
13-
dst="$S(BuildDir)/libs/armeabi-v7a/libcrystax.so" />
14-
<copyFile src="$S(PluginDir)/../../android/armeabi-v7a/libpython3.5m.so"
15-
dst="$S(BuildDir)/libs/armeabi-v7a/libpython3.5m.so" />
11+
<log text="bz2 APL copying files for $S(Architecture)/"/>
12+
<copyFile src="$S(PluginDir)/../../android/libs/arm64-v8a/libbz2.so"
13+
dst="$S(BuildDir)/libs/arm64-v8a/libbz2.so" />
14+
</resourceCopies>
15+
<resourceCopies>
16+
<log text="crypto APL copying files for $S(Architecture)/"/>
17+
<copyFile src="$S(PluginDir)/../../android/libs/arm64-v8a/libcrypto.so"
18+
dst="$S(BuildDir)/libs/arm64-v8a/libcrypto.so" />
19+
</resourceCopies>
20+
<resourceCopies>
21+
<log text="crypto1.1 APL copying files for $S(Architecture)/"/>
22+
<copyFile src="$S(PluginDir)/../../android/libs/arm64-v8a/libcrypto1.1.so"
23+
dst="$S(BuildDir)/libs/arm64-v8a/libcrypto1.1.so" />
24+
</resourceCopies>
25+
<resourceCopies>
26+
<log text="ffi APL copying files for $S(Architecture)/"/>
27+
<copyFile src="$S(PluginDir)/../../android/libs/arm64-v8a/libffi.so"
28+
dst="$S(BuildDir)/libs/arm64-v8a/libffi.so" />
29+
</resourceCopies>
30+
<resourceCopies>
31+
<log text="lzma APL copying files for $S(Architecture)/"/>
32+
<copyFile src="$S(PluginDir)/../../android/libs/arm64-v8a/liblzma.so"
33+
dst="$S(BuildDir)/libs/arm64-v8a/liblzma.so" />
34+
</resourceCopies>
35+
<resourceCopies>
36+
<log text="python3.7m APL copying files for $S(Architecture)/"/>
37+
<copyFile src="$S(PluginDir)/../../android/libs/arm64-v8a/libpython3.7m.so"
38+
dst="$S(BuildDir)/libs/arm64-v8a/libpython3.7m.so" />
39+
</resourceCopies>
40+
<resourceCopies>
41+
<log text="rubicon APL copying files for $S(Architecture)/"/>
42+
<copyFile src="$S(PluginDir)/../../android/libs/arm64-v8a/librubicon.so"
43+
dst="$S(BuildDir)/libs/arm64-v8a/librubicon.so" />
44+
</resourceCopies>
45+
<resourceCopies>
46+
<log text="sqlite3 APL copying files for $S(Architecture)/"/>
47+
<copyFile src="$S(PluginDir)/../../android/libs/arm64-v8a/libsqlite3.so"
48+
dst="$S(BuildDir)/libs/arm64-v8a/libsqlite3.so" />
49+
</resourceCopies>
50+
<resourceCopies>
51+
<log text="ssl APL copying files for $S(Architecture)/"/>
52+
<copyFile src="$S(PluginDir)/../../android/libs/arm64-v8a/libssl.so"
53+
dst="$S(BuildDir)/libs/arm64-v8a/libssl.so" />
54+
</resourceCopies>
55+
<resourceCopies>
56+
<log text="ssl1.1 APL copying files for $S(Architecture)/"/>
57+
<copyFile src="$S(PluginDir)/../../android/libs/arm64-v8a/libssl1.1.so"
58+
dst="$S(BuildDir)/libs/arm64-v8a/libssl1.1.so" />
1659
</resourceCopies>
1760

1861
<soLoadLibrary>
19-
<log text="Python APL adding loadLibrary references"/>
20-
<loadLibrary name="crystax" failmsg="libcrystax not loaded and required!" />
21-
<loadLibrary name="python3.5m" failmsg="libpython3.5m not loaded and required!" />
62+
<log text="bz2 APL adding loadLibrary references"/>
63+
<loadLibrary name="bz2" failmsg="bz2 not loaded and required!" />
64+
</soLoadLibrary>
65+
<soLoadLibrary>
66+
<log text="crypto APL adding loadLibrary references"/>
67+
<loadLibrary name="crypto" failmsg="crypto not loaded and required!" />
68+
</soLoadLibrary>
69+
<soLoadLibrary>
70+
<log text="crypto1.1 APL adding loadLibrary references"/>
71+
<loadLibrary name="crypto1.1" failmsg="crypto1.1 not loaded and required!" />
72+
</soLoadLibrary>
73+
<soLoadLibrary>
74+
<log text="ffi APL adding loadLibrary references"/>
75+
<loadLibrary name="ffi" failmsg="ffi not loaded and required!" />
76+
</soLoadLibrary>
77+
<soLoadLibrary>
78+
<log text="lzma APL adding loadLibrary references"/>
79+
<loadLibrary name="lzma" failmsg="lzma not loaded and required!" />
80+
</soLoadLibrary>
81+
<soLoadLibrary>
82+
<log text="python3.7m APL adding loadLibrary references"/>
83+
<loadLibrary name="python3.7m" failmsg="python3.6m not loaded and required!" />
84+
</soLoadLibrary>
85+
<soLoadLibrary>
86+
<log text="rubicon APL adding loadLibrary references"/>
87+
<loadLibrary name="rubicon" failmsg="rubicon not loaded and required!" />
88+
</soLoadLibrary>
89+
<soLoadLibrary>
90+
<log text="sqlite3 APL adding loadLibrary references"/>
91+
<loadLibrary name="sqlite3" failmsg="sqlite3 not loaded and required!" />
92+
</soLoadLibrary>
93+
<soLoadLibrary>
94+
<log text="ssl APL adding loadLibrary references"/>
95+
<loadLibrary name="ssl" failmsg="ssl not loaded and required!" />
96+
</soLoadLibrary>
97+
<soLoadLibrary>
98+
<log text="ssl1.1 APL adding loadLibrary references"/>
99+
<loadLibrary name="ssl1.1" failmsg="ssl1.1 not loaded and required!" />
22100
</soLoadLibrary>
23101
</root>
24102

android/armeabi-v7a/libcrystax.so

-3.37 MB
Binary file not shown.
-6.78 MB
Binary file not shown.
-8.41 MB
Binary file not shown.

0 commit comments

Comments
 (0)