Repository: kivy/python-for-android

Issue:
splash always loading 
i build app with bootstrap=webview, 
the application works perfect, but when I press the back button the splah comes back out and stays loaded. What I try is that this does not happen and that when you press the button to go back out of the application, is there any option to access the onResume methods ...? Is there any way to solve this problem?


Discussion:

Patch:
diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml
index 597293a9..74121077 100644
--- a/.github/workflows/push.yml
+++ b/.github/workflows/push.yml
@@ -3,9 +3,9 @@ name: Unit tests & build apps
 on: ['push', 'pull_request']
 
 env:
-  APK_ARTIFACT_FILENAME: bdist_unit_tests_app-debug-1.1-.apk
-  AAB_ARTIFACT_FILENAME: bdist_unit_tests_app-release-1.1-.aab
-  AAR_ARTIFACT_FILENAME: bdist_unit_tests_app-release-1.1-.aar
+  APK_ARTIFACT_FILENAME: bdist_unit_tests_app-debug-1.1.apk
+  AAB_ARTIFACT_FILENAME: bdist_unit_tests_app-release-1.1.aab
+  AAR_ARTIFACT_FILENAME: bdist_unit_tests_app-release-1.1.aar
   PYTHONFORANDROID_PREREQUISITES_INSTALL_INTERACTIVE: 0
 
 jobs:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4f90b67e..2e37bdc5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,99 @@
 # Changelog
 
