webrtc/examples/unityplugin/ANDROID_INSTRUCTION
George Zhou 2770c3df91 Synced webrtc_unity_plugin to the latest webrtc and fixed bugs.
1, Let targets libwebrtc_unity and webrtc_unity_plugin built with Ninja -C out/***.
2, Fixed compile issue of libwebrtc_unity.
3, Built libwebrtc_unity classes into Java 7 instead of Java 8 for android.
4, Added an interface to enable peerconnectionFactory for android in Unity.

Bug: webrtc:8986
Change-Id: I2a206a77ab38895ec9ac845ce89507d61076d396
Reviewed-on: https://webrtc-review.googlesource.com/59000
Reviewed-by: Qiang Chen <qiangchen@chromium.org>
Commit-Queue: George Zhou <gyzhou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#22373}
2018-03-09 18:34:14 +00:00

33 lines
2.2 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Instruction of running webrtc_unity_plugin on Android Unity
1. On Linux machine, compile target webrtc_unity_plugin.
Checkout WebRTC codebase: fetch --no-hooks webrtc_android
If you already have a checkout for linux, add target_os=”android” into .gclient file.
Run gclient sync
Run gn args out/Android, and again set target_os=”android” in the args.gn
Run ninja -C out/Android webrtc_unity_plugin
2. On Linux machine, build target libwebrtc_unity under webrtc checkout. This is the java code for webrtc to work on Android.
3. Copy libwebrtc_unity.jar and libwebrtc_unity_plugin.so into Unity project folder, under Assets/Plugins/Android folder.
4. 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”.
5. 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):
#if UNITY_ANDROID
AndroidJavaClass playerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = playerClass.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaClass utilityClass = new AndroidJavaClass("org.webrtc.UnityUtility");
utilityClass.CallStatic("InitializePeerConncectionFactory", new object[1] { activity });
#endif
6. Compile the unity project into an APK, and decompile the apk using apktool that you can download from https://ibotpeaches.github.io/Apktool/
Run apktool d apkname.apk.
Then copy the AndroidManifest.xml in the decompiled folder to the Assets/Plugins/Android folder, and add two lines:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
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.
7. Compile the unity project into an APK again and deploy it to an android device.