Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: webrtc/examples/unityplugin/ANDROID_INSTRUCTION

Issue 2993423002: Update android build instruction for webrtc unity plugin. (Closed)
Patch Set: misc Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 Instruction of Running webrtc_unity_plugin on Android Unity 1 Instruction of Running webrtc_unity_plugin on Android Unity
2 2
3 1. On Linux machine, compile target webrtc_unity_plugin. 3 1. On Linux machine, compile target webrtc_unity_plugin.
4 Checkout WebRTC codebase: fetch --no-hooks webrtc_android 4 Checkout WebRTC codebase: fetch --no-hooks webrtc_android
5 If you already have a checkout for linux, add target_os=”android” into .gclie nt file. 5 If you already have a checkout for linux, add target_os=”android” into .gclie nt file.
6 Run gclient sync 6 Run gclient sync
7 Modify files src/build/android/android_only_jni_exports.lst and src/build/and roid/android_only_explicit_jni_exports.lst to expose all functions. Namely, chan ge "global" section to "*", and remove "local" section. Otherwise, Unity C# code will not be able to access the functions defined in the plugin. If you do this step after you create a build folder, you may have to clean and recreate the bui ld folder.
7 Run gn args out/Android, and again set target_os=”android” in the args.gn 8 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 fun ctions. Namely, change "global" section to "*", and remove "local" section. Othe rwise, Unity C# code will not be able to access the functions defined in the plu gin. 9 Run ninja -C out/Android webrtc_unity_plugin
9 Run ninja -C out/Android webrtc_unity_plugin
10 10
11 2. On Linux machine, compile target libwebrtc_unity under webrtc checkout. This is the java code for webrtc to work on Android. 11 2. On Linux machine, compile target libwebrtc_unity under webrtc checkout. This is the java code for webrtc to work on Android.
12 12
13 3. Copy libwebrtc_unity.jar and libwebrtc_unity_plugin.so into Unity project fol der, under Assets/Plugins/Android folder. 13 3. Copy libwebrtc_unity.jar and libwebrtc_unity_plugin.so into Unity project fol der, under Assets/Plugins/Android folder.
14 14
15 4. Rename libwebrtc_unity_plugin.so to libjingle_peerconnection_so.so. Again, th is is hacky, and the purpose is to let the java code in libwebrtc.jar to find th eir JNI implementation. And simultaneously, in your C# wrapper script for the na tive plugin libjingle_peerconnection_so.so, the dll_path should be set to “jingl e_peerconnection_so”. 15 4. Rename libwebrtc_unity_plugin.so to libjingle_peerconnection_so.so. Again, th is is hacky, and the purpose is to let the java code in libwebrtc.jar to find th eir JNI implementation. And simultaneously, in your C# wrapper script for the na tive plugin libjingle_peerconnection_so.so, the dll_path should be set to “jingl e_peerconnection_so”.
16 16
17 5. In the Unity Main Scene’s Start method, write the following code to initializ e the Java environment for webrtc (otherwise, webrtc will not be able to access audio device or camera from C++ code): 17 5. In the Unity Main Scene’s Start method, write the following code to initializ e the Java environment for webrtc (otherwise, webrtc will not be able to access audio device or camera from C++ code):
18 18
19 #if UNITY_ANDROID 19 #if UNITY_ANDROID
20 AndroidJavaClass playerClass = new AndroidJavaClass("com.unity3d.player. UnityPlayer"); 20 AndroidJavaClass playerClass = new AndroidJavaClass("com.unity3d.player. UnityPlayer");
21 AndroidJavaObject activity = playerClass.GetStatic<AndroidJavaObject>("c urrentActivity"); 21 AndroidJavaObject activity = playerClass.GetStatic<AndroidJavaObject>("c urrentActivity");
22 AndroidJavaClass webrtcClass = new AndroidJavaClass("org.webrtc.PeerConn ectionFactory"); 22 AndroidJavaClass webrtcClass = new AndroidJavaClass("org.webrtc.PeerConn ectionFactory");
23 if (webrtcClass != null) 23 if (webrtcClass != null)
24 { 24 {
25 webrtcClass.CallStatic("initializeAndroidGlobals", new object[2] { a ctivity, false }); 25 webrtcClass.CallStatic("initializeAndroidGlobals", new object[2] { a ctivity, false });
26 } 26 }
27 #endif 27 #endif
28 28
29 6. Compile the unity project into an APK, and decompile the apk using apktool yo u can download from internet. And copy the AndroidManifest.xml to the Assets/Plu gins/Android folder, and add two lines: 29 6. Compile the unity project into an APK, and decompile the apk using apktool th at you can download from https://ibotpeaches.github.io/Apktool/
30 <uses-permission android:name=android.permission.RECORD_AUDIO /> 30 Run apktool d apkname.apk.
31 <uses-permission android:name=android.permission.CAMERA /> 31 Then copy the AndroidManifest.xml in the decompiled folder to the Assets/Plugins /Android folder, and add two lines:
32 <uses-permission android:name="android.permission.RECORD_AUDIO" />
33 <uses-permission android:name="android.permission.CAMERA" />
32 34
33 The purpose of using apktool is to get a well-written android manifest xml fil e. If you know how to write manifest file from scratch, you can skip using apkto ol. 35 The purpose of using apktool is to get a well-written android manifest xml fil e. If you know how to write manifest file from scratch, you can skip using apkto ol.
36
37 7. Compile the unity project into an APK again and deploy it to an android devic e.
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698