blob: d782e9423468cc97b8f06041a86079153cf8e44a [file] [log] [blame]
qiangchen42f96d52017-08-08 17:08:03 -07001Instruction of Running webrtc_unity_plugin on Android Unity
2
31. On Linux machine, compile target webrtc_unity_plugin.
4 Checkout WebRTC codebase: fetch --no-hooks webrtc_android
5 If you already have a checkout for linux, add target_os=”android into .gclient file.
6 Run gclient sync
7 Run gn args out/Android, and again set target_os=”android in the args.gn
8 Modify file src/build/android/android_only_jni_exports.lst, to expose all functions. Namely, change "global" section to "*", and remove "local" section. Otherwise, Unity C# code will not be able to access the functions defined in the plugin.
9 Run ninja -C out/Android webrtc_unity_plugin
10
112. On Linux machine, compile target libwebrtc_unity under webrtc checkout. This is the java code for webrtc to work on Android.
12
133. Copy libwebrtc_unity.jar and libwebrtc_unity_plugin.so into Unity project folder, under Assets/Plugins/Android folder.
14
154. Rename libwebrtc_unity_plugin.so to libjingle_peerconnection_so.so. Again, this is hacky, and the purpose is to let the java code in libwebrtc.jar to find their JNI implementation. And simultaneously, in your C# wrapper script for the native plugin libjingle_peerconnection_so.so, the dll_path should be set to “jingle_peerconnection_so”.
16
175. In the Unity Main Scenes Start method, write the following code to initialize the Java environment for webrtc (otherwise, webrtc will not be able to access audio device or camera from C++ code):
18
19#if UNITY_ANDROID
20 AndroidJavaClass playerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
21 AndroidJavaObject activity = playerClass.GetStatic<AndroidJavaObject>("currentActivity");
22 AndroidJavaClass webrtcClass = new AndroidJavaClass("org.webrtc.PeerConnectionFactory");
23 if (webrtcClass != null)
24 {
25 webrtcClass.CallStatic("initializeAndroidGlobals", new object[2] { activity, false });
26 }
27#endif
28
296. Compile the unity project into an APK, and decompile the apk using apktool you can download from internet. And copy the AndroidManifest.xml to the Assets/Plugins/Android folder, and add two lines:
30 <uses-permission android:name=”android.permission.RECORD_AUDIO />
31 <uses-permission android:name=”android.permission.CAMERA />
32
33 The purpose of using apktool is to get a well-written android manifest xml file. If you know how to write manifest file from scratch, you can skip using apktool.