Repository: kivy/python-for-android

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"...
```



Discussion:
Seems the code in your linked _android.so library by some reason requests SDL_xxx functions while they are not built in, as your bootstrap is webview, and hence the code you built has no SDL functions in it
Yeah, references to `SDL_Android_GetJNIEnv` are hard coded in the library: https://github.com/kivy/python-for-android/search?q=SDL_Android_GetJNIEnv. I tried replacing it wherever it shows up with `WebView_AndroidGetJNIEnv` (which appears to be [defined here](https://github.com/kivy/python-for-android/blob/ccb0f8e1bab36f1b7d1508216b4b4afb076e614f/pythonforandroid/bootstraps/webview/build/jni/application/src/pyjniusjni.c)?) but that led to a similar error:

```
ImportError: dlopen failed: cannot locate symbol "WebView_AndroidGetJNIEnv" referenced by "/data/data/org.anarres.pdfreader/files/app/_python_bundle/site-packages/android/_android.so"...
```

Resolving patch:
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 @@ def prebuild_arch(self, arch):
                 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'],


Test patch: