Start an Android Project
To start a LiveSwitch Android project, do the following:
Create a new Android Studio project.
In the
app
folder, create alibs
folder.Add the following
jar
files to your project to provide your app with the minimum set of Opus and VPX capabilities:fm.liveswitch.jar
fm.liveswitch.opus.jar
fm.liveswitch.vpx.jar
fm.liveswitch.yuv.jar
To enable H.264 support for your app, add
fm.liveswitch.openh264.jar
to thelibs
folder.To capture audio and video data from the user, add
fm.liveswitch.android.jar
to thelibs
folder.Add architecture-specific native libraries to your Android project's
app/src/main
folder. These libraries are in theAndroid/Libraries/jniLibs/arm64-v8a
,Android/Libraries/jniLibs/armebi-v7a
andAndroid/Libraries/jniLibs/x86
folders. Do the following:- If you are using
fm.liveswitch.audioprocessing.jar
, addlibaudioprocessingfmJNI.so
. - If you are using
fm.liveswitch.openh264.jar
, addlibopenh264fmJNI.so
. - If you are using
fm.liveswitch.opus.jar
, addlibopusfmJNI.so
. - If you are using
fm.liveswitch.vpx.jar
, addlibvpxfmJNI.so
. - If you are using
fm.liveswitch.yuv.jar
, addlibyuvfmJNI.so
.
Tip
If you want to be safe, add the entire
jniLibs
folder into your project directory. This ensures that you have the correct native libraries for any app.- If you are using
In your project non-source files, open
app/build.gradle
.In
app/build.gradle
, add the following to the end of theandroid
block:packagingOptions { exclude 'lib/linux_armv7/*' exclude 'lib/linux_armv8/*' exclude 'lib/linux_arm64/*' exclude 'lib/linux_x64/*' exclude 'lib/linux_x86/*' exclude '**/libaudioprocessingfm.so' exclude '**/libopenh264fm.so' exclude '**/libopusfm.so' exclude '**/libvpxfm.so' exclude '**/libyuvfm.so' } sourceSets { main { jniLibs { srcDirs = [ 'src/main/jniLibs' ] } } } lintOptions { abortOnError false }
In
app/build.gradle
, add the following to thedependencies
block:implementation fileTree(include: ['*.jar'], dir: '../lib')
Resync your Gradle project.
Work With ProGuard
If you are using ProGuard, you must specify some additional configuration settings so that ProGuard correctly shrinks your code. ProGuard is a code-shrinking tool that is available in Android SDK Tools 25.0.10 or newer. In your ProGuard configuration file, add the following rules:
-keep public class fm.liveswitch.audioprocessing.** { *; }
-keep public class fm.liveswitch.openh264.** { *; }
-keep public class fm.liveswitch.opus.** { *; }
-keep public class fm.liveswitch.vpx.** { *; }
-keep public class fm.liveswitch.yuv.** { *; }
If you are using ProGuard and your app calls a method from the Java Native Interface (that is, it uses any of the native libraries noted above), then you cannot minify your APK builds as ProGuard incorrectly removes this code.
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
Disable Instant Run
You should disable Instant Run in Android Studio.
When Instant Run is enabled in Android Studio, it might result in severe audio and video performance problems on some development machines. For more information, see https://stackoverflow.com/questions/35168753/instant-run-in-android-studio-2-0-how-to-turn-off
Permissions
You must add the following permissions to your manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<!-- largeHeap is necessary to avoid OOM errors on older devices -->
<application android:label="..." android:theme="..." android:name="android.support.multidex.MultiDexApplication" android:largeHeap="true"></application>