+## [v2022.07.20](https://github.com/kivy/python-for-android/tree/v2022.07.20) (2022-07-20)
+
+[Full Changelog](https://github.com/kivy/python-for-android/compare/v2022.03.13...v2022.07.20)
+
+**Fixed bugs:**
+
+- Current default Python version \(3.8.9\) is failing to build on latest macOS releases [\#2568](https://github.com/kivy/python-for-android/issues/2568)
+- Build failed for Pillow recipe when targeting x86\_64 arch [\#2259](https://github.com/kivy/python-for-android/issues/2259)
+- UnboundLocalError: local variable 'toolchain\_version' referenced before assignment [\#2190](https://github.com/kivy/python-for-android/issues/2190)
+- Numpy on MacOsX fails in our `CI` tests [\#2087](https://github.com/kivy/python-for-android/issues/2087)
+
+**Closed issues:**
+
+- pyzbar android building error [\#2635](https://github.com/kivy/python-for-android/issues/2635)
+- `tflite-runtime` build every time [\#2630](https://github.com/kivy/python-for-android/issues/2630)
+- Failed to build `matplotlib` because `kiwisolver` [\#2629](https://github.com/kivy/python-for-android/issues/2629)
+- Trying to build pandas with buildozer results in missing headers errors [\#2626](https://github.com/kivy/python-for-android/issues/2626)
+- https://github.com/kivy/python-for-android.git [\#2625](https://github.com/kivy/python-for-android/issues/2625)
+- \[SSL : CERTIFICATE\_VERIFY\_FAILED \] in Android  [\#2620](https://github.com/kivy/python-for-android/issues/2620)
+- How to run Python script in background in android? [\#2618](https://github.com/kivy/python-for-android/issues/2618)
+- USB permission [\#2611](https://github.com/kivy/python-for-android/issues/2611)
+- ffmpeg recipe for 23b build fails [\#2608](https://github.com/kivy/python-for-android/issues/2608)
+- Broken jpeg recipe for NDK 23b? [\#2603](https://github.com/kivy/python-for-android/issues/2603)
+- Need a help [\#2595](https://github.com/kivy/python-for-android/issues/2595)
+- Termux build fails [\#2585](https://github.com/kivy/python-for-android/issues/2585)
+- lapack build error [\#2584](https://github.com/kivy/python-for-android/issues/2584)
+- still this issue is happening [\#2572](https://github.com/kivy/python-for-android/issues/2572)
+- "Unit test apk" + "Unit test aab" + "Test updated recipes" test jobs should be run also on macOS \(both Intel and Apple Silicon\) [\#2569](https://github.com/kivy/python-for-android/issues/2569)
+- unpackPyBundle\(\) on startup crashes already running service [\#2564](https://github.com/kivy/python-for-android/issues/2564)
+- Webview app fail to startup. [\#2559](https://github.com/kivy/python-for-android/issues/2559)
+- genericndkbuild receipe Not compiling with android api \> 28 [\#2555](https://github.com/kivy/python-for-android/issues/2555)
+- Is there a way to build smaller apks? [\#2553](https://github.com/kivy/python-for-android/issues/2553)
+- Webview, icon [\#2552](https://github.com/kivy/python-for-android/issues/2552)
+- SONAME header not present in libpython3.8.so [\#2548](https://github.com/kivy/python-for-android/issues/2548)
+- How to mention Python modules in Kivy buildozer.spec file? [\#2547](https://github.com/kivy/python-for-android/issues/2547)
+- Issue with pyaudio and portaudio [\#2535](https://github.com/kivy/python-for-android/issues/2535)
+- \[Temporary Resolved\] Python 4 android in mac os with Apple Silicon via Roseta [\#2528](https://github.com/kivy/python-for-android/issues/2528)
+- Scipy is not installed due to "Error: 'numpy' must be installed before running the build." [\#2509](https://github.com/kivy/python-for-android/issues/2509)
+- Lapack depends on arm-linux-androideabi-gfortran [\#2508](https://github.com/kivy/python-for-android/issues/2508)
+- Apk file built by buildozer is large in comparision to other apks [\#2473](https://github.com/kivy/python-for-android/issues/2473)
+- p4a is not compatible with ndk \>= 22 [\#2391](https://github.com/kivy/python-for-android/issues/2391)
+- Sympy module. Error in buildozer: no module named sympy.testing [\#2381](https://github.com/kivy/python-for-android/issues/2381)
+- build.gradle 'compile' depreciated [\#2362](https://github.com/kivy/python-for-android/issues/2362)
+- API 29 support [\#2360](https://github.com/kivy/python-for-android/issues/2360)
+- python for android [\#2307](https://github.com/kivy/python-for-android/issues/2307)
+- application is not working in android  made with buildozer kivy [\#2260](https://github.com/kivy/python-for-android/issues/2260)
+- hostpython3 unpack error [\#2247](https://github.com/kivy/python-for-android/issues/2247)
+- no recipe for pyaudio \_portaudio.  [\#2223](https://github.com/kivy/python-for-android/issues/2223)
+- How to add a native Python package for kivy? [\#2089](https://github.com/kivy/python-for-android/issues/2089)
+- scipy module fails loading for 32 bit and 64 bit APK builds.  [\#2061](https://github.com/kivy/python-for-android/issues/2061)
+- Support for androidx [\#2020](https://github.com/kivy/python-for-android/issues/2020)
+- Cannot build apk using buidozer [\#2005](https://github.com/kivy/python-for-android/issues/2005)
+- Android NDK - "$NDK/platforms/android-25" missing? [\#1992](https://github.com/kivy/python-for-android/issues/1992)
+- Tidy up NDK 19+ support [\#1962](https://github.com/kivy/python-for-android/issues/1962)
+- Support for NDK 19 [\#1613](https://github.com/kivy/python-for-android/issues/1613)
+- Android NDK 18b issues [\#1525](https://github.com/kivy/python-for-android/issues/1525)
+- Google requiring 64 bits binary in August 2019 [\#1519](https://github.com/kivy/python-for-android/issues/1519)
+- Investigate Azure Pipelines [\#1400](https://github.com/kivy/python-for-android/issues/1400)
+
+**Merged pull requests:**
+
+- Use `shutil.which` instead of `sh.which` [\#2637](https://github.com/kivy/python-for-android/pull/2637) ([misl6](https://github.com/misl6))
+- add service\_lib and aar to the docs [\#2634](https://github.com/kivy/python-for-android/pull/2634) ([mzakharo](https://github.com/mzakharo))
+- Fix issue \#2630 [\#2631](https://github.com/kivy/python-for-android/pull/2631) ([Neizvestnyj](https://github.com/Neizvestnyj))
+- lapack/scipy: support NDK r21e, x86/64 archs [\#2619](https://github.com/kivy/python-for-android/pull/2619) ([mzakharo](https://github.com/mzakharo))
+- add scipy/lapack CI tests [\#2617](https://github.com/kivy/python-for-android/pull/2617) ([mzakharo](https://github.com/mzakharo))
+- use LEGACY\_NDK option to build lapack/scipy with a separate NDK [\#2615](https://github.com/kivy/python-for-android/pull/2615) ([mzakharo](https://github.com/mzakharo))
+- Fixing service\_library bootstrap + .aar  build. [\#2612](https://github.com/kivy/python-for-android/pull/2612) ([mzakharo](https://github.com/mzakharo))
+- Bump groestlcoin\_hash to 1.0.3 [\#2607](https://github.com/kivy/python-for-android/pull/2607) ([gruve-p](https://github.com/gruve-p))
+- removed `usr` and `lib` from ndk library path in `librt` recipe [\#2606](https://github.com/kivy/python-for-android/pull/2606) ([kengoon](https://github.com/kengoon))
+- changed arch.ndk\_platform to arch.ndk\_lib\_dir in `librt` recipe [\#2605](https://github.com/kivy/python-for-android/pull/2605) ([kengoon](https://github.com/kengoon))
+- Our self-hosted Apple Silicon runner now has been migrated to actions/runner v2.292.0 which now supports arm64 natively [\#2602](https://github.com/kivy/python-for-android/pull/2602) ([misl6](https://github.com/misl6))
+- Introduces pkg\_config\_location in Prerequisite and use OpenSSLPrerequisite\(\).pkg\_config\_location in hostpython3, so we can support ssl on hostpython3 just out of the box also on macOS [\#2599](https://github.com/kivy/python-for-android/pull/2599) ([misl6](https://github.com/misl6))
+- Add service to webview test app [\#2598](https://github.com/kivy/python-for-android/pull/2598) ([dbnicholson](https://github.com/dbnicholson))
+- Fix webview testapp jnius usage [\#2597](https://github.com/kivy/python-for-android/pull/2597) ([dbnicholson](https://github.com/dbnicholson))
+- Support multiarch in webview bootstrap [\#2596](https://github.com/kivy/python-for-android/pull/2596) ([dbnicholson](https://github.com/dbnicholson))
+- Handle all the macOS prerequisites \(except NDK/SDK\) via prerequisites.py [\#2594](https://github.com/kivy/python-for-android/pull/2594) ([misl6](https://github.com/misl6))
+- Prefer avdmanager from cmdline-tools [\#2593](https://github.com/kivy/python-for-android/pull/2593) ([dbnicholson](https://github.com/dbnicholson))
+- \*\_rebuild\_updated\_recipes CI jobs now test the updated recipe along all the supported Android archs \(arm64-v8a, armeabi-v7a, x86\_64, x86\) [\#2592](https://github.com/kivy/python-for-android/pull/2592) ([misl6](https://github.com/misl6))
+- Introduces pythonforandroid/prerequisites.py \(Experimental\). This allows a more granular check and install process for dependencies on both CI jobs and users installation. [\#2591](https://github.com/kivy/python-for-android/pull/2591) ([misl6](https://github.com/misl6))
+- Added py3dns recipe [\#2590](https://github.com/kivy/python-for-android/pull/2590) ([Neizvestnyj](https://github.com/Neizvestnyj))
+- Upload artifacts produced from every build platform, not only ubuntu-latest [\#2588](https://github.com/kivy/python-for-android/pull/2588) ([misl6](https://github.com/misl6))
+- Fixes a typo in macos\_rebuild\_updated\_recipes [\#2587](https://github.com/kivy/python-for-android/pull/2587) ([misl6](https://github.com/misl6))
+- Added pythonforandroid.androidndk.AndroidNDK + some changes needed in order to support build on Apple Silicon macs. [\#2586](https://github.com/kivy/python-for-android/pull/2586) ([misl6](https://github.com/misl6))
+- Set PATH using real SDK and NDK directories [\#2583](https://github.com/kivy/python-for-android/pull/2583) ([dbnicholson](https://github.com/dbnicholson))
+- Add missing fetch-depth: 0 on macos\_rebuild\_updated\_recipes [\#2579](https://github.com/kivy/python-for-android/pull/2579) ([misl6](https://github.com/misl6))
+- Bumps libffi to v3.4.2 + adds -fPIC on i686-linux-android [\#2578](https://github.com/kivy/python-for-android/pull/2578) ([misl6](https://github.com/misl6))
+- Bumps numpy version to 1.22.3, cython version to 0.29.28 and fixes numpy build on macOS [\#2575](https://github.com/kivy/python-for-android/pull/2575) ([misl6](https://github.com/misl6))
+- macOS CI: ADD APK, AAB & Updated Recipes build [\#2574](https://github.com/kivy/python-for-android/pull/2574) ([misl6](https://github.com/misl6))
+- add version check to unpackPyBundle [\#2565](https://github.com/kivy/python-for-android/pull/2565) ([mzakharo](https://github.com/mzakharo))
+- Merges master into develop after release 2022.03.13 [\#2562](https://github.com/kivy/python-for-android/pull/2562) ([misl6](https://github.com/misl6))
+- Fixes App Icon and Presplash\_Screen For Webview bootstrap [\#2556](https://github.com/kivy/python-for-android/pull/2556) ([kengoon](https://github.com/kengoon))
+- NDK 23 + Gradle 7 support [\#2550](https://github.com/kivy/python-for-android/pull/2550) ([misl6](https://github.com/misl6))
+
 ## [v2022.03.13](https://github.com/kivy/python-for-android/tree/v2022.03.13) (2022-03-13)
 
 [Full Changelog](https://github.com/kivy/python-for-android/compare/v2021.09.05...v2022.03.13)
diff --git a/Makefile b/Makefile
index b0d3da88..97f50221 100644
--- a/Makefile
+++ b/Makefile
@@ -106,17 +106,17 @@ docker/run/command: docker/build
 
 docker/run/make/with-artifact/apk/%: docker/build
 	docker run --name p4a-latest --env-file=.env $(DOCKER_IMAGE) make $*
-	docker cp p4a-latest:/home/user/app/testapps/on_device_unit_tests/bdist_unit_tests_app-debug-1.1-.apk ./apks
+	docker cp p4a-latest:/home/user/app/testapps/on_device_unit_tests/bdist_unit_tests_app-debug-1.1.apk ./apks
 	docker rm -fv p4a-latest
 
 docker/run/make/with-artifact/aar/%: docker/build
 	docker run --name p4a-latest --env-file=.env $(DOCKER_IMAGE) make $*
-	docker cp p4a-latest:/home/user/app/testapps/on_device_unit_tests/bdist_unit_tests_app-release-1.1-.aar ./aars
+	docker cp p4a-latest:/home/user/app/testapps/on_device_unit_tests/bdist_unit_tests_app-release-1.1.aar ./aars
 	docker rm -fv p4a-latest
 
 docker/run/make/with-artifact/aab/%: docker/build
 	docker run --name p4a-latest --env-file=.env $(DOCKER_IMAGE) make $*
-	docker cp p4a-latest:/home/user/app/testapps/on_device_unit_tests/bdist_unit_tests_app-release-1.1-.aab ./aabs
+	docker cp p4a-latest:/home/user/app/testapps/on_device_unit_tests/bdist_unit_tests_app-release-1.1.aab ./aabs
 	docker rm -fv p4a-latest
 
 docker/run/make/rebuild_updated_recipes: docker/build
diff --git a/pythonforandroid/__init__.py b/pythonforandroid/__init__.py
index eb2a14cb..e014c4ff 100644
--- a/pythonforandroid/__init__.py
+++ b/pythonforandroid/__init__.py
@@ -1,1 +1,1 @@
-__version__ = '2022.03.13'
+__version__ = '2022.07.20'
diff --git a/pythonforandroid/bootstraps/service_only/build/src/main/java/org/kivy/android/PythonActivity.java b/pythonforandroid/bootstraps/service_only/build/src/main/java/org/kivy/android/PythonActivity.java
index 919c42b0..87ea061c 100644
--- a/pythonforandroid/bootstraps/service_only/build/src/main/java/org/kivy/android/PythonActivity.java
+++ b/pythonforandroid/bootstraps/service_only/build/src/main/java/org/kivy/android/PythonActivity.java
@@ -177,19 +177,22 @@ public class PythonActivity extends Activity {
             new File(getApplicationInfo().nativeLibraryDir));
     }
 
-    long lastBackClick = SystemClock.elapsedRealtime();
+    long lastBackClick = 0;
     @Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
-        // If it wasn't the Back key or there's no web page history, bubble up to the default
-        // system behavior (probably exit the activity)
-        if (SystemClock.elapsedRealtime() - lastBackClick > 2000){
+        // Check if the key event was the Back button
+        if (keyCode == KeyEvent.KEYCODE_BACK) {
+            // If there's no web page history, bubble up to the default
+            // system behavior (probably exit the activity)
+            if (SystemClock.elapsedRealtime() - lastBackClick > 2000){
+                lastBackClick = SystemClock.elapsedRealtime();
+                Toast.makeText(this, "Tap again to close the app", Toast.LENGTH_LONG).show();
+                return true;
+            }
+
             lastBackClick = SystemClock.elapsedRealtime();
-            Toast.makeText(this, "Click again to close the app",
-            Toast.LENGTH_LONG).show();
-            return true;
         }
 
-        lastBackClick = SystemClock.elapsedRealtime();
         return super.onKeyDown(keyCode, event);
     }
 
diff --git a/pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java b/pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java
index b8499849..8aa308b2 100644
--- a/pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java
+++ b/pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java
@@ -32,6 +32,7 @@ import android.graphics.Color;
 import android.widget.AbsoluteLayout;
 import android.view.ViewGroup.LayoutParams;
 
+import android.webkit.WebBackForwardList;
 import android.webkit.WebViewClient;
 import android.webkit.WebView;
 import android.webkit.CookieManager;
@@ -269,24 +270,30 @@ public class PythonActivity extends Activity {
         return   mLayout;
     }
 
-    long lastBackClick = SystemClock.elapsedRealtime();
+    long lastBackClick = 0;
     @Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
-        // Check if the key event was the Back button and if there's history
-        if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
-            mWebView.goBack();
-            return true;
-        }
-        // If it wasn't the Back key or there's no web page history, bubble up to the default
-        // system behavior (probably exit the activity)
-        if (SystemClock.elapsedRealtime() - lastBackClick > 2000){
+        // Check if the key event was the Back button
+        if (keyCode == KeyEvent.KEYCODE_BACK) {
+            // Go back if there is web page history behind,
+            // but not to the start preloader
+            WebBackForwardList webViewBackForwardList = mWebView.copyBackForwardList();
+            if (webViewBackForwardList.getCurrentIndex() > 1) {
+                mWebView.goBack();
+                return true;
+            }
+
+            // If there's no web page history, bubble up to the default
+            // system behavior (probably exit the activity)
+            if (SystemClock.elapsedRealtime() - lastBackClick > 2000){
+                lastBackClick = SystemClock.elapsedRealtime();
+                Toast.makeText(this, "Tap again to close the app", Toast.LENGTH_LONG).show();
+                return true;
+            }
+
             lastBackClick = SystemClock.elapsedRealtime();
-            Toast.makeText(this, "Click again to close the app",
-            Toast.LENGTH_LONG).show();
-            return true;
         }
 
-        lastBackClick = SystemClock.elapsedRealtime();
         return super.onKeyDown(keyCode, event);
     }
 
diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py
index 7e19aef2..359ea636 100644
--- a/pythonforandroid/toolchain.py
+++ b/pythonforandroid/toolchain.py
@@ -720,7 +720,7 @@ class ToolchainCL:
 
         self._archs = args.arch
 
-        self.ctx.local_recipes = args.local_recipes
+        self.ctx.local_recipes = realpath(args.local_recipes)
         self.ctx.copy_libs = args.copy_libs
 
         self.ctx.activity_class_name = args.activity_class_name
@@ -1147,7 +1147,7 @@ class ToolchainCL:
         if package_add_version:
             info('# Add version number to android package')
             package_name = basename(package_file)[:-len(package_extension)]
-            package_file_dest = "{}-{}-{}".format(
+            package_file_dest = "{}-{}{}".format(
                 package_name, build_args.version, package_extension)
             info('# Android package renamed to {}'.format(package_file_dest))
             shprint(sh.cp, package_file, package_file_dest)


Test patch:
diff --git a/tests/test_toolchain.py b/tests/test_toolchain.py
index 23d0d3ff..0cc2b1a7 100644
--- a/tests/test_toolchain.py
+++ b/tests/test_toolchain.py
@@ -1,4 +1,5 @@
 import io
+import os
 import sys
 import pytest
 from unittest import mock
@@ -136,3 +137,34 @@ class TestToolchainCL:
             assert expected_string in m_stdout.getvalue()
         # deletes static attribute to not mess with other tests
         del Recipe.recipes
+
+    def test_local_recipes_dir(self):
+        """
+        Checks the `local_recipes` attribute in the Context is absolute.
+        """
+        cwd = os.path.realpath(os.getcwd())
+        common_args = [
+            'toolchain.py',
+            'recommendations',
+        ]
+
+        # Check the default ./p4a-recipes becomes absolute.
+        argv = common_args
+        with patch_sys_argv(argv):
+            toolchain = ToolchainCL()
+        expected_local_recipes = os.path.join(cwd, 'p4a-recipes')
+        assert toolchain.ctx.local_recipes == expected_local_recipes
+
+        # Check a supplied relative directory becomes absolute.
+        argv = common_args + ['--local-recipes=foo']
+        with patch_sys_argv(argv):
+            toolchain = ToolchainCL()
+        expected_local_recipes = os.path.join(cwd, 'foo')
+        assert toolchain.ctx.local_recipes == expected_local_recipes
+
+        # An absolute directory should remain unchanged.
+        local_recipes = os.path.join(cwd, 'foo')
+        argv = common_args + ['--local-recipes={}'.format(local_recipes)]
+        with patch_sys_argv(argv):
+            toolchain = ToolchainCL()
+        assert toolchain.ctx.local_recipes == local_recipes