trime同文输入法是基于rime输入法引擎面向Android平台的一款开源高度可定制化输入法应用,提到trime就不得不先了解下rime。
rime并不是一个输入法应用,而是经过巧妙设计能够满足丰富定制化的输入法引擎。
大约是2009年由佛振大佬发起项目,起初是在linux平台开发使用,配套的前端为ibus-rime(中州韵),后经多人共同开发维护,逐渐支持多平台,Rime前端汇总:
Frontend | Os | Code | Download |
---|---|---|---|
Weasel (小狼毫) | Windows | rime/weasel | link |
rime-gits | Windows | lotem/rime-gits | link |
PIME | Windows | EasyIME/PIME | link |
Squirrel (鼠须管) | macOS | rime/squirrel | link |
XIME | macOS | stackia/XIMA | link |
iRime | iOS | jimmy54/iRime | App Store |
ibus-rime | Linux | rime/ibus-rime | link |
fcitx-rime | Linux | fcitx/fcitx-rime | link |
Trime (同文) | Android | osfans/trime | link |
其核心算法库都为librime,用来维护输入方案和词典文件的数据集,是输入法软件的后端。
由此trime作为Android平台同文输入法的前端,librime作为同文输入法的后端。
有兴趣的同学可以阅读佛振大佬的专访:一位匠人的中州韵——专访Rime输入法作者佛振(图灵访谈)
如上所述,trime等其他基于rime输入引擎的输入法,其核心算法是通用的,因此trime的特点特长就是rime的特点,粗略总结如下:
具体trime的这些特点怎样体现,如何配置,请见第三、第四章节。
github trime项目地址:https://github.com/osfans/trime
(这里我是在wsl linux环境下载的代码,也可以通过github客户端下载)
下载步骤如下:
#planA:
$git clone --recursive https://github.com/osfans/trime.git
#如果出现如下报错,因为墙的原因导致的clone失败,请尝试planB
Cloning into 'trime'...
fatal: unable to access 'https://github.com/osfans/trime.git/': Failed to connect to github.com port 443: Connection refused
#planB,使用ghproxy.com代理
#Step1,
$git clone https://ghproxy.com/https://github.com/osfans/trime.git
Cloning into 'trime'...
remote: Enumerating objects: 15640, done.
remote: Counting objects: 100% (1379/1379), done.
remote: Compressing objects: 100% (455/455), done.
remote: Total 15640 (delta 710), reused 1203 (delta 606), pack-reused 14261
Receiving objects: 100% (15640/15640), 27.65 MiB | 1.65 MiB/s, done.
Resolving deltas: 100% (8094/8094), done.
Checking out files: 100% (260/260), done.
#Step2,配置trime子模块url
#修改trime/.gitmodules,每条url前面加上https://ghproxy.com/
[submodule "OpenCC"]
path = app/src/main/jni/OpenCC
url = https://ghproxy.com/https://github.com/BYVoid/OpenCC.git
[submodule "snappy"]
path = app/src/main/jni/snappy
url = https://ghproxy.com/https://github.com/google/snappy.git
[submodule "boost"]
path = app/src/main/jni/boost
url = https://ghproxy.com/https://github.com/boostorg/boost.git
[submodule "librime"]
path = app/src/main/jni/librime
url = https://ghproxy.com/https://github.com/rime/librime.git
ignore = dirty
[submodule "libiconv"]
path = app/src/main/jni/libiconv
url = https://ghproxy.com/https://github.com/osfans/libiconv-gnu.git
[submodule "librime-lua"]
path = app/src/main/jni/librime-lua
url = https://ghproxy.com/https://github.com/hchunhui/librime-lua
ignore = dirty
[submodule "librime-lua-deps"]
path = app/src/main/jni/librime-lua-deps
url = https://ghproxy.com/https://github.com/hchunhui/librime-lua
branch = thirdparty
[submodule "librime-octagram"]
path = app/src/main/jni/librime-octagram
url = https://ghproxy.com/https://github.com/lotem/librime-octagram.git
[submodule "capnproto"]
path = app/src/main/jni/capnproto
url = https://ghproxy.com/https://github.com/capnproto/capnproto.git
[submodule "librime-charcode"]
path = app/src/main/jni/librime-charcode
url = https://ghproxy.com/https://github.com/rime/librime-charcode
#Step3
$cd trime
$git submodule update --init --recursive
#可能出现如下报错 (未报错则跳过Step4):
Cloning into '/mnt/g/project/github/trime/app/src/main/jni/librime/deps/glog'...
fatal: unable to access 'https://github.com/google/glog.git/': Failed to connect to github.com port 443: Connection refused
fatal: clone of 'https://github.com/google/glog.git' into submodule path '/mnt/g/project/github/trime/app/src/main/jni/librime/deps/glog' failed
Failed to clone 'deps/glog'. Retry scheduled
Cloning into '/mnt/g/project/github/trime/app/src/main/jni/librime/deps/googletest'...
fatal: unable to access 'https://github.com/google/googletest.git/': Failed to connect to github.com port 443: Connection refused
fatal: clone of 'https://github.com/google/googletest.git' into submodule path '/mnt/g/project/github/trime/app/src/main/jni/librime/deps/googletest' failed
Failed to clone 'deps/googletest'. Retry scheduled
Cloning into '/mnt/g/project/github/trime/app/src/main/jni/librime/deps/leveldb'...
fatal: unable to access 'https://github.com/google/leveldb.git/': Failed to connect to github.com port 443: Connection refused
fatal: clone of 'https://github.com/google/leveldb.git' into submodule path '/mnt/g/project/github/trime/app/src/main/jni/librime/deps/leveldb' failed
Failed to clone 'deps/leveldb'. Retry scheduled
Cloning into '/mnt/g/project/github/trime/app/src/main/jni/librime/deps/marisa-trie'...
fatal: unable to access 'https://github.com/s-yata/marisa-trie.git/': Failed to connect to github.com port 443: Connection refused
fatal: clone of 'https://github.com/s-yata/marisa-trie.git' into submodule path '/mnt/g/project/github/trime/app/src/main/jni/librime/deps/marisa-trie' failed
Failed to clone 'deps/marisa-trie'. Retry scheduled
Cloning into '/mnt/g/project/github/trime/app/src/main/jni/librime/deps/opencc'...
fatal: unable to access 'https://github.com/BYVoid/OpenCC.git/': Failed to connect to github.com port 443: Connection refused
fatal: clone of 'https://github.com/BYVoid/OpenCC.git' into submodule path '/mnt/g/project/github/trime/app/src/main/jni/librime/deps/opencc' failed
Failed to clone 'deps/opencc'. Retry scheduled
Cloning into '/mnt/g/project/github/trime/app/src/main/jni/librime/deps/yaml-cpp'...
fatal: unable to access 'https://github.com/jbeder/yaml-cpp.git/': Failed to connect to github.com port 443: Connection refused
fatal: clone of 'https://github.com/jbeder/yaml-cpp.git' into submodule path '/mnt/g/project/github/trime/app/src/main/jni/librime/deps/yaml-cpp' failed
Failed to clone 'deps/yaml-cpp'. Retry scheduled
Cloning into '/mnt/g/project/github/trime/app/src/main/jni/librime/deps/glog'...
fatal: unable to access 'https://github.com/google/glog.git/': Failed to connect to github.com port 443: Connection refused
fatal: clone of 'https://github.com/google/glog.git' into submodule path '/mnt/g/project/github/trime/app/src/main/jni/librime/deps/glog' failed
Failed to clone 'deps/glog' a second time, aborting
Cloning into '/mnt/g/project/github/trime/app/src/main/jni/snappy/third_party/benchmark'...
fatal: unable to access 'https://github.com/google/benchmark.git/': Failed to connect to github.com port 443: Connection refused
fatal: clone of 'https://github.com/google/benchmark.git' into submodule path '/mnt/g/project/github/trime/app/src/main/jni/snappy/third_party/benchmark' failed
Failed to clone 'third_party/benchmark'. Retry scheduled
Cloning into '/mnt/g/project/github/trime/app/src/main/jni/snappy/third_party/googletest'...
fatal: unable to access 'https://github.com/google/googletest.git/': Failed to connect to github.com port 443: Connection refused
fatal: clone of 'https://github.com/google/googletest.git' into submodule path '/mnt/g/project/github/trime/app/src/main/jni/snappy/third_party/googletest' failed
Failed to clone 'third_party/googletest'. Retry scheduled
Cloning into '/mnt/g/project/github/trime/app/src/main/jni/snappy/third_party/benchmark'...
fatal: unable to access 'https://github.com/google/benchmark.git/': Failed to connect to github.com port 443: Connection refused
fatal: clone of 'https://github.com/google/benchmark.git' into submodule path '/mnt/g/project/github/trime/app/src/main/jni/snappy/third_party/benchmark' failed
Failed to clone 'third_party/benchmark' a second time, aborting
Failed to recurse into submodule path 'app/src/main/jni/librime'
Failed to recurse into submodule path 'app/src/main/jni/snappy'
#Step4 处理报错信息
#根据上述报错信息,修改相应子模块.gitmodules,每条url前面加上https://ghproxy.com/
#上述报错修改文件有:
#trime/app/src/main/jni/librime/.gitmodules
#trime/app/src/main/jni/snappy/.gitmodules
#trime/app/src/main/jni/librime/deps/leveldb/.gitmodules (第二次编译报错后修改)
#例如,trime/app/src/main/jni/snappy/.gitmodules修改后如下:
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://ghproxy.com/https://github.com/google/googletest.git
[submodule "third_party/benchmark"]
path = third_party/benchmark
url = https://ghproxy.com/https://github.com/google/benchmark
#更新.gitmodules配置并重新下载代码
$git submodule sync --recursive && git submodule update --init --recursive
#未报错则代码下载成功~(由于trime导入了众多第三方库,使得整个项目(V3.2.8)达到了1.97G。)
Step 5,修改trime源码文件格式为unix
由于下来的代码文件格式不统一,在linux编译时会导致奇奇怪怪的报错,保险起见将整个项目文件统一改为unix格式
trime$for x in $(find . -type f);do sudo dos2unix $x $x;done
注意
:由于trime项目(V3.2.8)有1.97G,因此dos2unix会花点时间,请耐心等待~
1、Android Studio 导入trime
File -> Open -> 选择trime
2、根据trime/app/build.gradle配置SDK,NDK,Cmake
android {
compileSdkVersion 31
ndkVersion "24.0.8215888" #在SDK Manager安装NDK 24.0.8
...
targetSdkVersion 29 #SDK Manager 安装SDK 29
...
externalNativeBuild {
cmake {
version "3.22.1" #SDK Manager 安装Cmake3.22.1
}
}
3、无其他报错则选择run,进行编译
若一切顺利,编译生成的apk路径位于:trime/app/build/intermediates/apk/debug/trime-3.2.9-arm64-v8a-debug.apk
并在devices中安装上了【同文输入法】;若有报错,参考 5.1编译报错小结。
⌵ trime #同文输入法根目录
⌵ app #android 及jni代码
| ⌵ build #编译生成文件
| | ⌵ intermediates/apk/debug #编译生成的apk路径
| | trime-3.2.9-arm64-v8a-debug.apk #编译出的apk
| ⌵ src/main #trime android 前端源码
| | ⌵ assets/rime #默认配置文件夹
| | ⌵ backgrounds #存放背景图片文件夹,用于定制化背景样式
| | | ⌵ myBcakgrounds #定制化背景图片存放路径,在trime.yaml -> background_folder: myBackgrounds配置
| | | background1.png #背景图片,可在trime.yaml->key_back_color、hilited_key_back_color等字段配置
| | | background2.png
| | | ...
| | ⌵ fonts #存放字体文件夹
| | | front1.ttf #front1.ttf字符文件,在trime.yaml->candidate_font、comment_font等字段配置
| | | front2.ttf
| | | ...
| | opencc #简繁转换组件
| | tongwenfeng.trime.yaml #定制化主题文件
| | trime.yaml #默认主题文件,可配置键盘布局,字体,颜色,间距等等键盘UI内容。
| ⌵ java/com/osfans/trime #trime android 前端java核心代码
| | core
| | data
| | ime
| | ui
| | util
| | TrimeApplication.kt
| | TrimeImeService.kt
| ⌵ jni #trime jni文件夹,各类库
| | boost
| | capnproto
| | cmake
| | libiconv
| | librime
| | librime_jni
| | librime-charcode
| | librime-lua
| | librime-lua-deps
| | librime-octagram
| | OpenCC
| | snappy
| | CMakeLists.txt
| res
| AndroidManifest.xml
| ic_app_icon-playstore.png
arwork
build
gradle/wrapper
script
⌵ sdcard/rime
⌵ build
|
default.yaml
default.custom.yaml
luna_pinyin.dict.yaml
luna_pinyin.schema.yaml
luna_pinyin.userdb
korean.dict.yaml
korean.schema.yaml
korean.userdb
...
installation.yaml
opencc
trime.yaml
trime.custom.yaml
user.yaml
Link | Content |
---|---|
Rime官网 | rime介绍 |
Rime前端汇总 | Windows、macOs、iOs、Linux、Android前端代码及应用下载地址 |
Rime输入方案设计书 | rime工作原理、设计思想、数据文件作用及分布、组件工作流程、patch定制 |
Rime的独门绝技 | 拼写运算、按键响应自定义、对输入处理流程的建模 |
配置同文输入法–简易索引 | 文件说明 |
Rime贴吧 | rime交流讨论 |
致第一次安装 RIME 的你之修订版 | 繁简转换、字体颜色配置、快捷键修改、标点符号定制等 |
佛振教你写 Rime 输入方案之辅助码的作法 | 辅助码配置 |
定制指南 | 定制候选页、标点符号、方案、组合键、字体字号、配色方案、模糊音、反查等 |
Schema.yaml详解 | schema.yaml输入方案的开关、输入引擎等细项配置、dict.yaml词典配置 |
trimer小知识 Yaml文件开头注释是什么意思? 配置文件中的一些yaml语法 |
yaml开头注释 yaml介绍、数据表示/引用方式、补丁注意事项等 |
配置同文输入法–trime.yaml详解 | trime.yaml 中style、字体、尺寸、悬浮窗口、颜色等 |
案例参考 五笔双键配置案例详解(一) 准备篇 五笔双键配置案例详解(二) 添加一个输入方案 五笔双键配置案例详解(三) 用模糊音实现双键转换 五笔双键配置案例详解(四) 实现手机上的双键键盘 |
案例五笔双拼配置教程 |
正则表达式 Perl 正则表达式语法 正则表达式(菜鸟教程) 正则表达式 |
正则表达式语法及使用介绍 |
//待整理后贴上
4.3.1 dict.yaml文件规范
//待整理后贴上
将需要预置的配置文件放入trime/app/src/main/assets/rime
//补充完善中…
Build file 'G:\project\github\trime\build.gradle' line: 17
Plugin [id: 'com.android.application', version: '7.2.2', apply: false] was not found in any of the following sources:
* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.android.application', version: '7.2.2', apply: false] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.android.application:com.android.application.gradle.plugin:7.2.2')
Searched in the following repositories:
Gradle Central Plugin Repository
Google
MavenRepo <97 internal lines>
at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:116)
at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:42) <82 internal lines>
问题原因:所配置的gradle版本在本地配置的gradle仓库中未找到。
解决方案:
修改settings.gradle
pluginManagement {
repositories {
+ maven { url "https://jitpack.io" }
+ maven { url 'https://maven.aliyun.com/repository/releases' }
+ maven { url 'https://maven.aliyun.com/repository/jcenter' }
+ maven { url 'https://maven.aliyun.com/repository/google' }
+ maven { url 'https://maven.aliyun.com/repository/central' }
+ maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
+ maven { url 'https://maven.aliyun.com/repository/public' }
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
+ maven { url "https://jitpack.io" }
+ maven { url 'https://maven.aliyun.com/repository/releases' }
+ maven { url 'https://maven.aliyun.com/repository/jcenter' }
+ maven { url 'https://maven.aliyun.com/repository/google' }
+ maven { url 'https://maven.aliyun.com/repository/central' }
+ maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
+ maven { url 'https://maven.aliyun.com/repository/public' }
google()
mavenCentral()
}
}
(参考:Gradle问题篇】Plugin [id: ‘com.android.application‘, version: ‘7.x.x‘, apply: false] was not found i…)
[CXX1300] CMake '3.22.1' was not found in SDK, PATH, or by cmake.dir property.
问题原因:未找到Cmake 3.22.1
解决方案:在Android Studio -> File -> Settings ->System Settings -> Android SDK -> SDK Tools中下载安装相应版本的Cmake组件。如果行不通可在Cmake官网下载后手动安装和配置。
Cmake版本定义在trime/app/build.gradle
externalNativeBuild {
cmake {
version "3.22.1"
}
}
(参考:Android Studio Cmake升级至最新版本)
[320/320] Linking CXX shared library G:\project\github\trime\app\build\intermediates\cxx\Debug\383b5c5f\obj\arm64-v8a\librime_jni.so
FAILED: G:/project/github/trime/app/build/intermediates/cxx/Debug/383b5c5f/obj/arm64-v8a/librime_jni.so
cmd.exe /C "cd . && D:\sdk\ndk\24.0.8215888\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-android21 --sysroot=D:/sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -fexceptions -frtti -stdlib=libc++ -g -fno-limit-debug-info -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Qunused-arguments -Wl,--no-undefined -shared -Wl,-soname,librime_jni.so -o G:\project\github\trime\app\build\intermediates\cxx\Debug\383b5c5f\obj\arm64-v8a\librime_jni.so librime_jni/CMakeFiles/rime_jni.dir/key_table.cc.o librime_jni/CMakeFiles/rime_jni.dir/levers.cc.o librime_jni/CMakeFiles/rime_jni.dir/opencc.cc.o librime_jni/CMakeFiles/rime_jni.dir/rime_jni.cc.o librime/lib/librime.a -llog OpenCC/src/libopencc.a boost/libs/filesystem/libboost_filesystem.a boost/libs/iostreams/libboost_iostreams.a D:/sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/lib/aarch64-linux-android/21/libz.so boost/libs/locale/libboost_locale.a libiconv.a boost/libs/random/libboost_random.a boost/libs/serialization/libboost_serialization.a boost/libs/thread/libboost_thread.a boost/libs/date_time/libboost_date_time.a boost/libs/exception/libboost_exception.a boost/libs/container/libboost_container.a boost/libs/atomic/libboost_atomic.a boost/libs/chrono/libboost_chrono.a librime/deps/yaml-cpp/libyaml-cppd.a librime/deps/leveldb/libleveldb.a snappy/libsnappy.a -pthread OpenCC/deps/marisa-0.2.6/libmarisa.a -static-libstdc++ -latomic -lm && cd ."
ld: error: undefined symbol: rime_require_module_lua()
>>> referenced by rime_jni.cc:9 (G:/project/github/trime/app/src/main/jni/librime_jni\rime_jni.cc:9)
>>> librime_jni/CMakeFiles/rime_jni.dir/rime_jni.cc.o:(declare_librime_module_dependencies())
ld: error: undefined symbol: rime_require_module_charcode()
>>> referenced by rime_jni.cc:10 (G:/project/github/trime/app/src/main/jni/librime_jni\rime_jni.cc:10)
>>> librime_jni/CMakeFiles/rime_jni.dir/rime_jni.cc.o:(declare_librime_module_dependencies())
ld: error: undefined symbol: rime_require_module_octagram()
>>> referenced by rime_jni.cc:11 (G:/project/github/trime/app/src/main/jni/librime_jni\rime_jni.cc:11)
>>> librime_jni/CMakeFiles/rime_jni.dir/rime_jni.cc.o:(declare_librime_module_dependencies())
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
问题原因:rime_require_module_lua()、rime_require_module_charcode()、rime_require_module_octagram()未实现。
解决方案:注释该无效引用
trime/app/src/main/jni/librime_jni/rime_jni.cc
JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM* jvm, void* reserved)
{
GlobalRef = new GlobalRefSingleton(jvm);
+// declare_librime_module_dependencies();
return JNI_VERSION_1_6;
}
问题原因:无法安装debug apk
解决方案:adb install -t xxx.apk
Settings -> 系统 -> 语言和输入法 -> 虚拟键盘 -> 同文输入法 -> 无法打开同文输入法的设置
02-15 04:07:25.952 1639 2314 I ActivityTaskManager: START u0 {act=android.intent.action.MAIN cmp=com.osfans.trime/.settings.PrefMainActivity} from uid 1000
02-15 04:07:25.958 17765 17765 D InputMethodPreference: IME's Settings Activity Not Found
02-15 04:07:25.958 17765 17765 D InputMethodPreference: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.osfans.trime/com.osfans.trime.settings.PrefMainActivity}; have you declared this activity in your AndroidManifest.xml?
02-15 04:07:25.958 17765 17765 D InputMethodPreference: at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2062)
问题原因:trime settingsActivity指向旧Activity,需更新
解决方案:
trime/app/src/main/res/xml/method.xml
+ android:settingsActivity="com.osfans.trime.ui.main.PrefMainActivity">
选择方案时出现如下提示:
问题原因:缺少默认方案配置文件default.yaml 或default.custom.yaml
。
trinket:/storage/emulated/0/rime # ls -al
total 264
drwxrwx--x 4 root sdcard_rw 3488 2022-02-14 23:01 .
drwxrwx--x 13 root sdcard_rw 3488 2022-02-14 23:01 ..
drwxrwx--x 2 root sdcard_rw 3488 2022-02-14 23:01 build
-rw-rw---- 1 root sdcard_rw 0 2022-02-14 23:01 default.custom.yaml
-rw-rw---- 1 root sdcard_rw 116 2022-02-14 23:01 installation.yaml
drwxrwx--x 2 root sdcard_rw 3488 2022-02-14 23:09 opencc
-rw-rw---- 1 root sdcard_rw 184697 2022-02-14 23:01 tongwenfeng.trime.yaml
-rw-rw---- 1 root sdcard_rw 67085 2022-02-14 23:01 trime.yaml
解决方案:
将default.yaml 、default.custom.yaml(可为空)放入【配置管理->共享文件夹】指定路径
default.yaml位于:trime\app\src\main\jni\librime\data\minimal\default.yaml
default.custom.yaml位于trime\app\src\main\assets\rime\default.custom.yaml或自己创建空文件
再次选择方案则正常
部署某方案后,调出输入法发现侯选栏为空,无法正常给出候选词,选择字母直接上屏
问题原因:punctuator
错误配置为symbols
解决方案:将punctuator配置为default
punctuator:
import_preset: default
option(ENABLE_LOGGING "" OFF)
trime/app/src/main/jni/librime/src/rime/common.h
#ifdef RIME_ENABLE_LOGGING //如果定义了RIME_ENABLE_LOGGING则采用glog打印
#define GLOG_NO_ABBREVIATED_SEVERITIES
#include
#else
#include "no_logging.h" //否则关闭log,默认走这个case
#endif // RIME_ENABLE_LOGGING
trime/app/src/main/jni/librime/src/rime/no_logging.h
#define RIME_NO_LOG true ? (void) 0 : rime::Voidify() & rime::VoidLogger().stream() //默认关闭log,改为false也无打印
#define LOG(severity) RIME_NO_LOG
#define VLOG(verboselevel) RIME_NO_LOG
#define LOG_IF(severity, condition) RIME_NO_LOG
#define LOG_EVERY_N(severity, n) RIME_NO_LOG
#define LOG_IF_EVERY_N(severity, condition, n) RIME_NO_LOG
#define LOG_ASSERT(condition) RIME_NO_LOG
在common.h中使用 android/log.h输出日志打印
trime/app/src/main/jni/librime/src/rime/common.h
#ifdef RIME_ENABLE_LOGGING
#define GLOG_NO_ABBREVIATED_SEVERITIES
#include
#else
#include "no_logging.h"
+//#define TAG "librime"
+#ifdef ANDROID
+#include
+#define ALOGE(fmt, ...) __android_log_print(ANDROID_LOG_ERROR, TAG, fmt, ##__VA_ARGS__)
+#define ALOGI(fmt, ...) __android_log_print(ANDROID_LOG_INFO, TAG, fmt, ##__VA_ARGS__)
+#else
+#define ALOGE printf
+#define ALOGI printf
+#endif
#endif // RIME_ENABLE_LOGGING
添加打印
trime/app/src/main/jni/librime/src/rime/engine.cc
+#define TAG "engine"
.....
bool ConcreteEngine::ProcessKey(const KeyEvent& key_event) {
DLOG(INFO) << "process key: " << key_event;
+ ALOGI("ProcessKey keycode=%d", key_event.keycode());
ProcessResult ret = kNoop;
输出日志:
engine : RimeProcessKey keycode=113