环境说明:
-
Ubuntu18.04
-
源码地址:GitHub - Genymobile/scrcpy: Display and control your Android device
-
scrcpy源码版本v1.23
一、搭建scrcpy编译开发环境:
-
下载scrcpy源码
git clone https://github.com/Genymobile/scrcpy
二、前置软件搭建
1.adb
-
安装adb的命令
sudo apt-get install android-tools-adb
2.查看adb是否安装成功
-
adb version
3.安装pip3
sudo apt install python3-pip
4meson搭建 -
pip3 install meson
这个时候,关键点来的,因为用
pip3 install meson安装的话,不但没有设置环境变量,而且版本低,略显麻烦,故用apt-get安装。
m:~/scrcpy-1.14$ pip3 install meson
Collecting meson
Downloading https://files.pythonhosted.org/packages/04/db/53fe14aa9a45e34b76e58f4b479276eb8dd0591552f941a4aea28cd3d760/meson-0.54.3.tar.gz (1.7MB)
100% |████████████████████████████████| 1.7MB 54kB/s
Building wheels for collected packages: meson
Running setup.py bdist_wheel for meson ... done
Stored in directory: /home/abc/.cache/pip/wheels/66/09/2d/4fcfb30d06d18fd9bdc67a724b8a56844e94cc194a45ea41f7
Successfully built meson
Installing collected packages: meson
Successfully installed meson-0.54.3
会显示下图所示,版本不过。
示版本太低:
meson.build:1:0: ERROR: Meson version is 0.45.1 but project requires >= 0.48.
解决办法
sudo apt-get install meson
export PATH=~/.local/bin:$PATH
meson -v
5.依赖包
# runtime dependencies
sudo apt install ffmpeg libsdl2-2.0-0
# client build dependencies
sudo apt install make gcc git pkg-config ninja-build \
libavcodec-dev libavformat-dev libavutil-dev \
libsdl2-dev
# server build dependencies
sudo apt install openjdk-8-jdk
但是,在安装过程会遇到很多,你明明安装了,但是它找不到这个包的问题。
所以,你要学会自学能力,找到这个包,如上图,libvadevice,libusb-1.0这两个包
sudo apt-get insatall libusb-1.0
类似 这种解决办法。
6python的版本问题
Ubuntu系统中已经安装了python3.6,在不卸载python3.6的情况下安装python3.7
sudo apt install python3.7
7.改变环境变量
我在安装了之后,检查python的版本之后还是3.6,并不是3.7。还需要改变环境变量
echo alias python=python3.7 >> ~/.bashrc
source ~/.bashrc
三scrcpy的搭建
meson x --buildtype release --strip -Db_lto=true
成功如下
The Meson build system
Version: 0.54.3
Source dir: /home/abc/scrcpy-1.14
Build dir: /home/abc/scrcpy-1.14/x
Build type: native build
Project name: scrcpy
Project version: 1.14
C compiler for the host machine: cc (gcc 7.5.0 "cc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0")
C linker for the host machine: cc ld.bfd 2.30
Host machine cpu family: x86_64
Host machine cpu: x86_64
Found pkg-config: /usr/bin/pkg-config (0.29.1)
Run-time dependency libavformat found: YES 57.83.100
Run-time dependency libavcodec found: YES 57.107.100
Run-time dependency libavutil found: YES 55.78.100
Run-time dependency sdl2 found: YES 2.0.8
Configuring config.h using configuration
Program ./scripts/build-wrapper.sh found: YES (/home/abc/scrcpy-1.14/server/./scripts/build-wrapper.sh)
Build targets in project: 3
Found ninja-1.8.2 at /usr/bin/ninj
四注意点
唯一需要提到一点的是,在编译时输入meson build之后,在生成的build文件下会有一个名为app的文件夹,需要将scrcpy-server压缩包(Release scrcpy v1.23 · Genymobile/scrcpy · GitHub:划到最下方就能看到)手动放入到该文件夹。
这个文件不要解压,一定要改名,改成scrcpy-server。
放到
sudo cp scrcpy-server /usr/local/share/scrcpy/
真正的编辑了scrcpy
ninja -Cx
成功如下
ninja: Entering directory `x'
[0/1] Generating scrcpy-server with a custom command
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 1m 43s
25 actionable tasks: 25 executed
sudo ninja -Cx install
成功如下
ninja: Entering directory `x'
[0/2] Generating scrcpy-server with a custom command
(not invoking gradle, since we are root)
[1/2] Installing files.
Installing app/scrcpy to /usr/local/bin
Stripping target 'app/scrcpy' using strip.
Installing server/scrcpy-server to /usr/local/share/scrcpy
Installing /home/abc/scrcpy-1.14/app/scrcpy.1 to /usr/local/share/man/man1
多种实现方式
cd /scrcpy
./run x
cd /x/app
./scrcpy
scrcpy
手机的配置,请同学们参考其他博主
Scrcpy投屏出现Exception on thread Thread错误
使用scrcpy投屏时出现Exception on thread Thread[main,5,main]等无法连接错误;[server] ERROR: Exception on thread Thread[main,5,main]
[server] ERROR: The hardware encoder is not able to encode at the given definition.
[server] ERROR: Try with a lower definition:
[server] ERROR: scrcpy -m 1024
android.media.MediaCodec$CodecException: Error 0xfffffc0e
at android.media.MediaCodec.native_configure(Native Method)
at android.media.MediaCodec.configure(MediaCodec.java:2023)
at android.media.MediaCodec.configure(MediaCodec.java:1951)
at com.genymobile.scrcpy.ScreenEncoder.configure(ScreenEncoder.java:167)
at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:68)
at com.genymobile.scrcpy.Server.scrcpy(Server.java:34)
at com.genymobile.scrcpy.Server.main(Server.java:163)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:359)
WARN: Device disconnected
原因为:手机不兼容 scrcpy 默认分辨率设置。
解决方法:
启动scrcpy时使用较低的分辨率。
scrcpy -m 1024
如果本文内容有帮助,期待一键三连哈~