webrtc_m130/webrtc/examples/unityplugin/ANDROID_INSTRUCTION
qiangchen 42f96d53f3 Add Android Camera To Unity Plugin
The existing unity plugin (an example in webrtc codebase) does not support camera access on Android platform. This CL implements such functionality.

TBR=gyzhou@chromium.org

BUG=webrtc:8067

Review-Url: https://codereview.webrtc.org/2993273002
Cr-Commit-Position: refs/heads/master@{#19277}
2017-08-09 00:08:03 +00:00

34 lines
2.4 KiB
Plaintext
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
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.
Run ninja -C out/Android webrtc_unity_plugin
2. On Linux machine, compile 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. 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”.
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 webrtcClass = new AndroidJavaClass("org.webrtc.PeerConnectionFactory");
if (webrtcClass != null)
{
webrtcClass.CallStatic("initializeAndroidGlobals", new object[2] { activity, false });
}
#endif
6. 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:
<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.