f-droid 是一个自由软件商店,最近在给我的开源应用KeepassA上传到f-droid商店时遇到了不少问题。

一、注册gitlib

f-droid 地址:https://gitlab.com/fdroid/fdroiddata/-/tree/master

二、预编译

主要是用来验证metadata配置文件是否正确。

Tip:F-Droid 提交应用,只需要将写好的metadata文件合并到官方的仓库中便可,不需要提供apk包,由服务器根据配置文件编译apk

2.1 安装服务仓库(不推荐)

  • brew 安装,该安装方式会缺少一些运行库
    brew install fdroidserver
  • 手动安装
    clone fdroidserver
    git clone https://gitlab.com/fdroid/fdroidserver.git
    export PATH="$PATH:$PWD/fdroidserver"
    安装需要的python环境
    pip install GitPython
    pip install pyasn1
    pip install pyasn1-modules
    pip install PyYAML
    pip install requests
    pip install ruamel.yaml
    pip install paramiko
    pip install Pillow
    然后执行命令fdroid,如果出现下面的帮助提示,表示fdroidserver安装成功。

image-20200822085750805

gradlew-fdroid设置权限

chmod +x gradlew-fdroid

2.2 clone数据仓库

git clone https://gitlab.com/fdroid/fdroiddata.git
cd fdroiddata

编辑config.py,配置一些必要的信息

wget -O https://gitlab.com/fdroid/fdroidserver/-/blob/master/examples/config.py
vim config.py
image-20200820162454666

配置keystor信息

keystorepass = "xxxx"
keypass = "xxxxx"
keystore = "/Users/aria/Downloads/kpa/ksyStore/xxx.keystore"
keyaliases={'xxx'}

配置sdk\ndk信息

sdk_path = "$ANDROID_HOME"

ndk_paths = {
'r21d': '/Users/aria/dev/android/sdk/ndk/21'
# 'r10e': None,
# 'r11c': None,
# 'r12b': "$ANDROID_NDK",
# 'r13b': None,
# 'r14b': None,
# 'r15c': None,
# 'r16b': None,
# 'r17c': None,
# 'r18b': None,
# 'r19c': None,
# 'r20b': None,
# 'r21d': None,
}

进行初始化

chmod 0600 config.py
# fdroid init
fdroid readmeta # 如果没有输出,表示配置成功

2.3 配置metadata

cd fdroiddata
fdroid import --url https://github.com/foo/bar --subdir app # 导入你项目所在的github代码

cd metadata
vim {你的包名}.yml

输入以下内容,并进行配置

# F-Droid metadata template
#
# See http://f-droid.org/manual for more details
# and the Metadata reference
# https://f-droid.org/docs/Build_Metadata_Reference/
#
# Fields that are commented out are optional
#
# Single-line fields start right after the colon (with a whitespace).

