ubuntu18.04 安装 scrcpy 遇到的坑

首先,通过以下命令直接安装是不行的:

sudo apt install scrcpy

sudo apt install scrcpy 或 sudo apt-get install scrcpy 都不行,提示“E: 无法定位软件包 scrcpy”

:~$ sudo apt-get install scrcpy
[sudo] abc 的密码: 
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
E: 无法定位软件包 scrcpy

及时更新切换源,也不起作用,在 Ubuntu 16.04 是试过很多次了。
 

不得已,下载了源码,就想通过编译安装的方式实现。

源码地址: https://github.com/Genymobile/scrcpy

根据 README.md 的说明,这种方法只能在 ubuntu 20.04 上用:

### Linux

On Debian (_testing_ and _sid_ for now) and Ubuntu (20.04):

```
apt install scrcpy
```

查看源码编译说明文档 BUILD.md 文件,安装说明一步一步执行,

其中一部是要安装 meson:

On old versions (like Ubuntu 16.04), `meson` is too old. In that case, install
it from `pip3`:

```bash
sudo apt install python3-pip
pip3 install meson
```

按照说明执行,也提示安装成功:

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

但到了下一步 ## Common steps 中执行 meson 命令时

## Common steps
...

Then, build:

```bash
meson x --buildtype release --strip -Db_lto=true
ninja -Cx
```

提示版本太低:

meson.build:1:0: ERROR: Meson version is 0.45.1 but project requires >= 0.48.

:~/scrcpy-1.14$ meson x --buildtype release --strip -Db_lto=true
The Meson build system
Version: 0.45.1
Source dir: /home/abc/scrcpy-1.14
Build dir: /home/abc/scrcpy-1.14/x
Build type: native build

meson.build:1:0: ERROR: Meson version is 0.45.1 but project requires >= 0.48.

A full log can be found at /home/abc/scrcpy-1.14/x/meson-logs/meson-log.txt

先通过 sudo apt-get remove meson 卸载系统自带的 meson 也不行,提示找不到 meson;

再执行 pip2 安装虽然提示安装成功,但还是找不到 meson:

abc@abc:~/scrcpy-1.14$ meson x --buildtype release --strip -Db_lto=true
bash: /usr/bin/meson: 没有那个文件或目录
abc@abc:~/scrcpy-1.14$ pip3 install meson
Collecting meson
Installing collected packages: meson
Successfully installed meson-0.54.3
abc@abc:~/scrcpy-1.14$ meson x --buildtype release --strip -Db_lto=true
bash: /usr/bin/meson: 没有那个文件或目录

真是陷入了无奈之中,后来从网上查了多次才查到一种解决方法如下:

https://askubuntu.com/questions/1212424/update-meson-on-ubuntu-18-04-4-lts-force-update

You can try updating your PATH var so that the new version is found first.

export PATH=$PATH:/home/youruser/.local/bin

原来,之前通过 pip3 的方式1确实安装成功了,只不过安装到了 ~/.local/bin 目录下。

所以使用 这个 meson 就可以编译了,编译如下:

abc@abc:~/scrcpy-1.14$ /home/abc/.local/bin/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/ninja

接着,再执行 ninja -Cx 命令就可以编译成功了。

需要注意的是,必须配置 ANDROID_HOME,否则编译不过:

If you want to build the server, install the [Android SDK] (_Android Studio_),
and set `ANDROID_HOME` to its directory. For example:

[Android SDK]: https://developer.android.com/studio/index.html

```bash
export ANDROID_HOME=~/android/sdk
```

编译成功的结果:

abc@abc:~/scrcpy-1.14$ 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

编译完后执行安装:

abc@abc:~/scrcpy-1.14$ 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

然后,就可以使用了 scrcpy 命令打开手机了,长舒一口气,心里美滋滋,终于看到了手机屏幕,痛并快乐着……

abc@abc:~/scrcpy-1.14$ scrcpy
INFO: scrcpy 1.14 <https://github.com/Genymobile/scrcpy>
/usr/local/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 143.6 MB/s (33142 bytes in 0.000s)
[server] INFO: Device: meizu meizu 17 (Android 10)INFO: OpenGL shaders: ENABLED
INFO: Created renderer: opengl
INFO: Renderer: opengl
INFO: OpenGL version: 4.5 (Compatibility Profile) Mesa 19.2.8
INFO: Trilinear filtering enabled
INFO: Initial texture: 1080x2336

效果如下,我的手机屏幕:

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值