prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Webview app crashes when trying to request permissions
  ### Checklist
  
  - [X] the issue is indeed a bug and not a support request
  - [X] issue doesn't already exist: https://github.com/kivy/python-for-android/issues
  - [X] I have a short, runnable example that reproduces the issue
  - [X] I reproduced the problem with the latest development version (`p4a.branch = develop`)
  - [X] I used the grave accent (aka backticks) to format code or logs when appropriated
  
  ### Versions
  
  - Python: 3.6.6
  - OS: Ubuntu 20.04
  - python-for-android: 2020.6.2
  
  ### Description
  
  I'm building with:
  
  ```
  HERE=$(pwd)
  cd app
  
  export ANDROIDSDK="$HERE/android_sdks"
  # Have also tried with
  # export ANDROIDNDK="$HERE/android_sdks/android-ndk-r19c"
  export ANDROIDNDK="$HERE/android_sdks/android-ndk-r21d"
  export ANDROIDAPI="27"  # Target API version of your application
  export NDKAPI="21"  # Minimum supported API version of your application
  
  p4a apk --private "." --package=org.anarres.pdfreader --name "pdf reader" --version 0.1 --bootstrap=webview --requirements=python3,flask --port=5000 --orientation=sensor --blacklist="../blacklist.txt" --permission READ_EXTERNAL_STORAGE --permission WRITE_EXTERNAL_STORAGE
  ```
  
  My python code is just:
  
  ```
  from android.permissions import request_permissions, Permission
  request_permissions([Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE])
  
  from flask import Flask, render_template
  
  app = Flask(__name__)
  
  @app.route('/')
  def index():
      return render_template('index.html')
  
  if __name__ == '__main__':
      app.run(port=5000)
  ```
  
  If I comment out:
  
  ```
  from android.permissions import request_permissions, Permission
  request_permissions([Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE])
  ```
  
  I don't see the error, but then of course I can't access the external storage.
  
  ### Logs
  
  ```
  ImportError: dlopen failed: cannot locate symbol "SDL_ANDROID_GetJNIEnv" referenced by "/data/data/org.anarres.pdfreader/files/app/_python_bundle/site-packages/android/_android.so"...
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pythonforandroid/recipes/android/src/setup.py`
  Content:
  ```
  1 from distutils.core import setup, Extension
  2 import os
  3 
  4 library_dirs = ['libs/' + os.environ['ARCH']]
  5 lib_dict = {
  6     'sdl2': ['SDL2', 'SDL2_image', 'SDL2_mixer', 'SDL2_ttf']
  7 }
  8 sdl_libs = lib_dict.get(os.environ['BOOTSTRAP'], [])
  9 
  10 modules = [Extension('android._android',
  11                      ['android/_android.c', 'android/_android_jni.c'],
  12                      libraries=sdl_libs + ['log'],
  13                      library_dirs=library_dirs),
  14            Extension('android._android_billing',
  15                      ['android/_android_billing.c', 'android/_android_billing_jni.c'],
  16                      libraries=['log'],
  17                      library_dirs=library_dirs)]
  18 
  19 setup(name='android',
  20       version='1.0',
  21       packages=['android'],
  22       package_dir={'android': 'android'},
  23       ext_modules=modules
  24       )
  25
  ```
  
  Path: `pythonforandroid/recipes/android/__init__.py`
  Content:
  ```
  1 from pythonforandroid.recipe import CythonRecipe, IncludedFilesBehaviour
  2 from pythonforandroid.util import current_directory
  3 from pythonforandroid import logger
  4 
  5 from os.path import join
  6 
  7 
  8 class AndroidRecipe(IncludedFilesBehaviour, CythonRecipe):
  9     # name = 'android'
  10     version = None
  11     url = None
  12 
  13     src_filename = 'src'
  14 
  15     depends = [('sdl2', 'genericndkbuild'), 'pyjnius']
  16 
  17     config_env = {}
  18 
  19     def get_recipe_env(self, arch):
  20         env = super().get_recipe_env(arch)
  21         env.update(self.config_env)
  22         return env
  23 
  24     def prebuild_arch(self, arch):
  25         super().prebuild_arch(arch)
  26         ctx_bootstrap = self.ctx.bootstrap.name
  27 
  28         # define macros for Cython, C, Python
  29         tpxi = 'DEF {} = {}\n'
  30         th = '#define {} {}\n'
  31         tpy = '{} = {}\n'
  32 
  33         # make sure bootstrap name is in unicode
  34         if isinstance(ctx_bootstrap, bytes):
  35             ctx_bootstrap = ctx_bootstrap.decode('utf-8')
  36         bootstrap = bootstrap_name = ctx_bootstrap
  37         is_sdl2 = (bootstrap_name == "sdl2")
  38         if bootstrap_name in ["sdl2", "webview", "service_only", "service_library"]:
  39             java_ns = u'org.kivy.android'
  40             jni_ns = u'org/kivy/android'
  41         else:
  42             logger.error((
  43                 'unsupported bootstrap for android recipe: {}'
  44                 ''.format(bootstrap_name)
  45             ))
  46             exit(1)
  47 
  48         config = {
  49             'BOOTSTRAP': bootstrap,
  50             'IS_SDL2': int(is_sdl2),
  51             'PY2': 0,
  52             'JAVA_NAMESPACE': java_ns,
  53             'JNI_NAMESPACE': jni_ns,
  54             'ACTIVITY_CLASS_NAME': self.ctx.activity_class_name,
  55             'ACTIVITY_CLASS_NAMESPACE': self.ctx.activity_class_name.replace('.', '/'),
  56         }
  57 
  58         # create config files for Cython, C and Python
  59         with (
  60                 current_directory(self.get_build_dir(arch.arch))), (
  61                 open(join('android', 'config.pxi'), 'w')) as fpxi, (
  62                 open(join('android', 'config.h'), 'w')) as fh, (
  63                 open(join('android', 'config.py'), 'w')) as fpy:
  64 
  65             for key, value in config.items():
  66                 fpxi.write(tpxi.format(key, repr(value)))
  67                 fpy.write(tpy.format(key, repr(value)))
  68 
  69                 fh.write(th.format(
  70                     key,
  71                     value if isinstance(value, int) else '"{}"'.format(value)
  72                 ))
  73                 self.config_env[key] = str(value)
  74 
  75             if is_sdl2:
  76                 fh.write('JNIEnv *SDL_AndroidGetJNIEnv(void);\n')
  77                 fh.write(
  78                     '#define SDL_ANDROID_GetJNIEnv SDL_AndroidGetJNIEnv\n'
  79                 )
  80 
  81 
  82 recipe = AndroidRecipe()
  83
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/pythonforandroid/recipes/android/__init__.py b/pythonforandroid/recipes/android/__init__.py
  --- a/pythonforandroid/recipes/android/__init__.py
  +++ b/pythonforandroid/recipes/android/__init__.py
  @@ -77,6 +77,11 @@
                   fh.write(
                       '#define SDL_ANDROID_GetJNIEnv SDL_AndroidGetJNIEnv\n'
                   )
  +            else:
  +                fh.write('JNIEnv *WebView_AndroidGetJNIEnv(void);\n')
  +                fh.write(
  +                    '#define SDL_ANDROID_GetJNIEnv WebView_AndroidGetJNIEnv\n'
  +                )
   
   
   recipe = AndroidRecipe()
  diff --git a/pythonforandroid/recipes/android/src/setup.py b/pythonforandroid/recipes/android/src/setup.py
  --- a/pythonforandroid/recipes/android/src/setup.py
  +++ b/pythonforandroid/recipes/android/src/setup.py
  @@ -5,7 +5,7 @@
   lib_dict = {
       'sdl2': ['SDL2', 'SDL2_image', 'SDL2_mixer', 'SDL2_ttf']
   }
  -sdl_libs = lib_dict.get(os.environ['BOOTSTRAP'], [])
  +sdl_libs = lib_dict.get(os.environ['BOOTSTRAP'], ['main'])
   
   modules = [Extension('android._android',
                        ['android/_android.c', 'android/_android_jni.c'],
  
verification_info: {"golden_diff": "diff --git a/pythonforandroid/recipes/android/__init__.py b/pythonforandroid/recipes/android/__init__.py\n--- a/pythonforandroid/recipes/android/__init__.py\n+++ b/pythonforandroid/recipes/android/__init__.py\n@@ -77,6 +77,11 @@\n                 fh.write(\n                     '#define SDL_ANDROID_GetJNIEnv SDL_AndroidGetJNIEnv\\n'\n                 )\n+            else:\n+                fh.write('JNIEnv *WebView_AndroidGetJNIEnv(void);\\n')\n+                fh.write(\n+                    '#define SDL_ANDROID_GetJNIEnv WebView_AndroidGetJNIEnv\\n'\n+                )\n \n \n recipe = AndroidRecipe()\ndiff --git a/pythonforandroid/recipes/android/src/setup.py b/pythonforandroid/recipes/android/src/setup.py\n--- a/pythonforandroid/recipes/android/src/setup.py\n+++ b/pythonforandroid/recipes/android/src/setup.py\n@@ -5,7 +5,7 @@\n lib_dict = {\n     'sdl2': ['SDL2', 'SDL2_image', 'SDL2_mixer', 'SDL2_ttf']\n }\n-sdl_libs = lib_dict.get(os.environ['BOOTSTRAP'], [])\n+sdl_libs = lib_dict.get(os.environ['BOOTSTRAP'], ['main'])\n \n modules = [Extension('android._android',\n                      ['android/_android.c', 'android/_android_jni.c'],\n", "issue": "Webview app crashes when trying to request permissions\n### Checklist\r\n\r\n- [X] the issue is indeed a bug and not a support request\r\n- [X] issue doesn't already exist: https://github.com/kivy/python-for-android/issues\r\n- [X] I have a short, runnable example that reproduces the issue\r\n- [X] I reproduced the problem with the latest development version (`p4a.branch = develop`)\r\n- [X] I used the grave accent (aka backticks) to format code or logs when appropriated\r\n\r\n### Versions\r\n\r\n- Python: 3.6.6\r\n- OS: Ubuntu 20.04\r\n- python-for-android: 2020.6.2\r\n\r\n### Description\r\n\r\nI'm building with:\r\n\r\n```\r\nHERE=$(pwd)\r\ncd app\r\n\r\nexport ANDROIDSDK=\"$HERE/android_sdks\"\r\n# Have also tried with\r\n# export ANDROIDNDK=\"$HERE/android_sdks/android-ndk-r19c\"\r\nexport ANDROIDNDK=\"$HERE/android_sdks/android-ndk-r21d\"\r\nexport ANDROIDAPI=\"27\"  # Target API version of your application\r\nexport NDKAPI=\"21\"  # Minimum supported API version of your application\r\n\r\np4a apk --private \".\" --package=org.anarres.pdfreader --name \"pdf reader\" --version 0.1 --bootstrap=webview --requirements=python3,flask --port=5000 --orientation=sensor --blacklist=\"../blacklist.txt\" --permission READ_EXTERNAL_STORAGE --permission WRITE_EXTERNAL_STORAGE\r\n```\r\n\r\nMy python code is just:\r\n\r\n```\r\nfrom android.permissions import request_permissions, Permission\r\nrequest_permissions([Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE])\r\n\r\nfrom flask import Flask, render_template\r\n\r\napp = Flask(__name__)\r\n\r\n@app.route('/')\r\ndef index():\r\n    return render_template('index.html')\r\n\r\nif __name__ == '__main__':\r\n    app.run(port=5000)\r\n```\r\n\r\nIf I comment out:\r\n\r\n```\r\nfrom android.permissions import request_permissions, Permission\r\nrequest_permissions([Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE])\r\n```\r\n\r\nI don't see the error, but then of course I can't access the external storage.\r\n\r\n### Logs\r\n\r\n```\r\nImportError: dlopen failed: cannot locate symbol \"SDL_ANDROID_GetJNIEnv\" referenced by \"/data/data/org.anarres.pdfreader/files/app/_python_bundle/site-packages/android/_android.so\"...\r\n```\r\n\n", "before_files": [{"content": "from distutils.core import setup, Extension\nimport os\n\nlibrary_dirs = ['libs/' + os.environ['ARCH']]\nlib_dict = {\n    'sdl2': ['SDL2', 'SDL2_image', 'SDL2_mixer', 'SDL2_ttf']\n}\nsdl_libs = lib_dict.get(os.environ['BOOTSTRAP'], [])\n\nmodules = [Extension('android._android',\n                     ['android/_android.c', 'android/_android_jni.c'],\n                     libraries=sdl_libs + ['log'],\n                     library_dirs=library_dirs),\n           Extension('android._android_billing',\n                     ['android/_android_billing.c', 'android/_android_billing_jni.c'],\n                     libraries=['log'],\n                     library_dirs=library_dirs)]\n\nsetup(name='android',\n      version='1.0',\n      packages=['android'],\n      package_dir={'android': 'android'},\n      ext_modules=modules\n      )\n", "path": "pythonforandroid/recipes/android/src/setup.py"}, {"content": "from pythonforandroid.recipe import CythonRecipe, IncludedFilesBehaviour\nfrom pythonforandroid.util import current_directory\nfrom pythonforandroid import logger\n\nfrom os.path import join\n\n\nclass AndroidRecipe(IncludedFilesBehaviour, CythonRecipe):\n    # name = 'android'\n    version = None\n    url = None\n\n    src_filename = 'src'\n\n    depends = [('sdl2', 'genericndkbuild'), 'pyjnius']\n\n    config_env = {}\n\n    def get_recipe_env(self, arch):\n        env = super().get_recipe_env(arch)\n        env.update(self.config_env)\n        return env\n\n    def prebuild_arch(self, arch):\n        super().prebuild_arch(arch)\n        ctx_bootstrap = self.ctx.bootstrap.name\n\n        # define macros for Cython, C, Python\n        tpxi = 'DEF {} = {}\\n'\n        th = '#define {} {}\\n'\n        tpy = '{} = {}\\n'\n\n        # make sure bootstrap name is in unicode\n        if isinstance(ctx_bootstrap, bytes):\n            ctx_bootstrap = ctx_bootstrap.decode('utf-8')\n        bootstrap = bootstrap_name = ctx_bootstrap\n        is_sdl2 = (bootstrap_name == \"sdl2\")\n        if bootstrap_name in [\"sdl2\", \"webview\", \"service_only\", \"service_library\"]:\n            java_ns = u'org.kivy.android'\n            jni_ns = u'org/kivy/android'\n        else:\n            logger.error((\n                'unsupported bootstrap for android recipe: {}'\n                ''.format(bootstrap_name)\n            ))\n            exit(1)\n\n        config = {\n            'BOOTSTRAP': bootstrap,\n            'IS_SDL2': int(is_sdl2),\n            'PY2': 0,\n            'JAVA_NAMESPACE': java_ns,\n            'JNI_NAMESPACE': jni_ns,\n            'ACTIVITY_CLASS_NAME': self.ctx.activity_class_name,\n            'ACTIVITY_CLASS_NAMESPACE': self.ctx.activity_class_name.replace('.', '/'),\n        }\n\n        # create config files for Cython, C and Python\n        with (\n                current_directory(self.get_build_dir(arch.arch))), (\n                open(join('android', 'config.pxi'), 'w')) as fpxi, (\n                open(join('android', 'config.h'), 'w')) as fh, (\n                open(join('android', 'config.py'), 'w')) as fpy:\n\n            for key, value in config.items():\n                fpxi.write(tpxi.format(key, repr(value)))\n                fpy.write(tpy.format(key, repr(value)))\n\n                fh.write(th.format(\n                    key,\n                    value if isinstance(value, int) else '\"{}\"'.format(value)\n                ))\n                self.config_env[key] = str(value)\n\n            if is_sdl2:\n                fh.write('JNIEnv *SDL_AndroidGetJNIEnv(void);\\n')\n                fh.write(\n                    '#define SDL_ANDROID_GetJNIEnv SDL_AndroidGetJNIEnv\\n'\n                )\n\n\nrecipe = AndroidRecipe()\n", "path": "pythonforandroid/recipes/android/__init__.py"}], "after_files": [{"content": "from distutils.core import setup, Extension\nimport os\n\nlibrary_dirs = ['libs/' + os.environ['ARCH']]\nlib_dict = {\n    'sdl2': ['SDL2', 'SDL2_image', 'SDL2_mixer', 'SDL2_ttf']\n}\nsdl_libs = lib_dict.get(os.environ['BOOTSTRAP'], ['main'])\n\nmodules = [Extension('android._android',\n                     ['android/_android.c', 'android/_android_jni.c'],\n                     libraries=sdl_libs + ['log'],\n                     library_dirs=library_dirs),\n           Extension('android._android_billing',\n                     ['android/_android_billing.c', 'android/_android_billing_jni.c'],\n                     libraries=['log'],\n                     library_dirs=library_dirs)]\n\nsetup(name='android',\n      version='1.0',\n      packages=['android'],\n      package_dir={'android': 'android'},\n      ext_modules=modules\n      )\n", "path": "pythonforandroid/recipes/android/src/setup.py"}, {"content": "from pythonforandroid.recipe import CythonRecipe, IncludedFilesBehaviour\nfrom pythonforandroid.util import current_directory\nfrom pythonforandroid import logger\n\nfrom os.path import join\n\n\nclass AndroidRecipe(IncludedFilesBehaviour, CythonRecipe):\n    # name = 'android'\n    version = None\n    url = None\n\n    src_filename = 'src'\n\n    depends = [('sdl2', 'genericndkbuild'), 'pyjnius']\n\n    config_env = {}\n\n    def get_recipe_env(self, arch):\n        env = super().get_recipe_env(arch)\n        env.update(self.config_env)\n        return env\n\n    def prebuild_arch(self, arch):\n        super().prebuild_arch(arch)\n        ctx_bootstrap = self.ctx.bootstrap.name\n\n        # define macros for Cython, C, Python\n        tpxi = 'DEF {} = {}\\n'\n        th = '#define {} {}\\n'\n        tpy = '{} = {}\\n'\n\n        # make sure bootstrap name is in unicode\n        if isinstance(ctx_bootstrap, bytes):\n            ctx_bootstrap = ctx_bootstrap.decode('utf-8')\n        bootstrap = bootstrap_name = ctx_bootstrap\n        is_sdl2 = (bootstrap_name == \"sdl2\")\n        if bootstrap_name in [\"sdl2\", \"webview\", \"service_only\", \"service_library\"]:\n            java_ns = u'org.kivy.android'\n            jni_ns = u'org/kivy/android'\n        else:\n            logger.error((\n                'unsupported bootstrap for android recipe: {}'\n                ''.format(bootstrap_name)\n            ))\n            exit(1)\n\n        config = {\n            'BOOTSTRAP': bootstrap,\n            'IS_SDL2': int(is_sdl2),\n            'PY2': 0,\n            'JAVA_NAMESPACE': java_ns,\n            'JNI_NAMESPACE': jni_ns,\n            'ACTIVITY_CLASS_NAME': self.ctx.activity_class_name,\n            'ACTIVITY_CLASS_NAMESPACE': self.ctx.activity_class_name.replace('.', '/'),\n        }\n\n        # create config files for Cython, C and Python\n        with (\n                current_directory(self.get_build_dir(arch.arch))), (\n                open(join('android', 'config.pxi'), 'w')) as fpxi, (\n                open(join('android', 'config.h'), 'w')) as fh, (\n                open(join('android', 'config.py'), 'w')) as fpy:\n\n            for key, value in config.items():\n                fpxi.write(tpxi.format(key, repr(value)))\n                fpy.write(tpy.format(key, repr(value)))\n\n                fh.write(th.format(\n                    key,\n                    value if isinstance(value, int) else '\"{}\"'.format(value)\n                ))\n                self.config_env[key] = str(value)\n\n            if is_sdl2:\n                fh.write('JNIEnv *SDL_AndroidGetJNIEnv(void);\\n')\n                fh.write(\n                    '#define SDL_ANDROID_GetJNIEnv SDL_AndroidGetJNIEnv\\n'\n                )\n            else:\n                fh.write('JNIEnv *WebView_AndroidGetJNIEnv(void);\\n')\n                fh.write(\n                    '#define SDL_ANDROID_GetJNIEnv WebView_AndroidGetJNIEnv\\n'\n                )\n\n\nrecipe = AndroidRecipe()\n", "path": "pythonforandroid/recipes/android/__init__.py"}]}