Finder 默认并不显示隐藏文件,可以通过如下两种方式开启:

  1. 在终端中输入 defaults write com.apple.finder AppleShowAllFiles YES,然后重启 Finder
  2. Finder 中使用快捷键 Shift + Command + "."

参考:

An enum switch case label must be the unqualified name of an enumeration constantJava 中常见的编译错误,基本上 Google 搜索出来的错误场景都是因为在 switch 中使用枚举时搭配了类名造成,例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Season season = Season.SPRING;

switch (season) {
// 编译错误,直接使用 SPRING 即可
case Season.SPRING:
System.out.println("spring");

break;
case Season.SUMMER:
System.out.println("summer");

break;
default:
break;
}

然而,如果某个枚举值不存在,也会提示一样的错误,例如:

1
2
3
4
5
6
7
8
9
10
Season season = Season.SPRING;

switch (season) {
case SOME_VALUE_DOES_NOT_EXIST:
System.out.println("spring");

break;
default:
break;
}

这种情况下的错误提示容易让人摸不着头脑,IntelliJ IDEA 的错误提示则较为友好:Cannot resolve symbol 'SOME_VALUE_DOES_NOT_EXIST'。对于这种错误场景,实际工作中遇到一个例子:

  1. 在开发阶段,A 拉了个 some.package 的分支,更新版本号为 a.b-SNAPSHOT 并发布,将其引入 some.app,推送代码后触发了 some.appJenkins 构建任务
  2. B 也拉了个 some.package 的分支,同样更新版本号为 a.b-SNAPSHOT 并发布,并增加了一个新的枚举值到 SomeEnum,同样将其引入 some.app,推送代码后触发了 some.appJenkins 构建任务,此时任务构建失败,提示编译错误:An enum switch case label must be the unqualified name of an enumeration constant

出现这样的原因是 Jenkins 执行构建任务时执行的编译命令是 mvn compile,在 A 提交任务时,构建服务器下载了 some.packagea.b-SNAPSHOT 版本,由于是 SNAPSHOT 版本,在 B 提交任务时,构建服务器没有重新下载 some.package,导致服务器中的 some.package 没有 B 新增的修改,从而出现编译错误,解决方法是在编译时增加 -U 参数来强制更新 SNAPSHOT

参考:

假设我们希望将 server1 下的 /data1 目录中的数据同步到 server2 下的 /data2 目录,首先需要建立 server1server2 的免密登陆,在 server1 上执行 ssh-keygen,默认情况会在 ~/.ssh 目录下生成 id_rsaid_rsa.pub 两个文件,然后将 ~/.ssh/id_rsa.pub 文件的内容复制到 server2~/.ssh/authorized_keys 文件中即可。

接着,就可以使用 rsync 进行数据同步,具体命令为 rsync -az --delete /data1/ server2-user@server2-ip:/data2,其中 -a 表示递归同步 /data1 下的子文件夹及保留文件的权限、组、软连接等信息,如果不需要这些额外的文件信息而只想要递归同步可以使用 -r 来代替 -a-z 表示开启文件压缩来减少网络传输;--delete 表示在 /data1 中删除的文件在 /data2 中也会同步删除。最后需要注意命令中 /data1/ 末尾的 /,加了 / 表示将 /data1 下的所有文件同步到 /data2,没有 / 则表示将 /data1 这个文件夹同步到 /data2 下,假设 /data1 下有 abc 三个文件,两种写法最后的同步区别为:

  • /data1//data2/a,b,c
  • /data1/data2/data1/a,b,c

最后,我们需要将 rsync 加入到定时任务中进行自动备份。执行 crontab -e,将定时任务添加到文件中,如每小时执行一次:0 * * * * rsync -az --delete /data1/ server2-user@server2-ip:/data2

参考:

野生 NHK NEWS EASY 客户端,无广告,功能还比较单一,只上了 Google PlayiOS 没有通过:

alt

alt

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')

