Nuke.Unreal
Build Unreal apps in Style.
Loading...
Searching...
No Matches
IAndroidBuildTargets.cs
1using Nuke.Common;
2using Nuke.Common.IO;
3using Nuke.Common.Tooling;
4
6
7/// <summary>
8/// Build component for common tasks related to building an Android app
9/// </summary>
10[ParameterPrefix("Android")]
12{
13 /// <summary>
14 /// <para>
15 /// **NUKE PARAMETER**
16 /// </para>
17 /// Specify the full qualified android app name
18 /// </summary>
19 [Parameter]
20 string AppName => TryGetValue(() => AppName) ?? this.GetAppNameFromConfig();
21
22 /// <summary>
23 /// <para>
24 /// **NUKE PARAMETER**
25 /// </para>
26 /// Temporarily override the major JDK version used for Android tasks
27 /// </summary>
28 [Parameter]
29 int? Jdk => TryGetValue<int?>(() => Jdk);
30
31 /// <summary>
32 /// <para>
33 /// **NUKE PARAMETER**
34 /// </para>
35 /// Temporarily override the major Android SDK version used for Android tasks
36 /// </summary>
37 [Parameter]
38 int? Sdk => TryGetValue<int?>(() => Sdk);
39
40 /// <summary>
41 /// <para>
42 /// **NUKE PARAMETER**
43 /// </para>
44 /// Processor architecture of your target hardware
45 /// </summary>
46 [Parameter]
48
49 /// <summary>
50 /// <para>
51 /// **NUKE TARGET**
52 /// </para>
53 /// Clean up the Android folder inside Intermediate
54 /// </summary>
55 Target CleanIntermediateAndroid => _ => _
56 .Description(
57 """
58 |
59 | Clean up the Android folder inside Intermediate
60
61 """
62 )
63 .OnlyWhenStatic(this.IsAndroidPlatform)
64 .DependentFor(Build)
65 .DependentFor<IPackageTargets>(p => p.Package)
66 .Executes(() =>
67 {
68 (ProjectFolder / "Intermediate" / "Android").DeleteDirectory();
69 });
70
71 /// <summary>
72 /// <para>
73 /// **NUKE TARGET**
74 /// </para>
75 /// Sign the output APK
76 /// </summary>
77 Target SignApk => _ => _
78 .Description(
79 """
80 |
81 | Sign the output APK
82
83 """
84 )
85 .OnlyWhenStatic(this.IsAndroidPlatform)
86 .DependsOn(SetupPlatformSdk)
87 .TriggeredBy<IPackageTargets>(p => p.Package)
88 // .Before(InstallOnAndroid, DebugOnAndroid)
89 .After(Build)
90 .Executes(() =>
91 {
92 var androidRuntimeSettings = ReadIniHierarchy("Engine")?["/Script/AndroidRuntimeSettings.AndroidRuntimeSettings"];
93 var keyStore = androidRuntimeSettings?.GetFirst("KeyStore").Value;
94 var password = androidRuntimeSettings?.GetFirst("KeyStorePassword").Value;
95 var keystorePath = ProjectFolder / "Build" / "Android" / keyStore;
96
97 Assert.False(string.IsNullOrWhiteSpace(keyStore), "There was no keystore specified");
98 Assert.True(keystorePath.FileExists(), "Specified keystore was not found");
99
100 if (string.IsNullOrWhiteSpace(password))
101 password = androidRuntimeSettings?.GetFirst("KeyPassword").Value;
102
103 Assert.False(string.IsNullOrWhiteSpace(password), "There was no keystore password specified");
104
105 // save the password in a temporary file so special characters not appreciated by batch will not cause trouble
106 var kspassFile = TemporaryDirectory / "Android" / "kspass";
107 if (!kspassFile.Parent.DirectoryExists())
108 {
109 kspassFile.Parent.CreateDirectory();
110 }
111 kspassFile.WriteAllText(password);
112
113 var sdk = this.GetAndroidSdk();
114 sdk.GetApkSigner(this)(
115 $"sign --ks \"{keystorePath}\" --ks-pass \"file:{kspassFile}\" \"{this.GetApkFile()}\""
116 );
117 });
118}
Target for packaging the current project we're working on.
Target Package
Same as running Package Project from Editor.
Base interface for build components which require an UnrealBuild main class.
AbsolutePath ProjectFolder
Path to folder containing the .project file.
ConfigIni ReadIniHierarchy(string shortName, IniHierarchyLevel lowestLevel=IniHierarchyLevel.Base, IniHierarchyLevel highestLevel=IniHierarchyLevel.Saved, bool considerPlugins=true, IEnumerable< string >? extraConfigSubfolder=null)
Read INI configuration emulating the same hierarchy of importance as Unreal Engine also does.
Build component for common tasks related to building an Android app.