We recommend you run the SDK on Android 5.0 (API level 21) or later.
Below are the environment requirements for SDK development. You don't need to meet the same requirements for application development, but make sure that your application is compatible with the SDK.
build.gradle
in the App
directory of the project:dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// Import the SDK AAR file. Replace `x.y.zzzz` in `LiteAVSDK_UGC_x.y.zzzz` with the latest version number.
compile(name: 'LiteAVSDK_UGC_10.7.1136', ext: 'aar')
...
}
build.gradle
in the project directory, add flatDir
to specify the local repository:allprojects {
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
}
defaultConfig
in build.gradle
in the App
directory of the project:defaultConfig {
...
ndk {
abiFilters "armeabi-v7a", "arm64-v8a"
}
}
Configure application permissions in AndroidManifest.xml
. Audio/Video applications generally need the following permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.Camera"/>
<uses-feature android:name="android.hardware.camera.autofocus" />
- Application onCreate()
:public class DemoApplication extends Application {
String ugcLicenceUrl = ""; // Enter the license URL obtained from the console.
String ugcKey = ""; // Enter the license key obtained from the console.
@Override
public void onCreate() {
super.onCreate();
TXUGCBase.getInstance().setLicence(instance, ugcLicenceUrl, ugcKey);
}
}
Note:If you use a license for the SDK on v4.7 and have upgraded the SDK to v4.9, you can click Switch to New License in the console to generate a new license key and URL. A new license can be used only for the SDK on v4.9 or later and should be configured as described above.
You can enable/disable console log printing and set the log level in TXLiveBase
. See the sample code below.
TXLiveBase.setConsoleEnabled(true);
TXLiveBase.setLogLevel(TXLiveConstants.LOG_LEVEL_DEBUG);
Call an SDK API in your project to get the SDK version number and verify whether your project is correctly configured.
Import the SDK:
Import the SDK class in MainActivity.java
:
import com.tencent.rtmp.TXLiveBase;
Call the API:
Call getSDKVersioin
in onCreate
to get the version number:
String sdkver = TXLiveBase.getSDKVersionStr();
Log.d("liteavsdk", "liteav sdk version is : " + sdkver);
Build and run the project:
If the above steps are performed correctly, you will build the project successfully and, after running it, you will see the following log information in logcat
.09-26 19:30:36.547 19577-19577/ D/liteavsdk: liteav sdk version is : 7.4.9211
After importing the UGSV SDK, when you build and run your project, if the following error occurs:
Caused by: android.view.InflateException:
Binary XML file #14:Error inflating class com.tencent.rtmp.ui.TXCloudVideoView
Follow the steps below to troubleshoot the problem:
Check whether you have copied the JAR and SO files to the jniLibs
directory.
If you use the full edition integrated with the .aar file, check whether the .so libraries for the x64 architecture are filtered out in defaultConfig
in build.gradle
in the project directory.
defaultConfig {
...
ndk {
abiFilters "armeabi-v7a", "arm64-v8a"
}
}
Check if the package name of the SDK has been added to the "do not obfuscate" list.
-keep class com.tencent.** { *;}
Configure packaging options for your application.
This section describes how to quickly integrate the UGSV SDK into your existing project to implement a complete range of short video features including shooting, editing, and composition. The code and resources mentioned in this section can be found in the SDK ZIP file as described in SDK Download and the UGSV demo.
UGCKit
Create a project (empty activity)
Create an empty Android Studio project. You can name it ugc
and give it a custom package name. Make sure the project can be built and run successfully.
Configure build.gradle
of the project.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
# Copying starts.
classpath 'com.android.tools.build:gradle:3.6.1'
# Copying ends.
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
# Copying starts.
flatDir {
dirs 'src/main/jniLibs'
dirs project(':ugckit').file('libs')
}
# Copying ends.
jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
# Copying starts.
ext {
compileSdkVersion = 29
buildToolsVersion = "29.0.2"
supportSdkVersion = "26.1.0"
minSdkVersion = 21
targetSdkVersion = 26
versionCode = 1
versionName = "v1.1"
proguard = true
rootPrj = "$projectDir/.."
ndkAbi = 'armeabi-v7a'
liteavSdk = "com.tencent.liteav:LiteAVSDK_UGC:latest.release"
}
# Copying ends.
Configure build.gradle
of your application.
plugins {
id 'com.android.application'
}
android {
# Copying starts.
compileSdkVersion = rootProject.ext.compileSdkVersion
buildToolsVersion = rootProject.ext.buildToolsVersion
# Copying ends.
defaultConfig {
applicationId "com.yunxiao.dev.liteavdemo"
# Copying starts.
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
renderscriptTargetApi = 19
renderscriptSupportModeEnabled = true
multiDexEnabled = true
ndk {
abiFilters rootProject.ext.ndkAbi
}
# Copying ends.
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
# Copying starts.
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.google.code.gson:gson:2.3.1'
implementation 'com.tencent.rqd:crashreport:3.4.4'
implementation 'com.tencent.rqd:nativecrashreport:3.9.2'
implementation 'com.github.castorflex.verticalviewpager:library:19.0.1'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation rootProject.ext.liteavSdk
implementation project(':ugckit')
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation('com.blankj:utilcode:1.25.9', {
exclude group: 'com.google.code.gson', module: 'gson'
})
# Copying ends.
}
Specify the Gradle version.
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip
Copy the ugckit
module to the ugc
directory of your newly created project.
To integrate basic beauty filters, copy the beautysettingkit
module to the ugc
directory of the project.
To integrate the Tencent Effect SDK, copy the xmagickit
module to the ugc
directory of the project. For more information, see SDK Integration Guide (Android).
Import ugckit
to settings.gradle
of the project.
In UGC/settings.gradle
of the project, import the modules below:
include ':ugckit'
include ':beautysettingkit'
include ':xmagickit'
Add ugckit
as a dependency for the app modules of your project.
implementation project(':ugckit')
Apply for a license
You need to set the license first before using UGCKit
.
Set the license and initialize UGCKit
Set the license and initialize UGCKit
as early as possible before using UGSV features.
// Configure the license
TXUGCBase.getInstance().setLicence(this, ugcLicenceUrl, ugcKey);
// Initialize `UGCKit`
UGCKit.init(this);
Create an XML file for shooting and add the code below:
<com.tencent.qcloud.ugckit.UGCKitVideoRecord
android:id="@+id/video_record_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Create an empty theme for shooting in res/values/styles.xml
and inherit the default shooting theme of UGCKit
.
<style name="RecordActivityTheme" parent="UGCKitRecordStyle"/>
Create an activity for shooting, inherit FragmentActivity
, implement the ActivityCompat.OnRequestPermissionsResultCallback
API, get a UGCKitVideoRecord
object, and set the callback.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// You must configure the theme in the code (`setTheme`) or in `AndroidManifest` (android:theme).
setTheme(R.style.RecordActivityTheme);
setContentView(R.layout.activity_video_record);
// Get `UGCKitVideoRecord`
mUGCKitVideoRecord = (UGCKitVideoRecord) findViewById(R.id.video_record_layout);
// Listen for shooting events
mUGCKitVideoRecord.setOnRecordListener(new IVideoRecordKit.OnRecordListener() {
@Override
public void onRecordCanceled() {
// Shooting was canceled.
}
@Override
public void onRecordCompleted(UGCKitResult result) {
// Callback for ending shooting
}
});
}
@Override
protected void onStart() {
super.onStart();
// Get whether the camera and audio recording permissions are granted. For details, see `Github/Demo`.
if (hasPermission()) {
// `UGCKit` takes over the shooting lifecycle. For details, see `Github/Demo`.
mUGCKitVideoRecord.start();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (grantResults != null && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
mUGCKitVideoRecord.start();
}
}
The UI view looks like this:
3. Implement video import
Create an XML file and add the code below:
<com.tencent.qcloud.ugckit.UGCKitVideoPicker
android:id="@+id/video_picker"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Create an empty theme in res/values/styles.xml
and inherit the default video importing theme of UGCKit
.
<style name="PickerActivityTheme" parent="UGCKitPickerStyle"/>
Activity
, get a UGCKitVideoPicker
object, and set the callback.@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// You must configure the theme in the code (`setTheme`) or in `AndroidManifest` (android:theme).
setTheme(R.style.PickerActivityTheme);
setContentView(R.layout.activity_video_picker);
// Get `UGCKitVideoPicker`
mUGCKitVideoPicker = (UGCKitVideoPicker) findViewById(R.id.video_picker);
// Listen for video importing events
mUGCKitVideoPicker.setOnPickerListener(new IPickerLayout.OnPickerListener() {
@Override
public void onPickedList(ArrayList<TCVideoFileInfo> list) {
// `UGCKit` returns the paths of selected videos.
}
});
}
The UI view looks like this:
4. Implement video clipping
<com.tencent.qcloud.ugckit.UGCKitVideoCut
android:id="@+id/video_cutter"
android:layout_width="match_parent"
android:layout_height="match_parent" />
res/values/styles.xml
and inherit the default video editing theme of UGCKit
.<style name="EditerActivityTheme" parent="UGCKitEditerStyle"/>
FragmentActivity
API, get a UGCKitVideoCut
object, and set the callback.@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// You must configure the theme in the code (`setTheme`) or in `AndroidManifest` (android:theme).
setTheme(R.style.EditerActivityTheme);
setContentView(R.layout.activity_video_cut);
mUGCKitVideoCut = (UGCKitVideoCut) findViewById(R.id.video_cutter);
// Get the paths of videos imported via the previous view
mVideoPath = getIntent().getStringExtra(UGCKitConstants.VIDEO_PATH);
// `UGCKit` sets the video path.
mUGCKitVideoCut.setVideoPath(mVideoPath);
// Listen for the generation of videos
mUGCKitVideoCut.setOnCutListener(new IVideoCutKit.OnCutListener() {
@Override
public void onCutterCompleted(UGCKitResult ugcKitResult) {
// Callback for the completion of video clipping
}
@Override
public void onCutterCanceled() {
// Callback for clipping being canceled
}
});
}
@Override
protected void onResume() {
super.onResume();
// `UGCKit` takes over the lifecycle of the video clipping view. For details, see `Github/Demo`.
mUGCKitVideoCut.startPlay();
}
The UI view looks like this:
5. Implement video special effect editing
<com.tencent.qcloud.ugckit.UGCKitVideoEdit
android:id="@+id/video_edit"
android:layout_width="match_parent"
android:layout_height="match_parent" />
FragmentActivity
, get a UGCKitVideoEdit
object, and set the callback.@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// You must configure the theme in the code (`setTheme`) or in `AndroidManifest` (android:theme).
setTheme(R.style.EditerActivityTheme);
setContentView(R.layout.activity_video_editer);
// Set the video path (optional). You can skip this if the previous view is video clipping and `setVideoEditFlag(true)` is called.
mVideoPath = getIntent().getStringExtra(UGCKitConstants.VIDEO_PATH);
mUGCKitVideoEdit = (UGCKitVideoEdit) findViewById(R.id.video_edit);
if (!TextUtils.isEmpty(mVideoPath)) {
mUGCKitVideoEdit.setVideoPath(mVideoPath);
}
// Initialize the player
mUGCKitVideoEdit.initPlayer();
mUGCKitVideoEdit.setOnVideoEditListener(new IVideoEditKit.OnEditListener() {
@Override
public void onEditCompleted(UGCKitResult ugcKitResult) {
// Video editing completed.
}
@Override
public void onEditCanceled() {
}
});
}
@Override
protected void onResume() {
super.onResume();
// `UGCKit` takes over the lifecycle of the editing view. For details, see `Github/Demo`.
mUGCKitVideoEdit.start();
}
The UI view looks like this:
See the documents below for a detailed description of different UGSV modules.
The latest version of UGCKit
uses AndroidX. If you still use UGCKit
based on the Android Support Library, you can update it to the latest version or switch to AndroidX as follows. Here, UGSVSDK
is used as an example, which also uses the UGCKit
module in its demo.
compileSdkVersion
to 28 or later.buildToolsVersion
to 28.0.2 or later.UGCKit
build version error occurs?Error message:
ERROR: Unable to find method 'org.gradle.api.tasks.compile.CompileOptions.setBootClasspath(Ljava/lang/String;)V'.
Possible causes for this unexpected error include:
Cause: The problem occurs because the version of the Gradle plugin used for UGCKit
is v2.2.3, but that of Gradle is v3.3.
Solution: Check whether the versions of Android Studio Gradle
and Gradle match. For details, see Update the Android Gradle plugin.
UGCKit
?renderscript-v8.jar
is missing from the ugckit
module. renderscript-v8.jar
is responsible for image processing, blurring, and rendering.ugckit
module and add renderscript-v8.jar
, which you can find in \sdk\build-tools\
, to the folder.
Was this page helpful?