blob: f0149eb953e3e95a2be3af26a7e668557b3add5c [file] [log] [blame]
George Zhou2770c3d2018-03-07 09:58:54 -08001Instruction of running webrtc_unity_plugin on Android Unity
qiangchen42f96d52017-08-08 17:08:03 -07002
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
gyzhou3abb7382017-08-10 16:31:22 -07008 Run ninja -C out/Android webrtc_unity_plugin
qiangchen42f96d52017-08-08 17:08:03 -07009
George Zhou2770c3d2018-03-07 09:58:54 -0800102. On Linux machine, build target libwebrtc_unity under webrtc checkout. This is the java code for webrtc to work on Android.
qiangchen42f96d52017-08-08 17:08:03 -070011
123. Copy libwebrtc_unity.jar and libwebrtc_unity_plugin.so into Unity project folder, under Assets/Plugins/Android folder.
13
George Zhou2770c3d2018-03-07 09:58:54 -0800144. Rename libwebrtc_unity_plugin.so to libjingle_peerconnection_so.so. This is hacky, and the purpose is to let the java code in libwebrtc_unity.jar to find their JNI implementations. Simultaneously, in your C# wrapper script for the native plugin libjingle_peerconnection_so.so, the dll_path should be set to “jingle_peerconnection_so”.
qiangchen42f96d52017-08-08 17:08:03 -070015
165. 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):
17
18#if UNITY_ANDROID
George Zhou2770c3d2018-03-07 09:58:54 -080019 AndroidJavaClass playerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
20 AndroidJavaObject activity = playerClass.GetStatic<AndroidJavaObject>("currentActivity");
21 AndroidJavaClass utilityClass = new AndroidJavaClass("org.webrtc.UnityUtility");
22 utilityClass.CallStatic("InitializePeerConncectionFactory", new object[1] { activity });
qiangchen42f96d52017-08-08 17:08:03 -070023#endif
24
gyzhou3abb7382017-08-10 16:31:22 -0700256. Compile the unity project into an APK, and decompile the apk using apktool that you can download from https://ibotpeaches.github.io/Apktool/
26 Run apktool d apkname.apk.
27Then copy the AndroidManifest.xml in the decompiled folder to the Assets/Plugins/Android folder, and add two lines:
28 <uses-permission android:name="android.permission.RECORD_AUDIO" />
29 <uses-permission android:name="android.permission.CAMERA" />
qiangchen42f96d52017-08-08 17:08:03 -070030
George Zhou2770c3d2018-03-07 09:58:54 -080031The 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.
gyzhou3abb7382017-08-10 16:31:22 -070032
337. Compile the unity project into an APK again and deploy it to an android device.