这个问题在 FlutterGitHub 仓库中也有人提到,解决方法也比较简单,删除 App.framework 文件夹即可,即 rm -rf ios/Flutter/App.framework

参考:

对于发布到 Google Play 或者 App Store 的应用,需要提供一份隐私政策的说明,如果不知道怎么写的话推荐一个在线的网站来自动生成隐私政策。通过 App Privacy Policy Generator 只需填写一些关键信息即可生成一份隐私政策说明,最终效果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
**Privacy Policy**

Awesome developer built the My awesome app app as an Open Source app. This SERVICE is provided by Awesome developer at no cost and is intended for use as is.

This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service.

If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy.

The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which is accessible at My awesome app unless otherwise defined in this Privacy Policy.

**Information Collection and Use**

For a better experience, while using our Service, I may require you to provide us with certain personally identifiable information, including but not limited to ip. The information that I request will be retained on your device and is not collected by me in any way.

The app does use third party services that may collect information used to identify you.

Link to privacy policy of third party service providers used by the app

* [Google Play Services](https://www.google.com/policies/privacy/)

**Log Data**

I want to inform you that whenever you use my Service, in a case of an error in the app I collect data and information (through third party products) on your phone called Log Data. This Log Data may include information such as your device Internet Protocol (“IP”) address, device name, operating system version, the configuration of the app when utilizing my Service, the time and date of your use of the Service, and other statistics.

**Cookies**

Cookies are files with a small amount of data that are commonly used as anonymous unique identifiers. These are sent to your browser from the websites that you visit and are stored on your device's internal memory.

This Service does not use these “cookies” explicitly. However, the app may use third party code and libraries that use “cookies” to collect information and improve their services. You have the option to either accept or refuse these cookies and know when a cookie is being sent to your device. If you choose to refuse our cookies, you may not be able to use some portions of this Service.

**Service Providers**

I may employ third-party companies and individuals due to the following reasons:

* To facilitate our Service;
* To provide the Service on our behalf;
* To perform Service-related services; or
* To assist us in analyzing how our Service is used.

I want to inform users of this Service that these third parties have access to your Personal Information. The reason is to perform the tasks assigned to them on our behalf. However, they are obligated not to disclose or use the information for any other purpose.

**Security**

I value your trust in providing us your Personal Information, thus we are striving to use commercially acceptable means of protecting it. But remember that no method of transmission over the internet, or method of electronic storage is 100% secure and reliable, and I cannot guarantee its absolute security.

**Links to Other Sites**

This Service may contain links to other sites. If you click on a third-party link, you will be directed to that site. Note that these external sites are not operated by me. Therefore, I strongly advise you to review the Privacy Policy of these websites. I have no control over and assume no responsibility for the content, privacy policies, or practices of any third-party sites or services.

**Children’s Privacy**

These Services do not address anyone under the age of 13. I do not knowingly collect personally identifiable information from children under 13\. In the case I discover that a child under 13 has provided me with personal information, I immediately delete this from our servers. If you are a parent or guardian and you are aware that your child has provided us with personal information, please contact me so that I will be able to do necessary actions.

**Changes to This Privacy Policy**

I may update our Privacy Policy from time to time. Thus, you are advised to review this page periodically for any changes. I will notify you of any changes by posting the new Privacy Policy on this page.

This policy is effective as of 2020-05-04

**Contact Us**

If you have any questions or suggestions about my Privacy Policy, do not hesitate to contact me at dev@example.com.

This privacy policy page was created at [privacypolicytemplate.net](https://privacypolicytemplate.net) and modified/generated by [App Privacy Policy Generator](https://app-privacy-policy-generator.firebaseapp.com/)

Travis CI 构建

Building Flutter APKs and IPAs on Travis 这篇文章详细介绍了如何在 Travis CI 上为 Flutter 项目打包 Android/iOS 应用,不过实际构建时存在几个问题,原文中的 .travis.yml 配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
matrix:
include:
- os: linux
language: android
licenses:
- 'android-sdk-preview-license-.+'
- 'android-sdk-license-.+'
- 'google-gdk-license-.+'
android:
components:
- tools
- platform-tools
- build-tools-25.0.3
- android-25
- sys-img-armeabi-v7a-google_apis-25
- extra-android-m2repository
- extra-google-m2repository
- extra-google-android-support
jdk: oraclejdk8
sudo: false
addons:
apt:
# Flutter depends on /usr/lib/x86_64-linux-gnu/libstdc++.so.6 version GLIBCXX_3.4.18
sources:
- ubuntu-toolchain-r-test # if we don't specify this, the libstdc++6 we get is the wrong version
packages:
- libstdc++6
- fonts-droid
before_script:
- wget http://services.gradle.org/distributions/gradle-3.5-bin.zip
- unzip -qq gradle-3.5-bin.zip
- export GRADLE_HOME=$PWD/gradle-3.5
- export PATH=$GRADLE_HOME/bin:$PATH
- git clone https://github.com/flutter/flutter.git -b alpha --depth 1
script:
- ./flutter/bin/flutter -v build apk

- os: osx
language: generic
osx_image: xcode8.3
before_script:
- pip install six
- brew update
- brew install --HEAD libimobiledevice
- brew install ideviceinstaller
- brew install ios-deploy
- git clone https://github.com/flutter/flutter.git -b alpha --depth 1
script:
- ./flutter/bin/flutter -v build ios --no-codesign

cache:
directories:
- $HOME/.pub-cache

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 代码的阶段,原文中的配置会下载 Flutteralpha 分支代码,但是目前 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
2
3
4
5
6
7
8
9
10
11
[        ] > Failed to install the following Android SDK packages as some

licences have not been accepted.

[ ] build-tools;28.0.3 Android SDK Build-Tools 28.0.3

[ ] platforms;android-29 Android SDK Platform 29

[ ] To build this project, accept the SDK license agreements and

install the missing components using the Android Studio SDK Manager.

这个错误是由于没有同意 Android SDK 的许可证协议,在 before_script 中加入如下配置即可:

1
2
yes | sdkmanager "platforms;android-29"
yes | sdkmanager "build-tools;28.0.3"

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
matrix:
include:
- os: linux
language: android
licenses:
- 'android-sdk-preview-license-.+'
- 'android-sdk-license-.+'
- 'google-gdk-license-.+'
android:
components:
- tools
- platform-tools
- build-tools-25.0.3
- android-25
- sys-img-armeabi-v7a-google_apis-25
- extra-android-m2repository
- extra-google-m2repository
- extra-google-android-support
jdk: oraclejdk8
sudo: false
addons:
apt:
# Flutter depends on /usr/lib/x86_64-linux-gnu/libstdc++.so.6 version GLIBCXX_3.4.18
sources:
- ubuntu-toolchain-r-test # if we don't specify this, the libstdc++6 we get is the wrong version
packages:
- libstdc++6
- fonts-droid
before_script:
- wget https://services.gradle.org/distributions/gradle-3.5-bin.zip
- unzip -qq gradle-3.5-bin.zip
- export GRADLE_HOME=$PWD/gradle-3.5
- export PATH=$GRADLE_HOME/bin:$PATH
- git clone https://github.com/flutter/flutter.git -b stable --depth 1
- yes | sdkmanager "platforms;android-29"
- yes | sdkmanager "build-tools;28.0.3"
script:
- ./flutter/bin/flutter -v build apk

- os: osx
language: generic
osx_image: xcode11
before_script:
- brew update
- brew install --HEAD libimobiledevice
- brew install ideviceinstaller
- brew install ios-deploy
- git clone https://github.com/flutter/flutter.git -b stable --depth 1
script:
- ./flutter/bin/flutter -v build ios --no-codesign

cache:
directories:
- $HOME/.pub-cache

完整的代码可参考 flutter-travis-build-demo

Codemagic

最后推荐 Codemagic 这个服务,提供云端打包 Flutter 应用的功能,省去了 Travis CI 配置的步骤,免费用户每月有500分钟的额度来执行构建。

参考

项目搭建

首先执行命令 dotnet new classlib --name App 来创建一个类库程序作为测试的对象,该类库只包含一个 SumService 类:

1
2
3
4
5
6
7
8
9
10
11
12
using System;

namespace App
{
public class SumService
{
public static int Sum(int a, int b)
{
return a + b;
}
}
}

然后创建一个基于 xunit 的单元测试项目来编写测试用例,并将 App 类库项目作为项目引用加入到 App.Tests 项目中:

1
2
dotnet new xunit --name App.Tests
dotnet add .\App.Tests\App.Tests.csproj reference .\App\App.csproj

并编写一个测试用例 SumServiceTest

1
2
3
4
5
6
7
8
9
10
11
12
13
14
using System;
using Xunit;

namespace App.Tests
{
public class SumServiceTest
{
[Fact]
public void ShouldReturn5()
{
Assert.Equal(5, SumService.Sum(2, 3));
}
}
}

接着创建一个解决方案,并将 AppApp.Tests 项目加入到该解决方案中:

1
2
dotnet new sln --name App
dotnet sln add .\App\App.csproj .\App.Tests\App.Tests.csproj

最后项目结构如下:

1
2
3
4
5
6
7
├── App
│ └── App.csproj
│ └── SumService.cs
├── App.Tests
│ └── App.Tests.csproj
│ └── SumServiceTest.cs
├── App.sln

覆盖率测试

覆盖率测试依赖 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
2
dotnet remove .\App.Tests package coverlet.collector
dotnet add .\App.Tests\ package coverlet.msbuild

然后执行测试命令:

1
dotnet test /p:CollectCoverage=true

即可在控制台打印测试覆盖率报告:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Calculating coverage result...
Generating report 'D:\WorkSpace\dotnet-core-coverlet-msbuild-demo\App.Tests\coverage.json'

+--------+------+--------+--------+
| Module | Line | Branch | Method |
+--------+------+--------+--------+
| App | 100% | 100% | 100% |
+--------+------+--------+--------+

+---------+------+--------+--------+
| | Line | Branch | Method |
+---------+------+--------+--------+
| Total | 100% | 100% | 100% |
+---------+------+--------+--------+
| Average | 100% | 100% | 100% |
+---------+------+--------+--------+

集成 codecov

coverlet.msbuild

集成 codecov 需要指定测试覆盖率报告文件的路径,暂不支持 coverlet.msbuild 默认生成的 json 格式的文件,可以在执行测试时添加 /p:CoverletOutputFormat=opencover 参数来生成 opencover 格式的文件,相应的 .appveyor.yml 文件内容如下:

1
2
3
4
5
6
7
8
image: Visual Studio 2019
before_build:
- choco install codecov
build_script:
- dotnet build
test_script:
- dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
- codecov -f ./App.Tests/coverage.opencover.xml

coverlet.collector

使用 coverlet.collector 时每次生成的测试覆盖率报告所在的路径是随机的,所以需要将测试覆盖率报告复制到一个固定的路径中,可以使用如下的 PowerShell 脚本:

1
2
3
4
$source = "./App.Tests/TestResults"
$destination = $source
$filter = "coverage.cobertura.xml"
Get-ChildItem -Recurse -Path $source | Where-Object { $_.Name -match $filter } | Copy-Item -Destination $destination

相应的 .appveyor.yml 文件内容如下:

1
2
3
4
5
6
7
8
9
image: Visual Studio 2019
before_build:
- choco install codecov
build_script:
- dotnet build
test_script:
- dotnet test --collect:"XPlat Code Coverage"
- ps: ./FindCoverageFile.ps1
- codecov -f ./App.Tests/TestResults/coverage.cobertura.xml

完整的代码可参考 dotnet-core-coverlet-msbuild-demodotnet-core-coverlet-collector-demo

参考

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

参考:

0%