[*] android开发环境配置完成
This commit is contained in:
@@ -1,12 +1,44 @@
|
||||
# 安卓终端
|
||||
|
||||
注意:功能还没完成
|
||||
|
||||
## C++终端
|
||||
|
||||
* [libmediasoupclient源码](https://github.com/versatica/libmediasoupclient)
|
||||
* [libmediasoupclient文档](https://mediasoup.org/documentation/v3/libmediasoupclient)
|
||||
* [libmediasoupclient接口](https://mediasoup.org/documentation/v3/libmediasoupclient/api)
|
||||
|
||||
## 项目配置
|
||||
|
||||
可以自己编译`WebRTC`依赖或者下载已有依赖,
|
||||
项目导入以后拷贝`libmediasoupclient`源码还有`WebRTC`头文件和二进制文件到`deps`目录。
|
||||
|
||||
[WebRTC](https://pan.baidu.com/s/1E_DXv32D9ODyj5J-o-ji_g?pwd=hudc)
|
||||
|
||||
> 注意删除目录`src/build/linux`和`third_party`目录中除了`abseil-cpp`以外的所有依赖(当然不删也没关系就是文件太多编译器会变慢)
|
||||
|
||||
## 学习资料
|
||||
|
||||
https://developer.android.google.cn/docs?hl=zh-cn
|
||||
https://developer.android.google.cn/guide?hl=zh-cn
|
||||
|
||||
## 依赖编译
|
||||
|
||||
https://webrtc.github.io/webrtc-org/native-code/android/
|
||||
https://webrtc.github.io/webrtc-org/native-code/development/
|
||||
https://webrtc.github.io/webrtc-org/native-code/development/prerequisite-sw/
|
||||
https://www.chromium.org/developers/how-tos/install-depot-tools/
|
||||
https://mediasoup.org/documentation/v3/libmediasoupclient/installation/
|
||||
|
||||
## 参考项目
|
||||
|
||||
https://github.com/haiyangwu/webrtc-android-build
|
||||
https://github.com/haiyangwu/mediasoup-demo-android
|
||||
https://github.com/haiyangwu/mediasoup-client-android
|
||||
|
||||
## 其他依赖
|
||||
|
||||
其他一些框架:
|
||||
|
||||
* `org.webrtc:google-webrtc`
|
||||
* `io.github.haiyangwu:mediasoup-client`
|
||||
|
||||
2
taoyao-client-android/taoyao/.gitignore
vendored
2
taoyao-client-android/taoyao/.gitignore
vendored
@@ -5,3 +5,5 @@ local.properties
|
||||
**/.gradle
|
||||
|
||||
**/build
|
||||
|
||||
mediasoup/deps
|
||||
@@ -10,6 +10,8 @@ android {
|
||||
targetSdk 32
|
||||
versionCode 100
|
||||
versionName "1.0.0"
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
@@ -17,9 +19,6 @@ android {
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
@@ -30,4 +29,6 @@ dependencies {
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2'
|
||||
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.2'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
-optimizationpasses 5
|
||||
@@ -12,14 +12,6 @@ android {
|
||||
versionName "1.0.0"
|
||||
applicationId "com.acgist.taoyao.client"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
cFlags '-std=c17'
|
||||
cppFlags '-std=c++17'
|
||||
// CPU架构:x86_64、x86、armeabi-v7a、arm64-v8a
|
||||
abiFilters 'arm64-v8a'
|
||||
}
|
||||
}
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
@@ -34,17 +26,11 @@ android {
|
||||
sourceCompatibility JavaVersion.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
}
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path file('src/main/cpp/CMakeLists.txt')
|
||||
version '3.22.1'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(path: ':boot')
|
||||
implementation fileTree(dir: 'libs', include: ['*.so', '*.jar'])
|
||||
implementation project(path: ':mediasoup')
|
||||
implementation 'androidx.appcompat:appcompat:1.4.1'
|
||||
implementation 'com.google.android.material:material:1.5.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
-optimizationpasses 5
|
||||
@@ -10,15 +10,15 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.Taoyao">
|
||||
<service
|
||||
android:name=".client.MediaService"
|
||||
android:name=".MediaService"
|
||||
android:enabled="true"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".client.SettingsActivity"
|
||||
android:name=".SettingsActivity"
|
||||
android:exported="false"
|
||||
android:label="@string/title_activity_settings" />
|
||||
<activity
|
||||
android:name=".client.MainActivity"
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.22.1)
|
||||
|
||||
project(taoyao VERSION 1.0.0 LANGUAGES C CXX)
|
||||
|
||||
# Debug | Release
|
||||
# DCMAKE_BUILD_TYPE=Debug
|
||||
# set(CMAKE_BUILD_TYPE Debug)
|
||||
|
||||
# C编译选项
|
||||
set(CMAKE_C_STANDARD 17)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c17 -O3")
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -std=c17 -O0 -g")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -std=c17 -O3")
|
||||
|
||||
# C++编译选项
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O3")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++17 -O0 -g")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++17 -O3")
|
||||
|
||||
# 输出目录
|
||||
# set(PROJECT_BINARY_DIR ${PROJECT_SOURCE_DIR}/build)
|
||||
|
||||
file(
|
||||
GLOB SOURCE_FILE
|
||||
"main.hpp"
|
||||
"include/*.hpp"
|
||||
"mediasoup/*.hpp"
|
||||
"main.cpp"
|
||||
"media/*.cpp"
|
||||
)
|
||||
|
||||
add_library(taoyao SHARED ${SOURCE_FILE})
|
||||
find_library(
|
||||
log-lib
|
||||
log
|
||||
)
|
||||
target_link_libraries(
|
||||
taoyao
|
||||
${log-lib}
|
||||
)
|
||||
|
||||
# 配置
|
||||
# cmake -B build
|
||||
# Windows:cmake -B build -G "Unix Makefiles"
|
||||
# 编译
|
||||
# cmake --build build
|
||||
# 标准线程:-lpthread
|
||||
@@ -1,10 +0,0 @@
|
||||
#include <jni.h>
|
||||
#include <string>
|
||||
|
||||
extern "C" JNIEXPORT jstring JNICALL
|
||||
Java_com_acgist_taoyao_MainActivity_stringFromJNI(
|
||||
JNIEnv* env,
|
||||
jobject /* this */) {
|
||||
std::string hello = "Hello from C++";
|
||||
return env->NewStringUTF(hello.c_str());
|
||||
}
|
||||
0
taoyao-client-android/taoyao/mediasoup/.gitignore
vendored
Normal file
0
taoyao-client-android/taoyao/mediasoup/.gitignore
vendored
Normal file
76
taoyao-client-android/taoyao/mediasoup/CMakeLists.txt
Normal file
76
taoyao-client-android/taoyao/mediasoup/CMakeLists.txt
Normal file
@@ -0,0 +1,76 @@
|
||||
cmake_minimum_required(VERSION 3.22.1)
|
||||
|
||||
project(taoyao VERSION 1.0.0 LANGUAGES C CXX)
|
||||
|
||||
# Debug | Release
|
||||
# -DCMAKE_BUILD_TYPE=Debug
|
||||
# set(CMAKE_BUILD_TYPE Debug)
|
||||
|
||||
# C编译选项
|
||||
#set(CMAKE_C_STANDARD 17)
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c17 -O3")
|
||||
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -std=c17 -O0 -g")
|
||||
#set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -std=c17 -O3")
|
||||
|
||||
# C++编译选项
|
||||
#set(CMAKE_CXX_STANDARD 17)
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O3")
|
||||
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++17 -O0 -g")
|
||||
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++17 -O3")
|
||||
|
||||
set(
|
||||
SOURCE_DIR
|
||||
src/main/cpp/
|
||||
)
|
||||
|
||||
set(
|
||||
SOURCE_FILES
|
||||
${SOURCE_DIR}/main.hpp
|
||||
${SOURCE_DIR}/main.cpp
|
||||
)
|
||||
|
||||
set(LIBWEBRTC_BINARY_PATH ${LIBWEBRTC_BINARY_PATH}/${ANDROID_ABI} CACHE STRING "libwebrtc binary path" FORCE)
|
||||
|
||||
if (${MEDIASOUPCLIENT_LOG_TRACE})
|
||||
target_compile_definitions(
|
||||
${PROJECT_NAME} PRIVATE MSC_LOG_TRACE=1
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (${MEDIASOUPCLIENT_LOG_DEV})
|
||||
target_compile_definitions(
|
||||
${PROJECT_NAME} PRIVATE MSC_LOG_DEV=1
|
||||
)
|
||||
endif ()
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
|
||||
|
||||
add_subdirectory("deps/libmediasoupclient")
|
||||
|
||||
set_source_files_properties(
|
||||
${SOURCE_FILES} PROPERTIES COMPILE_FLAGS -Wall -Wextra -Wpedantic
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
${PROJECT_NAME} PUBLIC
|
||||
"${SOURCE_DIR}/include"
|
||||
"${PROJECT_SOURCE_DIR}/deps/libmediasoupclient/include"
|
||||
"${PROJECT_SOURCE_DIR}/deps/libmediasoupclient/deps/libsdptransform/include"
|
||||
)
|
||||
|
||||
target_compile_definitions(
|
||||
${PROJECT_NAME} PUBLIC
|
||||
$<$<NOT:$<PLATFORM_ID:Windows>>:WEBRTC_POSIX>
|
||||
$<$<PLATFORM_ID:Darwin>:WEBRTC_MAC>
|
||||
$<$<PLATFORM_ID:Windows>:NOMINMAX>
|
||||
$<$<PLATFORM_ID:Windows>:WEBRTC_WIN>
|
||||
$<$<PLATFORM_ID:Windows>:WIN32_LEAN_AND_MEAN>
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
${PROJECT_NAME} PUBLIC
|
||||
log
|
||||
android
|
||||
OpenSLES
|
||||
mediasoupclient
|
||||
)
|
||||
58
taoyao-client-android/taoyao/mediasoup/build.gradle
Normal file
58
taoyao-client-android/taoyao/mediasoup/build.gradle
Normal file
@@ -0,0 +1,58 @@
|
||||
plugins {
|
||||
id 'com.android.library'
|
||||
}
|
||||
|
||||
def WEBRTC_INC_PATH = "${projectDir}/deps/webrtc/src"
|
||||
def WEBRTC_LIB_PATH = "${projectDir}/deps/webrtc/lib"
|
||||
|
||||
android {
|
||||
namespace 'com.acgist.mediasoup'
|
||||
compileSdk 32
|
||||
defaultConfig {
|
||||
minSdk 31
|
||||
targetSdk 32
|
||||
versionCode 100
|
||||
versionName "1.0.0"
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
cFlags '-std=c17'
|
||||
cppFlags '-std=c++17'
|
||||
// CPU架构:x86_64、x86、arm64-v8a、armeabi-v7a
|
||||
abiFilters 'arm64-v8a'
|
||||
arguments "-DLIBWEBRTC_INCLUDE_PATH=" + WEBRTC_INC_PATH,
|
||||
"-DLIBWEBRTC_BINARY_PATH=" + WEBRTC_LIB_PATH,
|
||||
"-DMEDIASOUPCLIENT_BUILD_TESTS=OFF",
|
||||
"-DMEDIASOUPCLIENT_LOG_TRACE=OFF",
|
||||
"-DMEDIASOUPCLIENT_LOG_DEV=OFF"
|
||||
}
|
||||
}
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
}
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path file('CMakeLists.txt')
|
||||
version '3.22.1'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api fileTree(dir: WEBRTC_LIB_PATH, include: ['libwebrtc.jar'])
|
||||
implementation fileTree(dir: 'libs', include: ['*.a', '*.so', '*.jar'])
|
||||
implementation 'androidx.appcompat:appcompat:1.4.1'
|
||||
implementation 'com.google.android.material:material:1.5.0'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
}
|
||||
BIN
taoyao-client-android/taoyao/mediasoup/libs/libwebrtc.jar
Normal file
BIN
taoyao-client-android/taoyao/mediasoup/libs/libwebrtc.jar
Normal file
Binary file not shown.
0
taoyao-client-android/taoyao/mediasoup/proguard-rules.pro
vendored
Normal file
0
taoyao-client-android/taoyao/mediasoup/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
</manifest>
|
||||
18
taoyao-client-android/taoyao/mediasoup/src/main/cpp/main.cpp
Normal file
18
taoyao-client-android/taoyao/mediasoup/src/main/cpp/main.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <jni.h>
|
||||
#include <string>
|
||||
|
||||
#include "Device.hpp"
|
||||
|
||||
extern "C" JNIEXPORT jstring JNICALL
|
||||
Java_com_acgist_taoyao_client_MainActivity_stringFromJNI(
|
||||
JNIEnv* env,
|
||||
jobject /* this */) {
|
||||
mediasoupclient::Device device;
|
||||
if(device.IsLoaded()) {
|
||||
std::string hello = "Hello from C++ true";
|
||||
return env->NewStringUTF(hello.c_str());
|
||||
} else {
|
||||
std::string hello = "Hello from C++ false";
|
||||
return env->NewStringUTF(hello.c_str());
|
||||
}
|
||||
}
|
||||
@@ -15,3 +15,4 @@ dependencyResolutionManagement {
|
||||
rootProject.name = "taoyao"
|
||||
include ':boot'
|
||||
include ':client'
|
||||
include ':mediasoup'
|
||||
|
||||
Reference in New Issue
Block a user