Skip to content

Commit

Permalink
Write Android build guide; fixed:
Browse files Browse the repository at this point in the history
error when LANG=None
initial config have incorrect strength/energy
adjustments to docs and scripts
  • Loading branch information
NaitLee committed Sep 11, 2022
1 parent cbfd904 commit 70cdd84
Show file tree
Hide file tree
Showing 17 changed files with 516 additions and 100 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ cat-printer*.zip
cat-printer-sha256-*.txt
# bleak, the bare pip package as a folder
build-common/bleak
# python embeddable package, with bleak_winrt inside
# python embeddable package, historically with bleak_winrt inside
build-common/python-win32*
build-common/python-w32*
# bleak_winrt is now outside python-w32
build-common/bleak_winrt
# dev config
config.json
# dev backup
Expand Down
52 changes: 30 additions & 22 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,81 @@

Thank you for looking into this project.

Let's keep short & be positive:
Lets keep short & be positive:

## Communication

1. Use Issue for a potential bug and Discussion for feature request.
But do whichever you feel better. This is just a hint.

2. Consider you're interacting with the whole world. Use English.
But you may also use another if you're confident enough that someone in community could understand it & help you.
2. Consider youre interacting with the world. Use English.
But you may also use another if youre confident enough that someone in community could understand it & help you.

## Sharing

Let's just call it "sharing". You can of course share your experience of this project with your friends, online or offline.
Lets just call it sharing. You can of course share your experience of this project with your friends, online or offline.

This is also one step toward Software Freedom.

But note that, if necessary, disclaim that you have no relationship with any of the printer vendors. Neither the author(s) here.

Also for avoiding potential hassle, don't mention the "original" or "official" app(s).
Also for avoiding potential hassle, dont mention the original or official app(s).

## Translating

See [i18n.md](./i18n.i18n/i18n.md) for what to do.

As a special note, try to correctly use marks & symbols:

- Use `“”‘’` in place of `"'`, except when in a terminal
- Localize marks right, e.g. `“”` in English shall correspond to `„“` in German or `»«` in French, etc.
- Keep spaces consistent, e.g. `“”` will be rendered full-width in CJK font, so leave no space around them in CJK context

Hint: a Keyboard Layout other than default maybe helpful, especially those with AltGr/Level 3 Shift keys.

You can seek for help here, to do grammar extensions & leftovers.

## Coding

1. Whether big or small, pull requests are welcome.
1. Any contribution welcome.

2. See file `TODO` for what's next. But don't limit imagination, do whatever you think is useful.
2. See file `TODO` for whats next. But dont limit imagination, do whatever you think is useful.

3. Keep the existing "way". Here are details:
3. Keep the existing way. Here are details:

- Think about the Unix Philosophy before doing. Try to suck less.
- Follow coding style & naming convention.
- Think about the use cases: Web UI and/or command-line backend, average and/or advanced users
- Test the code well. Document if necessary.
- Don't forget internationalization & necessary accessibility features.
- Dont forget internationalization & necessary accessibility features.

4. Finally, "rules". Just skim these, don't feel pressure as I trust you won't mistake:
4. Finally, rules. Just skim these, dont feel pressure as I trust you wont mistake:

- Don't leak development/test cache/junk to the repo. Please.
And never put pictures/executables/any big binary to this repo. Try uploading in an issue/discussion instead.
- Don't connect to an online service to fetch resource.
If necessary, ask the user first.
- Don’t leak development/test cache/junk to the repo. Please.
And never put pictures/executable/any big binary to this repo. Try uploading in an issue/discussion instead.
- No more 3rd-party blackbox dependencies/assets, without explaining & using its most functionality.
Consider using existing system programs, or implementing enough from scratch.
If that really happened, make it optional (i.e. don't fail the load just for its non-existence),
And don't push the dependency source code.
For big dependencies, if you really love it, it's suggested to fork this repo & develop in your own way.
- Don't make anti-features. Don't be someone yourself dislike most.
If that really happened, make it optional (i.e. don’t fail the load just for its non-existence),
And don’t push the dependency source code.
For big dependencies, if you really love it, it’s suggested to fork this repo & develop in your own way.
- Don’t connect to an online service to fetch resource.
If necessary, ask the user first. Again, such functionality shall be elsewhere.
- Don’t make anti-features. Don’t be someone yourself dislike most.
Examples:
- You can do: simple borders & stickers, scribbling, simple PostScript interpreter, another common printing protocol
- Considering previous rule, discuss first: Bar/QR Code, formula, Native (non-Web) UI
- You shouldn't do: Way too fancy UI/editor, Cloud storage, camera integration & OCR
- You shouldnt do: Way too fancy UI/editor, Cloud storage, camera integration & OCR
- Never consider: online account, non-free service integration, analysis/telemetry
- Please don't violate the license (GNU General Public License version 3)
- Please dont violate the license (GNU General Public License version 3)
Modification to existing files are released under its existing license,
mostly GPL3 or CC0, according to statement in readme.
- If you want to preserve your copyright & use other license, create new file(s) for your work.
But, never release your code under any non-free license.

5. You can take any part of this project to do something else. It's also contribution! Let the ideas spread!
5. You can take any part of this project to do something else. Its also contribution! Let the ideas spread!

## Footnote

Nothing could go wrong. Trust yourself & try your best.

Let's together build it better. Thank you.
Lets together build it better. Thank you.
7 changes: 4 additions & 3 deletions build-android/0-build-android.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/sh
export version=`cat ../version`
version=`cat ../version`

p4a apk --private .. --dist_name="cat-printer" --package="io.github.naitlee.catprinter" --name="Cat Printer" \
--icon=icon.png --version=$version --bootstrap=webview --window --requirements=android,pyjnius,bleak \
--icon=icon.png --version=$version --bootstrap=webview --window --requirements="`cat build-deps.txt`" \
--blacklist-requirements=sqlite3,openssl --port=8095 --arch=arm64-v8a --blacklist="blacklist.txt" \
--presplash=blank.png --presplash-color=black --add-source="advancedwebview" --orientation=user \
--permission=BLUETOOTH --permission=BLUETOOTH_SCAN --permission=BLUETOOTH_CONNECT \
--permission=BLUETOOTH_ADMIN --permission=ACCESS_FINE_LOCATION --permission=ACCESS_COARSE_LOCATION
--permission=BLUETOOTH_ADMIN --permission=ACCESS_FINE_LOCATION --permission=ACCESS_COARSE_LOCATION $@
7 changes: 4 additions & 3 deletions build-android/3-formal-build.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/sh
export version=`cat ../version`
version=`cat ../version`

rm -rf "dist"
unzip -q "../cat-printer-bare-$version.zip"
mv "cat-printer" "dist"
p4a apk --private "dist" --dist_name="cat-printer" --package="io.github.naitlee.catprinter" --name="Cat Printer" \
--icon=icon.png --version="$version" --bootstrap=webview --window --requirements=android,pyjnius,bleak \
--icon=icon.png --version="$version" --bootstrap=webview --window --requirements="`cat build-deps.txt`" \
--blacklist-requirements=sqlite3,openssl --port=8095 --arch=arm64-v8a --release \
--presplash=blank.png --presplash-color=black --add-source="advancedwebview" --orientation=user \
--permission=BLUETOOTH --permission=BLUETOOTH_SCAN --permission=BLUETOOTH_CONNECT \
--permission=BLUETOOTH_ADMIN --permission=ACCESS_FINE_LOCATION --permission=ACCESS_COARSE_LOCATION
--permission=BLUETOOTH_ADMIN --permission=ACCESS_FINE_LOCATION --permission=ACCESS_COARSE_LOCATION $@
15 changes: 10 additions & 5 deletions build-android/4-sign.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#!/bin/sh
export version=`cat ../version`
export unsigned_apk=cat-printer-release-unsigned-$version-.apk
export signed_apk=cat-printer-android-$version.apk
$ANDROIDSDK/build-tools/32.0.0/zipalign 4 $unsigned_apk $signed_apk
$ANDROIDSDK/build-tools/32.0.0/apksigner sign --ks $1 $signed_apk
version=`cat ../version`
unsigned_apk=cat-printer-release-unsigned-$version-.apk
signed_apk=cat-printer-android-$version.apk

if {
$ANDROIDSDK/build-tools/*/zipalign 4 $unsigned_apk $signed_apk;
$ANDROIDSDK/build-tools/*/apksigner sign --ks $1 $signed_apk;
}; then
echo "Complete! Moving APK..."
mv $signed_apk $signed_apk.idsig ../
rm *.apk
fi
8 changes: 8 additions & 0 deletions build-android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# Build for Android

The build environment shall be setup manually, since it’s a bit complex, and I’m not so familiar with Android development.

See [Manual Steps](./manual-steps.md) to get started.

Android enthusiasts may help with automated build procedure, then for example F-Droid release would be possible.
1 change: 1 addition & 0 deletions build-android/build-deps.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
async_timeout,typing-extensions,android,pyjnius,bleak
32 changes: 32 additions & 0 deletions build-android/fix-ndk-execs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
''' Some casual code to fix those alias files
in Android NDK llvm bin to symlinks instead
'''

import os
import sys

MAX_LENGTH = 256

ndk_path = sys.argv[1] if len(sys.argv) > 1 else input('Android NDK path: ')

bin_path = os.path.join(ndk_path, 'toolchains/llvm/prebuilt/linux-x86_64/bin/')

workdir = os.getcwd()

os.chdir(bin_path)

try:
for path in os.listdir():
# with this encoding it won't error when reading binary
file = open(path, 'r', encoding='iso8859-1')
data = file.read(MAX_LENGTH).strip()
file.close()
# inside the alias file is the filename that should be executed
# let's see if there is one
if os.path.isfile(data):
print('Will fix %s -> %s' % (path, data))
#os.remove(path)
os.rename(path, path + '.alias')
os.symlink(data, path)
finally:
os.chdir(workdir)
Loading

0 comments on commit 70cdd84

Please sign in to comment.