Categories: (use those which apply)
- Connectivity
- Development
- Games
- Graphics
- Internet
- Money
- Multimedia
- Navigation
- Phone & SMS
- Reading
- Science & Education
- Security
- Sports & Health
- System
- Theming
- Time
- Writing
License: (identifier from https://spdx.org/licenses)
AuthorName: AriaLyy
AuthorEmail: laoyuyu@laoyuyu.me
IssueTracker: https://github.com/AriaLyy/KeepassA/issues

# WebSite: (web link)
SourceCode: (web link)
# IssueTracker: (web link)

# Changelog: (web link)
# Donate: (web link)
# FlattrID: (number)
# LiberapayID: (number)
# Bitcoin: (bitcoin address)

# You may not need to add Summary and Description here,
# if you want to translate them. For details on other locations, see
# https://f-droid.org/en/docs/All_About_Descriptions_Graphics_and_Screenshots/
Summary: (one sentence, no more than 30-50 chars, no trailing punctuation)
Description: |-
Description of what the app does, starting on a new line. It should be as
objective as possible and wrapped at 80 chars (except links and list
items).

A blank line means a line break, i.e. the end of a paragraph.

Bulleted lists can be used:

* Item 1
* Item 2

Links can be added like this:
[https://github.com/org/project/raw/HEAD/res/raw/changelog.xml Changelog]

Links to other apps too: [[some.other.app]]

RepoType: (git, git-svn, svn, hg or bzr)
Repo: (repo url, preferably https)

# At least one for new apps
Builds:
- versionName: '1.0'
versionCode: 1
commit: v1.0
subdir: app
# submodules: true
gradle:
- yes
# output: some.apk
# prebuild: sed -i -e

# For a complete list of possible flags, see the manual

# MaintainerNotes: |-
# Here go the notes to take into account for future updates, builds, etc.
# Will be published in the wiki if present.

# The following options are described at this location:
# https://f-droid.org/docs/Build_Metadata_Reference/#UpdateCheckMode

AutoUpdateMode: Version v%v
UpdateCheckMode: Tags v\d+\.\d+(\.\d+)?
CurrentVersion: 0.10.2
CurrentVersionCode: 102

配置项说明:
https://f-droid.org/docs/Build_Metadata_Reference/

2.4 构建

fdroid readmeta
fdroid rewritemeta 包名
fdroid checkupdates 包名
fdroid lint 包名
fdroid build -v -l 包名

当出现以下内容时,表示构建成功

image-20200822114414145

2.5 提交

a、Fork fdroiddata仓库

b、将本地的fdroiddata上传到自己的gitlab的fdroiddata仓库中

c、打开官方数据仓库,创建合并请求

image-20200822144647928 image-20200822144945516

然后根据类型,升级还是新增app,选择模版

image-20200822153730618

Tip: 申请合并之前先在自己的仓库的CICD中看看能否正常打包,如果能正常编译,一般合并都能通过

三、常见问题

3.1 Build metadata git repo has uncommited changes!

参考地址:https://forum.f-droid.org/t/checkupdate-error-uncommited-changes/7116

解决:

增加--allow-dirty参数

fdroid checkupdates 包名 --allow-dirty

3.2 VCS error while building app com.lyy.keepassa: Git checkout of ‘v1.1’ failed

解决:

检查{包名}.yml文件中的commit字段是否在git commit 中存在,一般填你需要打包的版本的git hash

image-20200822133712080

在github上可直接复制。

image-20200822133801654

3.3 Build Error: gradlew-fdroid no such file

image-20200821163233260

参考地址:https://forum.f-droid.org/t/build-error-gradlew-fdroid-no-such-file/5601

解决:

1、clone git clone https://gitlab.com/fdroid/fdroiddata.git

2、将gradlew-fdroid创建一个替身,并将提升拷贝到提示文件找不到的目录中

3、将替身的权限设置为

chmod +x gradlew-fdroid

3.4 sha256sum: command not foun

参考地址:https://unix.stackexchange.com/questions/426837/no-sha256sum-in-macos
解决:

brew install coreutils

然后添加环境变量

vim ~/.zshrc
# 添加下面行
export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"

# 退出vim,并更新环境变量
source ~/.zshrc

3.5 ERROR: Found unknown maven repo

如:阿里云的maven仓库,将其仓库改为https的

maven {
url 'https://maven.aliyun.com/repository/public/'
}

这是使用了非公用仓库的问题,f-droid无法验证这些仓库中的软件是否是免费软件
解决:
修改gradle文件,将这些仓库屏蔽了
或修改../fdroidserver/fdroidserver/scanner.py源码,在allowed_repos中增加你的仓库地址

image-20200822100716930

3.6 Found usual suspect ‘com.tencent.bugly’

原因是bugly是非自由软件

image-20200822101030593

解决:

a、创建fdroid的渠道

image-20200822140620123

b、使用spi机制将需要使用的非自由软件抽出来,只有非f-droid渠道才动态加载那些非自由软件的库

c、grade 中使用{渠道}Implementation的方式动态加载不同的渠道的库,如我这,只有debugrelease才加载bugly的库,f-droid渠道不加载这两个库

image-20200822140639868

d、编辑包名.yml配置文件,指定需要编译的渠道,也就是第一步中创建的渠道fdroid,然后配置rm模块,删除非自由软件的module

image-20200822125729751

e、在代码中根据渠道名动态加载不同渠道的库

image-20200822140744211

3.6 Unexpected version/version cod

检查包名.yml中配置的版本名和版本号是否和app/build.gradle中的一至。

注意,如果你使用的是渠道,检查渠道配置中是否添加了versionNameSuffix "-fdroid" 渠道后缀,如果有的话,包名.yml的versionName也需要加上后缀名。

image-20200822141831841

参考地址

https://gitlab.com/fdroid/fdroiddata/-/blob/master/CONTRIBUTING.md
https://f-droid.org/docs/Submitting_to_F-Droid_Quick_Start_Guide/