Skip to content

android

Yi Xing edited this page Feb 14, 2024 · 8 revisions

Running SilverDict on Android

The mobile app

See SilverDict-mobile.

The mobile app is independent of the web app, though sharing the same back-end and much code. It has all the functionality you would expect from a dictionary app and looks more polished than the web app.

After start-up, go to the settings and set the server address. The default is http://localhost:2628, which is the address of the server running on the same device. To connect to a server running on another device in the local network, you need to find out its IP address and change localhost to that one. Or you can also deploy the server on the Internet and connect to it from anywhere.

A guide to the UI

Query

  • When the search bar is empty, history is displayed; otherwise suggestions are displayed.
  • Tap on the bookshelf icon to select groups or jump to a specific dictionary.
  • Tap on a word to search for it. Screenshot_1697784182
  • If you see little boxes or question marks, please download additional fonts in the settings page (see below).

Library

Dictionaries
  • Tap on one to rename or delete
  • Long-press (drag-and-drop) to reorder. Their relative order will be reflected in all groups.
Groups
  • Long-press on Languages/Dictionaries to edit.
  • Drag and drop to reorder.
Sources

No 'hidden' features here.

Settings

  • Additional fonts: here you can select which scripts (instead of languages) you would like to download additional fonts for. They will be downloaded and cached next time you start a new query.

Running the server on Android

The server is a Python application, so it can be run on Android using Termux. After installation, first run termux-setup-storage to grant access to the external storage. Then download the archive SilverDict.zip from the releases page and unzip it somewhere. Now run the bash script termux_setup.sh inside the unzipped folder. It will install the necessary packages, set up a default dictionary source at /sdcard/Documents/Dictionaries and create two shortcuts (see below). During the process, pkg may prompt you to choose between some options. Just press 'enter' to select the default in each case.

Now you can run the server with python server/server.py and it will listen at 127.0.0.1:2628. A convenient way to start the server is to use the Termux plug-in Termux:Widget: add the widget to the home screen and put into ~/.shortcuts a bash script like this:

#!/bin/bash
python /storage/emulated/0/SilverDict/server/server.py

If you set SilverDict up with the bash script, two shortcuts SilverDict-Start.sh and SilverDict-Stop.sh will be created in ~/.shortcuts. The first one acquires a wakelock, starts the server in the background, saving the log to ~/.silverdict/server.log; the second stops the server and release the acquired wakelock.

Note: the installation script installs the legacy PyHunspell. Sibel is recommended as an alternative. It doesn't install Xapian or the Python bindings. To use full-text search, first install the Xapian packages with pkg and grab the source code of xapian-bindings and run the following commands:

pkg install libxapian xapian-tools binutils-is-llvm
pip install sphinx

export CFLAGS=$(python-config --cflags)
export CXXFLAGS=$(python-config --cflags)
export LDFLAGS=$(python-config --ldflags)
export LIBS=$(python-config --libs)
./configure --prefix=$PREFIX --with-python3
make
make install

For geeky users who know the command line

Indexing dictionaries and creating the ngram index is a time-consuming process, so it is recommended to do it on a PC and then copy the files to the Android device. Follow the steps below to do that.

  1. Rename to your existing SilverDict directories (~/.silverdict and ~/.cache/SilverDict) to something else, e.g. .silverdict.old.
  2. Start the server with python server.py.
  3. Put all dictionaries you'd use on Android into ~/.silverdict/source.
  4. Run curl http://localhost:2628/api/management/scan to index the dictionaries, or do it in the web UI.
  5. Run curl http://localhost:2628/api/management/create_ngram_table to create the ngram index, or do it in the web UI, if you want to use the ngram search (both-sides expansion).
  6. Change ~/.silverdict/preferences.yaml to your liking.
  7. Change the filenames in ~/.silverdict/dictionaries.yaml to reflect their paths on Android.
  8. Fix any symbolic links in .silverdict/cache/SilverDict.
  9. Move ~/.silverdict and ~/.cache/SilverDict to Termux.

Then you are all done.

FAQ

Why is the server not responding/very slow?

Try turning off 'battery optimisation' for Termux, which interferes with the server's ability to run in the background. Here's how to do it (on a Samsung Galaxy with Android 12): Settings -> Apps -> Termux -> Battery -> Unrestricted.

My phone boasts better specs than my PC, but SilverDict is slower on the former.

See this discussion.

In short, it is probably due to the inherent limitation of the Android platform and the Arm architecture.