-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Work manager integration #119
Changes from 14 commits
42b6324
f1ef772
4860e43
831403a
f07c67d
5f489b5
2864e56
a0f1097
d9d785d
8f4b901
d02edc0
83b796d
426ac58
f2db879
ac09bf8
8fc35e8
290ec04
0703d2a
3d5c953
bb44d03
679f489
7fb01af
ebab523
a509b4f
9e60047
002a696
04e91a9
f890001
cd06417
8276578
c5b0f14
3dad265
803f639
14a7159
f24b159
ffaffd2
8de5db7
897bb77
7e74447
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ needs-android-dirs: | |
|
||
# Clear out apks | ||
clean: | ||
- rm -rf dist/*.apk src/kolibri tmpenv | ||
- rm -rf dist/*.apk src/kolibri tmpenv src/*.pyc | ||
|
||
deepclean: clean | ||
$(PYTHON_FOR_ANDROID) clean_dists | ||
|
@@ -72,9 +72,25 @@ src/kolibri: clean | |
# patch Django to allow migrations to be pyc files, as p4a compiles and deletes the originals | ||
sed -i 's/if name.endswith(".py"):/if name.endswith(".py") or name.endswith(".pyc"):/g' src/kolibri/dist/django/db/migrations/loader.py | ||
|
||
.PHONY: check-android-clean | ||
check-android-clean: | ||
@git diff --quiet --exit-code python-for-android || (echo "python-for-android directory has uncommitted changes in the working tree" && exit 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this just displayed as a warning? Or does the Probably I'm also misinterpreting these new make targets. Could you add a one-line comment on each as to what it does? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can build while the Java files are being actively edited - we just can't reimport from the bootstrap while that is the case. Will add some comments to make it clearer. |
||
|
||
.PHONY: p4a_android_distro | ||
p4a_android_distro: needs-android-dirs | ||
p4a_android_distro: needs-android-dirs check-android-clean | ||
$(P4A) create $(ARCH_OPTIONS) | ||
# Stash any changes to our python-for-android directory | ||
@git stash push --quiet --include-untracked -- python-for-android | ||
|
||
.PHONY: p4a_android_project | ||
p4a_android_project: p4a_android_distro src/kolibri needs-version | ||
$(P4A) bootstrap $(ARCH_OPTIONS) --version=$(APK_VERSION) --numeric-version=$(BUILD_NUMBER) | ||
# Stash any changes to our python-for-android directory | ||
@git stash push --quiet --include-untracked -- python-for-android | ||
|
||
.PHONY: update_project_from_p4a | ||
update_project_from_p4a: p4a_android_distro src/kolibri needs-version | ||
$(P4A) bootstrap $(ARCH_OPTIONS) --version=$(APK_VERSION) --numeric-version=$(BUILD_NUMBER) | ||
|
||
.PHONY: needs-version | ||
needs-version: | ||
|
@@ -83,38 +99,35 @@ needs-version: | |
|
||
.PHONY: kolibri.apk | ||
# Build the signed version of the apk | ||
# For some reason, p4a defauls to adding a final '-' to the filename, so we remove it in the final step. | ||
kolibri.apk: p4a_android_distro src/kolibri needs-version | ||
kolibri.apk: p4a_android_project | ||
$(MAKE) guard-P4A_RELEASE_KEYSTORE | ||
$(MAKE) guard-P4A_RELEASE_KEYALIAS | ||
$(MAKE) guard-P4A_RELEASE_KEYSTORE_PASSWD | ||
$(MAKE) guard-P4A_RELEASE_KEYALIAS_PASSWD | ||
@echo "--- :android: Build APK" | ||
$(P4A) apk --release --sign $(ARCH_OPTIONS) --version=$(APK_VERSION) --numeric-version=$(BUILD_NUMBER) | ||
cd python-for-android/dists/kolibri && ./gradlew clean assembleRelease | ||
mkdir -p dist | ||
mv kolibri-release-$(APK_VERSION).apk dist/kolibri-release-$(APK_VERSION).apk | ||
cp python-for-android/dists/kolibri/build/outputs/apk/release/kolibri-release.apk dist/kolibri-release-$(APK_VERSION).apk | ||
|
||
.PHONY: kolibri.apk.unsigned | ||
# Build the unsigned debug version of the apk | ||
# For some reason, p4a defauls to adding a final '-' to the filename, so we remove it in the final step. | ||
kolibri.apk.unsigned: p4a_android_distro src/kolibri needs-version | ||
kolibri.apk.unsigned: p4a_android_project | ||
@echo "--- :android: Build APK (unsigned)" | ||
$(P4A) apk $(ARCH_OPTIONS) --version=$(APK_VERSION) --numeric-version=$(BUILD_NUMBER) | ||
cd python-for-android/dists/kolibri && ./gradlew clean assembleDebug | ||
mkdir -p dist | ||
mv kolibri-debug-$(APK_VERSION).apk dist/kolibri-debug-$(APK_VERSION).apk | ||
cp python-for-android/dists/kolibri/build/outputs/apk/debug/kolibri-debug.apk dist/kolibri-debug-$(APK_VERSION).apk | ||
|
||
.PHONY: kolibri.aab | ||
# Build the signed version of the aab | ||
# For some reason, p4a defauls to adding a final '-' to the filename, so we remove it in the final step. | ||
kolibri.aab: p4a_android_distro src/kolibri needs-version | ||
kolibri.aab: p4a_android_project | ||
$(MAKE) guard-P4A_RELEASE_KEYSTORE | ||
$(MAKE) guard-P4A_RELEASE_KEYALIAS | ||
$(MAKE) guard-P4A_RELEASE_KEYSTORE_PASSWD | ||
$(MAKE) guard-P4A_RELEASE_KEYALIAS_PASSWD | ||
@echo "--- :android: Build AAB" | ||
$(P4A) aab --release --sign $(ARCH_OPTIONS) --version=$(APK_VERSION) --numeric-version=$(BUILD_NUMBER) | ||
cd python-for-android/dists/kolibri && ./gradlew clean bundleRelease | ||
mkdir -p dist | ||
mv kolibri-release-$(APK_VERSION).aab dist/kolibri-release-$(APK_VERSION).aab | ||
cp python-for-android/dists/kolibri/build/outputs/bundle/release/kolibri-release.aab dist/kolibri-release-$(APK_VERSION).aab | ||
|
||
# DOCKER BUILD | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ This project was primarily developed on Docker, so this method is more rigorousl | |
|
||
4. The generated APK will end up in the `bin/` folder. | ||
|
||
## Building for Development | ||
## Development Flow | ||
|
||
1. Install the Android SDK and Android NDK. | ||
|
||
|
@@ -33,14 +33,25 @@ Follow the instructions from the command to set the additional environment varia | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth above these pieces suggesting a venv? |
||
4. Build or download a Kolibri WHL file, and place it in the `whl/` directory. | ||
|
||
To download a Kolibri WHL file, you can use `make whl=<URL>` from the command line. It will download it and put it in the correct directory. | ||
To download a Kolibri WHL file, you can use `make get-whl whl=<URL>` from the command line. It will download it and put it in the correct directory. | ||
|
||
5. By default the APK will be built for most architectures supported by | ||
Python for Android. To build for a smaller set of architectures, set | ||
the `ARCHES` environment variable. Run `p4a archs` to see the | ||
available targets. | ||
5. By default the APK/AAB will be built for most architectures supported by Python for Android. To build for a smaller set of architectures, set the `ARCHES` environment variable. Run `p4a archs` to see the available targets. | ||
|
||
6. Run `make kolibri.apk.unsigned` to build the apk. Watch for success at the end, or errors, which might indicate missing build dependencies or build errors. If successful, there should be an APK in the `dist/` directory. | ||
6. Run `make p4a_android_project` this will do all of the Python for Android setup up until the point of actually building an APK or AAB. | ||
|
||
N.B. You will need to rerun this step any time you update the Kolibri WHL file you are using, or any time you update the Python code in this repository. | ||
|
||
7. You can now run Android Studio and open the folder `python-for-android/dists/kolibri` as the project folder to work from. You should be able to make updates to Java code, resource files, etc. using Android Studio, and build and run the project using Android Studio, including launching into emulators and real physical devices. | ||
|
||
N.B. When you rerun step 6, it will complain loudly and exit early if you have uncommitted changes in the python-for-android folder. Any changes should be committed (even if in a temporary commit) before rerunning this step, as we use git stash to undo any changes in the Android project caused by the Python for Android project bootstrapping process. Also, when rerunning step 5, the Android version will not have incremented, meaning that any emulator or physical device will need to have Kolibri explicitly uninstalled for any changes to Python code to be updated on install. | ||
|
||
## Debugging the app | ||
|
||
1. When running the app from Android Studio, if you are using an emulator, it is possible that there will be many warning messages due to GPU emulation. In the logcat tab, update the filter to this `package:mine & -tag:eglCodecCommon` to hide those errors from the logcat output. | ||
|
||
## Building from the commandline | ||
|
||
1. Run `make kolibri.apk.unsigned` to build the development apk. Watch for success at the end, or errors, which might indicate missing build dependencies or build errors. If successful, there should be an APK in the `dist/` directory. | ||
|
||
## Installing the apk | ||
1. Connect your Android device over USB, with USB Debugging enabled. | ||
|
@@ -52,8 +63,6 @@ To download a Kolibri WHL file, you can use `make whl=<URL>` from the command li | |
|
||
1. Run `adb shell am start -n org.learningequality.Kolibri/org.kivy.android.PythonActivity` | ||
|
||
## Debugging the app | ||
|
||
### Server Side | ||
Run `adb logcat -v brief python:D *:F` to get all debug logs from the Kolibri server | ||
|
||
|
@@ -102,3 +111,9 @@ Host kolibri-android | |
HostkeyAlgorithms +ssh-rsa | ||
``` | ||
Then, you should be able to just do “ssh kolibri-android” | ||
|
||
## Updating Python for Android | ||
|
||
We maintain a fork of Python for Android that includes various changes we have made to the source code to support our specific needs. As P4A make new releases, we make a branch from the latest release tag, and then replay the commits on top of this tag using an interactive rebase. Sometimes, this allows us to drop commits as new features are merged into P4A. Our naming convention for the branch on our fork is `from_upstream_<tag_name>`. Any time we push new commits to this branch, we must also update the pinned commit in `requirements.txt`, so that we are always building with a completely predictable version of Python for Android. | ||
|
||
By default we stash any updates to our bootstrap coming from Python for Android, because mostly we have overwritten their bootstrap code to make the relevant changes for us. If there are upstream changes to code we have committed in this repo from the bootstraps, then if the diff is small, it is probably simplest to manually copy in these changes to our committed code. If the diff is larger, or the developer fancies exercising some git-fu, then the make command `make update_project_from_p4a` will update the bootstrap from Python for Android, and not stash any changes that introduces. Through judicious change reversion and diffing, the appropriate changes can then be applied. Here be dragons. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
|
||
h1 { | ||
font-size: 30px; | ||
color: blue; | ||
font-weight: bold; | ||
text-align:center; | ||
} | ||
|
||
h2 { | ||
text-align:center; | ||
} | ||
|
||
button { | ||
margin-left: auto; | ||
margin-right: auto; | ||
display: block; | ||
margin-top: 50px; | ||
font-size: 30px; | ||
} | ||
|
||
|
||
/* Loader from http://projects.lukehaas.me/css-loaders/#load1 */ | ||
|
||
.loader, | ||
.loader:before, | ||
.loader:after { | ||
background: #aaaaff; | ||
-webkit-animation: load1 1s infinite ease-in-out; | ||
animation: load1 1s infinite ease-in-out; | ||
width: 1em; | ||
height: 4em; | ||
} | ||
.loader:before, | ||
.loader:after { | ||
position: absolute; | ||
top: 0; | ||
content: ''; | ||
} | ||
.loader:before { | ||
left: -1.5em; | ||
} | ||
.loader { | ||
text-indent: -9999em; | ||
margin: 8em auto; | ||
position: relative; | ||
font-size: 11px; | ||
-webkit-animation-delay: -0.16s; | ||
animation-delay: -0.16s; | ||
} | ||
.loader:after { | ||
left: 1.5em; | ||
-webkit-animation-delay: -0.32s; | ||
animation-delay: -0.32s; | ||
} | ||
@-webkit-keyframes load1 { | ||
0%, | ||
80%, | ||
100% { | ||
box-shadow: 0 0 #aaaaff; | ||
height: 4em; | ||
} | ||
40% { | ||
box-shadow: 0 -2em #aaaaff; | ||
height: 5em; | ||
} | ||
} | ||
@keyframes load1 { | ||
0%, | ||
80%, | ||
100% { | ||
box-shadow: 0 0 #aaaaff; | ||
height: 4em; | ||
} | ||
40% { | ||
box-shadow: 0 -2em #aaaaff; | ||
height: 5em; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.jnius; | ||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Method; | ||
|
||
public class NativeInvocationHandler implements InvocationHandler { | ||
static boolean DEBUG = false; | ||
private long ptr; | ||
|
||
public NativeInvocationHandler(long ptr) { | ||
this.ptr = ptr; | ||
} | ||
|
||
public Object invoke(Object proxy, Method method, Object[] args) { | ||
if ( DEBUG ) { | ||
System.out.print("+ java:invoke(<proxy>, "); | ||
// don't call it, or recursive lookup/proxy will go! | ||
//System.out.print(proxy); | ||
//System.out.print(", "); | ||
System.out.print(method); | ||
System.out.print(", "); | ||
System.out.print(args); | ||
System.out.println(")"); | ||
System.out.flush(); | ||
} | ||
|
||
Object ret = invoke0(proxy, method, args); | ||
|
||
if ( DEBUG ) { | ||
System.out.print("+ java:invoke returned: "); | ||
System.out.println(ret); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
public long getPythonObjectPointer() { | ||
return ptr; | ||
} | ||
|
||
native Object invoke0(Object proxy, Method method, Object[] args); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-rf
is recursive when you delete a folder itself, but I don't think this will recursively delete from subfolders with the wildcards like that, so it may be good to adapt to be safer.Confirmed: