Skip to content

Commit

Permalink
added UnityWebViewPostprocessBuild.cs for Android.
Browse files Browse the repository at this point in the history
  • Loading branch information
KojiNakamaru committed Jan 6, 2017
1 parent 922188b commit 35507a3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/Rakefile
Expand Up @@ -36,6 +36,7 @@ SRCS[0]=%W|
WebViewObject.cs
iOS/WebView.mm
iOS/Editor/UnityWebViewPostprocessBuild.cs
Android/Editor/UnityWebViewPostprocessBuild.cs
|

# NOTE: WebPlayerTemplates is not inclued for now because the sample app becomes complicated.
Expand Down
51 changes: 51 additions & 0 deletions plugins/Android/Editor/UnityWebViewPostprocessBuild.cs
@@ -0,0 +1,51 @@
#if UNITY_ANDROID
using System.Collections;
using System.IO;
using System.Xml;
using UnityEditor.Callbacks;
using UnityEditor;
using UnityEngine;

public class UnityWebViewPostprocessBuild {
// you need to modify ACTIVITY_NAME if you utilize any custom activty.
private const string ACTIVITY_NAME = "com.unity3d.player.UnityPlayerActivity";

[PostProcessBuild(100)]
public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
if (buildTarget == BuildTarget.Android) {
string manifest = Path.Combine(Application.dataPath, "Plugins/Android/AndroidManifest.xml");
if (!File.Exists(manifest)) {
string manifest0 = Path.Combine(Application.dataPath, "../Temp/StagingArea/AndroidManifest-main.xml");
if (!File.Exists(manifest0)) {
Debug.LogError("cannot find both Assets/Plugins/Android/AndroidManifest.xml and Temp/StagingArea/AndroidManifest-main.xml. please build the app to generate Assets/Plugins/Android/AndroidManifest.xml and then rebuild it again.");
return;
} else {
File.Copy(manifest0, manifest);
}
}
XmlDocument doc = new XmlDocument();
doc.Load(manifest);
XmlElement activity = null;
// Let's find the application node.
foreach (XmlNode node0 in doc.DocumentElement.ChildNodes) {
if (node0.Name == "application") {
foreach (XmlNode node1 in node0.ChildNodes) {
if (node1.Name == "activity"
&& ((XmlElement)node1).GetAttribute("android:name") == ACTIVITY_NAME) {
activity = (XmlElement)node1;
break;
}
}
break;
}
}
if (activity != null
&& string.IsNullOrEmpty(activity.GetAttribute("android:hardwareAccelerated"))) {
activity.SetAttribute("hardwareAccelerated", "http://schemas.android.com/apk/res/android", "true");
doc.Save(manifest);
Debug.LogError("adjusted AndroidManifest.xml about android:hardwareAccelerated. Please rebuild the app.");
}
}
}
}
#endif

0 comments on commit 35507a3

Please sign in to comment.