野生 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

参考:

使用 Visual Studio CodeRemote - SSH 插件连接服务器开发时,有可能会遇到不同的服务器对应不同的私钥的情况,这时就需要单独为各个服务器指定私钥的位置。打开 SSH 配置文件(默认路径是 ~/.ssh/config),在需要指定私钥路径的服务器下添加 IdentityFile path-to-private-key 即可,例如:

1
2
3
4
5
Host your-host
HostName your-host-name
User your-host-user
ForwardAgent yes
IdentityFile path-to-private-key

参考:

在某些场景下,编写 Dockerfile 时需要定义变量来避免重复出现的值,例如下面的例子中,Gradle 的版本号出现了三次,如果未来需要更新 Gradle 的版本号,则需要修改三次。

1
2
3
RUN wget https://services.gradle.org/distributions/gradle-6.3-bin.zip
RUN unzip gradle-6.3-bin.zip
RUN gradle-6.3/bin/gradle task

可以通过 ARG variable-name=variable-value 来定义一个变量,使用变量时通过 $variable-name 访问即可,对开头的例子使用变量修改后如下:

1
2
3
4
ARG GRADLE_VERSION=6.3
RUN wget https://services.gradle.org/distributions/gradle-$GRADLE_VERSION-bin.zip
RUN unzip gradle-$GRADLE_VERSION-bin.zip
RUN gradle-$GRADLE_VERSION/bin/gradle task

参考:

Math

Computer Science

Algorithm & Data Structures

Compiler & Interpreter

Operating Systems

Database

Networking

Linux

Programming

Programming Languages

C

Java

JavaScript

TypeScript

Python

Clojure

Ruby

Racket

Rust

Go

OCaml

Haskell

Redis

Git

German

Others

首先构建一个多模块的 Maven 项目,项目结构如下:

1
2
3
4
5
6
7
├── product-service
│ └── pom.xml
├── sum-service
│ └── pom.xml
├── app
│ └── pom.xml
├── pom.xml

其中 product-servicesum-service 表示功能代码,app 负责测试用例的整合。product-servicesum-service 分别包含一个 ProductService 类和 SumService 类,具体代码如下:

1
2
3
4
5
6
// ProductService
public class ProductService {
public int product(int x, int y) {
return x * y;
}
}
1
2
3
4
5
6
// SumService
public class SumService {
public int sum(int x, int y) {
return x + y;
}
}

app 内的测试用例如下:

1
2
3
4
5
6
7
public class AppTest {
@Test
public void shouldCalculateCorrectSumAndProduct() {
Assert.assertEquals(10, new ProductService().product(2, 5));
Assert.assertEquals(5, new SumService().sum(2, 3));
}
}

然后在 root 模块的 pom.xml 文件中配置 JaCoCo 插件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

最后在 app 模块的 pom.xml 文件中配置 JaCoCo 插件:

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
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>${argLine} -Xms256m -Xmx2048m</argLine>
<forkCount>1</forkCount>
<runOrder>random</runOrder>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<id>report-aggregate</id>
<phase>test</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

此时在 root 模块下执行 mvn test,执行成功后在 app/target/site/jacoco-aggregate 目录下就会生成各个模块的覆盖测试报告:

alt

完整的代码可参考 GitHub

参考:

0%