1
1
using System ;
2
- using System . Diagnostics ;
3
2
using System . IO ;
4
3
using System . Linq ;
5
4
using System . Text . RegularExpressions ;
@@ -14,17 +13,31 @@ public class Build : MonoBehaviour
14
13
15
14
static readonly string apkPath = Path . Combine ( ProjectPath , "Builds/" + Application . productName + ".apk" ) ;
16
15
17
- [ MenuItem ( "Flutter/Export Android %&a" , false , 1 ) ]
18
- public static void DoBuildAndroid ( )
16
+ static readonly string androidExportPath = Path . GetFullPath ( Path . Combine ( ProjectPath , "../../android/UnityExport" ) ) ;
17
+ static readonly string iosExportPath = Path . GetFullPath ( Path . Combine ( ProjectPath , "../../ios/UnityExport" ) ) ;
18
+
19
+ [ MenuItem ( "Flutter/Export Android (Unity 2019.3.*) %&n" , false , 1 ) ]
20
+ public static void DoBuildAndroidLibrary ( )
21
+ {
22
+ DoBuildAndroid ( Path . Combine ( apkPath , "unityLibrary" ) ) ;
23
+
24
+ // Copy over resources from the launcher module that are used by the library
25
+ Copy ( Path . Combine ( apkPath + "/launcher/src/main/res" ) , Path . Combine ( androidExportPath , "src/main/res" ) ) ;
26
+ }
27
+
28
+ [ MenuItem ( "Flutter/Export Android %&a" , false , 2 ) ]
29
+ public static void DoBuildAndroidLegacy ( )
19
30
{
20
- string buildPath = Path . Combine ( apkPath , Application . productName ) ;
21
- string exportPath = Path . GetFullPath ( Path . Combine ( ProjectPath , "../../android/UnityExport" ) ) ;
31
+ DoBuildAndroid ( Path . Combine ( apkPath , Application . productName ) ) ;
32
+ }
22
33
34
+ public static void DoBuildAndroid ( String buildPath )
35
+ {
23
36
if ( Directory . Exists ( apkPath ) )
24
37
Directory . Delete ( apkPath , true ) ;
25
38
26
- if ( Directory . Exists ( exportPath ) )
27
- Directory . Delete ( exportPath , true ) ;
39
+ if ( Directory . Exists ( androidExportPath ) )
40
+ Directory . Delete ( androidExportPath , true ) ;
28
41
29
42
EditorUserBuildSettings . androidBuildSystem = AndroidBuildSystem . Gradle ;
30
43
@@ -39,38 +52,37 @@ public static void DoBuildAndroid()
39
52
if ( report . summary . result != BuildResult . Succeeded )
40
53
throw new Exception ( "Build failed" ) ;
41
54
42
- Copy ( buildPath , exportPath ) ;
55
+ Copy ( buildPath , androidExportPath ) ;
43
56
44
57
// Modify build.gradle
45
- var build_file = Path . Combine ( exportPath , "build.gradle" ) ;
58
+ var build_file = Path . Combine ( androidExportPath , "build.gradle" ) ;
46
59
var build_text = File . ReadAllText ( build_file ) ;
47
60
build_text = build_text . Replace ( "com.android.application" , "com.android.library" ) ;
61
+ build_text = build_text . Replace ( "implementation fileTree(dir: 'libs', include: ['*.jar'])" , "implementation project(':unity-classes')" ) ;
48
62
build_text = Regex . Replace ( build_text , @"\n.*applicationId '.+'.*\n" , "\n " ) ;
49
63
File . WriteAllText ( build_file , build_text ) ;
50
64
51
65
// Modify AndroidManifest.xml
52
- var manifest_file = Path . Combine ( exportPath , "src/main/AndroidManifest.xml" ) ;
66
+ var manifest_file = Path . Combine ( androidExportPath , "src/main/AndroidManifest.xml" ) ;
53
67
var manifest_text = File . ReadAllText ( manifest_file ) ;
54
68
manifest_text = Regex . Replace ( manifest_text , @"<application .*>" , "<application>" ) ;
55
69
Regex regex = new Regex ( @"<activity.*>(\s|\S)+?</activity>" , RegexOptions . Multiline ) ;
56
70
manifest_text = regex . Replace ( manifest_text , "" ) ;
57
71
File . WriteAllText ( manifest_file , manifest_text ) ;
58
72
}
59
73
60
- [ MenuItem ( "Flutter/Export IOS %&i" , false , 2 ) ]
74
+ [ MenuItem ( "Flutter/Export IOS (Unity 2019.3.*) %&i" , false , 3 ) ]
61
75
public static void DoBuildIOS ( )
62
76
{
63
- string exportPath = Path . GetFullPath ( Path . Combine ( ProjectPath , "../../ios/UnityExport" ) ) ;
64
-
65
- if ( Directory . Exists ( exportPath ) )
66
- Directory . Delete ( exportPath , true ) ;
77
+ if ( Directory . Exists ( iosExportPath ) )
78
+ Directory . Delete ( iosExportPath , true ) ;
67
79
68
80
EditorUserBuildSettings . iOSBuildConfigType = iOSBuildType . Release ;
69
81
70
82
var options = BuildOptions . AcceptExternalModificationsToPlayer ;
71
83
var report = BuildPipeline . BuildPlayer (
72
84
GetEnabledScenes ( ) ,
73
- exportPath ,
85
+ iosExportPath ,
74
86
BuildTarget . iOS ,
75
87
options
76
88
) ;
0 commit comments