Skip to content

Commit ebca6a8

Browse files
authored
Merge pull request #7 from jamalex/pew_webview
Add usesCleartextTraffic flag so webview works for Android 9 & 10, and --fileprovider-paths support
2 parents df52687 + 440f411 commit ebca6a8

File tree

6 files changed

+38
-2
lines changed

6 files changed

+38
-2
lines changed

pythonforandroid/bootstraps/common/build/build.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,9 @@ def make_package(args):
469469
remove('AndroidManifest.xml')
470470
shutil.copy(manifest_path, 'AndroidManifest.xml')
471471

472+
if args.fileprovider_paths:
473+
shutil.copy(args.fileprovider_paths, join(res_dir, "xml/file_paths.xml"))
474+
472475
# gradle build templates
473476
render(
474477
'build.tmpl.gradle',
@@ -674,6 +677,8 @@ def parse_args_and_make_package(args=None):
674677
ap.add_argument('--depend', dest='depends', action='append',
675678
help=('Add a external dependency '
676679
'(eg: com.android.support:appcompat-v7:19.0.1)'))
680+
ap.add_argument('--fileprovider-paths', dest='fileprovider_paths',
681+
help=('Add fileprovider paths xml file'))
677682
# The --sdk option has been removed, it is ignored in favour of
678683
# --android-api handled by toolchain.py
679684
ap.add_argument('--sdk', dest='sdk_version', default=-1,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

pythonforandroid/bootstraps/common/build/templates/build.tmpl.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ android {
3232
targetSdkVersion {{ android_api }}
3333
versionCode {{ args.numeric_version }}
3434
versionName '{{ args.version }}'
35+
multiDexEnabled true
3536
}
3637

3738
{% if debug_build -%}
@@ -98,4 +99,6 @@ dependencies {
9899
compile '{{ depend }}'
99100
{%- endfor %}
100101
{%- endif %}
102+
compile 'com.android.support:support-v4:26.1.0'
103+
compile 'com.android.support:multidex:1.0.3'
101104
}

pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@
132132
{% for a in args.add_activity %}
133133
<activity android:name="{{ a }}"></activity>
134134
{% endfor %}
135+
136+
{% if args.fileprovider_paths %}
137+
<provider
138+
android:name="android.support.v4.content.FileProvider"
139+
android:authorities="{{ args.package }}.fileprovider"
140+
android:exported="false"
141+
android:grantUriPermissions="true">
142+
<meta-data
143+
android:name="android.support.FILE_PROVIDER_PATHS"
144+
android:resource="@xml/file_paths"/>
145+
</provider>
146+
{% endif %}
135147
</application>
136148

137149
</manifest>

pythonforandroid/bootstraps/webview/build/templates/AndroidManifest.tmpl.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
android:icon="@drawable/icon"
5050
android:allowBackup="true"
5151
android:theme="{{args.android_apptheme}}{% if not args.window %}.Fullscreen{% endif %}"
52-
android:hardwareAccelerated="true" >
52+
android:hardwareAccelerated="true"
53+
android:usesCleartextTraffic="true" >
5354
{% for l in args.android_used_libs %}
5455
<uses-library android:name="{{ l }}" />
5556
{% endfor %}
@@ -92,6 +93,19 @@
9293
</intent-filter>
9394
</receiver>
9495
{% endif %}
96+
97+
{% if args.fileprovider_paths %}
98+
<provider
99+
android:name="android.support.v4.content.FileProvider"
100+
android:authorities="{{ args.package }}.fileprovider"
101+
android:exported="false"
102+
android:grantUriPermissions="true">
103+
<meta-data
104+
android:name="android.support.FILE_PROVIDER_PATHS"
105+
android:resource="@xml/file_paths"/>
106+
</provider>
107+
{% endif %}
108+
95109
</application>
96110

97111
</manifest>

pythonforandroid/toolchain.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,8 @@ def apk(self, args):
955955
# we can't leave it until later as the build.py scripts assume
956956
# they are in the current directory.
957957
fix_args = ('--dir', '--private', '--add-jar', '--add-source',
958-
'--whitelist', '--blacklist', '--presplash', '--icon')
958+
'--whitelist', '--blacklist', '--presplash', '--icon',
959+
'--fileprovider-paths')
959960
unknown_args = args.unknown_args
960961
for i, arg in enumerate(unknown_args):
961962
argx = arg.split('=')

0 commit comments

Comments
 (0)