Flutter error - Building for iOS Simulator, but the linked and embedded framework 'App.framework' was built for iOS
Flutter
项目打包 iOS
应用的时候遇到个错误:
1 | Building for iOS Simulator, but the linked and embedded framework 'App.framework' was built for iOS. (in target 'Runner' from project 'Runner') |
这个问题在 Flutter
的 GitHub
仓库中也有人提到,解决方法也比较简单,删除 App.framework
文件夹即可,即 rm -rf ios/Flutter/App.framework
。
参考:
【分享】隐私政策生成器
对于发布到 Google Play
或者 App Store
的应用,需要提供一份隐私政策的说明,如果不知道怎么写的话推荐一个在线的网站来自动生成隐私政策。通过 App Privacy Policy Generator 只需填写一些关键信息即可生成一份隐私政策说明,最终效果如下:
1 | **Privacy Policy** |
使用 Travis CI 为 Flutter 项目打包 Android/iOS 应用
Travis CI 构建
Building Flutter APKs and IPAs on Travis 这篇文章详细介绍了如何在 Travis CI 上为 Flutter 项目打包 Android/iOS 应用,不过实际构建时存在几个问题,原文中的 .travis.yml
配置如下:
1 | matrix: |
Android
wget - 403 Forbidden
这个错误发生在执行 wget http://services.gradle.org/distributions/gradle-3.5-bin.zip
的时候,把 gradle
的下载路径替换成 https
即可。
Remote branch alpha not found in upstream origin
这个错误发生在下载 Flutter
代码的阶段,原文中的配置会下载 Flutter
的 alpha
分支代码,但是目前 Flutter
的仓库已经没有 alpha
分支,切换到 stable
分支即可,即:git clone https://github.com/flutter/flutter.git -b stable --depth 1
。
Failed to install the following Android SDK packages as some licences have not been accepted
详细错误信息如下:
1 | [ ] > Failed to install the following Android SDK packages as some |
这个错误是由于没有同意 Android SDK
的许可证协议,在 before_script
中加入如下配置即可:
1 | yes | sdkmanager "platforms;android-29" |
iOS
pip: command not found
这个错误在执行 pip install six
时遇到,经过实际验证构建 iOS
应用时并不需要此行配置,所以删掉即可。
Xcode 11.0 or greater is required to develop for iOS
原文中的配置使用的是 Xcode 8.3
,最后打包时会提示此错误,将 osx_image
设置为 xcode11
即可。
最后完整可用的 .travis.yml
配置如下:
1 | matrix: |
完整的代码可参考 flutter-travis-build-demo。
Codemagic
最后推荐 Codemagic 这个服务,提供云端打包 Flutter
应用的功能,省去了 Travis CI
配置的步骤,免费用户每月有500分钟的额度来执行构建。
参考
.NET Core 覆盖率测试
项目搭建
首先执行命令 dotnet new classlib --name App
来创建一个类库程序作为测试的对象,该类库只包含一个 SumService
类:
1 | using System; |
然后创建一个基于 xunit
的单元测试项目来编写测试用例,并将 App
类库项目作为项目引用加入到 App.Tests
项目中:
1 | dotnet new xunit --name App.Tests |
并编写一个测试用例 SumServiceTest
:
1 | using System; |
接着创建一个解决方案,并将 App
和 App.Tests
项目加入到该解决方案中:
1 | dotnet new sln --name App |
最后项目结构如下:
1 | ├── App |
覆盖率测试
覆盖率测试依赖 coverlet
,在创建单元测试项目时已自动添加了该依赖,执行测试时添加 coverlet
相关的参数即可生成测试覆盖率报告:
1 | dotnet test --collect:"XPlat Code Coverage" |
执行成功后会在 App.Tests/TestResults/{random-string}
目录下生成名为 coverage.cobertura.xml
的测试覆盖率报告。
但是,自动创建的单元测试项目默认添加的 coverlet
依赖是 coverlet.collector
,目前还不支持在控制台中打印测试覆盖率报告:
At the moment VSTest integration doesn’t support all features of msbuild and .NET tool, for instance show result on console, report merging and threshold validation. We’re working to fill the gaps.
如果希望在控制台中打印测试覆盖率报告可将 coverlet.collector
依赖改为 coverlet.msbuild
:
1 | dotnet remove .\App.Tests package coverlet.collector |
然后执行测试命令:
1 | dotnet test /p:CollectCoverage=true |
即可在控制台打印测试覆盖率报告:
1 | Calculating coverage result... |
集成 codecov
coverlet.msbuild
集成 codecov
需要指定测试覆盖率报告文件的路径,暂不支持 coverlet.msbuild
默认生成的 json
格式的文件,可以在执行测试时添加 /p:CoverletOutputFormat=opencover
参数来生成 opencover
格式的文件,相应的 .appveyor.yml
文件内容如下:
1 | image: Visual Studio 2019 |
coverlet.collector
使用 coverlet.collector
时每次生成的测试覆盖率报告所在的路径是随机的,所以需要将测试覆盖率报告复制到一个固定的路径中,可以使用如下的 PowerShell
脚本:
1 | $source = "./App.Tests/TestResults" |
相应的 .appveyor.yml
文件内容如下:
1 | image: Visual Studio 2019 |
完整的代码可参考 dotnet-core-coverlet-msbuild-demo 及 dotnet-core-coverlet-collector-demo。
参考
在 Ubuntu 下使用 Puppeteer 时无法加载类库 libX11-xcb.so.1
在 Ubuntu
下运行 Puppeteer
遇到了如下错误:
1 | error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory |
需要安装以下依赖来解决:
1 | sudo apt-get install gconf-service libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxss1 libxtst6 libappindicator1 libnss3 libasound2 libatk1.0-0 libc6 ca-certificates fonts-liberation lsb-release xdg-utils wget |
参考:
SSH 连接服务器时指定私钥的路径
使用 Visual Studio Code
的 Remote - SSH
插件连接服务器开发时,有可能会遇到不同的服务器对应不同的私钥的情况,这时就需要单独为各个服务器指定私钥的位置。打开 SSH
配置文件(默认路径是 ~/.ssh/config
),在需要指定私钥路径的服务器下添加 IdentityFile path-to-private-key
即可,例如:
1 | Host your-host |
参考:
如何在 Dockerfile 中定义变量
在某些场景下,编写 Dockerfile
时需要定义变量来避免重复出现的值,例如下面的例子中,Gradle
的版本号出现了三次,如果未来需要更新 Gradle
的版本号,则需要修改三次。
1 | RUN wget https://services.gradle.org/distributions/gradle-6.3-bin.zip |
可以通过 ARG variable-name=variable-value
来定义一个变量,使用变量时通过 $variable-name
访问即可,对开头的例子使用变量修改后如下:
1 | ARG GRADLE_VERSION=6.3 |
参考:
一些在线书籍(不定期更新)
Math
- Introduction to Probability, Statistics, and Random Processes
- Interactive Linear Algebra
- Mathematics for Machine Learning
- Probabilistic Programming & Bayesian Methods for Hackers
- Elementary Calculus: An Infinitesimal Approach
Computer Science
- CS for All
- Foundations of Computer Science
- CS Principles: Big Ideas in Programming
- How to Think Like a Computer Scientist
- Computer Science from the Bottom Up
Algorithm & Data Structures
Compiler & Interpreter
- Crafting Interpreters
- Build Your Own Lisp
- A Compiler Writing Journey
- Resources for Amateur Compiler Writers
Operating Systems
- Operating Systems: Three Easy Pieces
- Writing an OS in Rust
- Think OS: A Brief Introduction to Operating Systems
Database
Networking
Linux
- Linux Inside
- The Linux Kernel
- Linux Kernel Teaching
- Linux From Scratch
- The Linux Command Line
- UNIX TOOLBOX
Programming
- How to Design Programs
- Structure and Interpretation of Computer Programs
- SICP Distilled
- Mostly Adequate Guide to Functional Programming
Programming Languages
C
Java
JavaScript
- Eloquent JavaScript
- Speaking JavaScript: An In-Depth Guide for Programmers
- Learning JavaScript Design Patterns
- The Modern JavaScript Tutorial
- JavaScript Garden
- Robust Client-Side JavaScript
- JavaScript for Data Science
- Deep JavaScript
TypeScript
Python
- The Hitchhiker’s Guide to Python!
- Intermediate Python
- Full Stack Python
- Test-Driven Development with Python
- Dive Into Python 3
- Automate the Boring Stuff with Python
- The Little Book of Python Anti-Patterns
Clojure
Ruby
Racket
Rust
Go
OCaml
Haskell
Redis
Git
German
Others
- The Architecture of Open Source Applications
- Professional Software Development
- Object-Oriented System Development
- Distributed systems for fun and profit
- High Performance Browser Networking
- 97 Things Every Programmer Should Know
- Concurrent Programming for Scalable Web Architectures
- The Twelve-Factor App
- Secure Programming HOWTO
- Lessons In Electric Circuits
- A Graduate Course in Applied Cryptography
- GameBoy Emulation in JavaScript
- Learn LaTeX
JaCoCo 配置 Maven 多模块覆盖率测试
首先构建一个多模块的 Maven
项目,项目结构如下:
1 | ├── product-service |
其中 product-service
和 sum-service
表示功能代码,app
负责测试用例的整合。product-service
和 sum-service
分别包含一个 ProductService
类和 SumService
类,具体代码如下:
1 | // ProductService |
1 | // SumService |
app
内的测试用例如下:
1 | public class AppTest { |
然后在 root
模块的 pom.xml
文件中配置 JaCoCo
插件:
1 | <build> |
最后在 app
模块的 pom.xml
文件中配置 JaCoCo
插件:
1 | <build> |
此时在 root
模块下执行 mvn test
,执行成功后在 app/target/site/jacoco-aggregate
目录下就会生成各个模块的覆盖测试报告:
完整的代码可参考 GitHub。
参考: