Skip to content

Commit e80ddab

Browse files
Fak3rtibbles
authored andcommitted
Add optional android fileprovider.
1 parent bf4bbc5 commit e80ddab

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

pythonforandroid/bootstraps/common/build/build.py

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

540+
if args.fileprovider_paths:
541+
shutil.copy(args.fileprovider_paths, join(res_dir, "xml/file_paths.xml"))
542+
540543
# gradle build templates
541544
render(
542545
'build.tmpl.gradle',
@@ -785,6 +788,8 @@ def parse_args_and_make_package(args=None):
785788
ap.add_argument('--depend', dest='depends', action='append',
786789
help=('Add a external dependency '
787790
'(eg: com.android.support:appcompat-v7:19.0.1)'))
791+
ap.add_argument('--fileprovider-paths', dest='fileprovider_paths',
792+
help=('Add fileprovider paths xml file'))
788793
# The --sdk option has been removed, it is ignored in favour of
789794
# --android-api handled by toolchain.py
790795
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ android {
3737
versionCode {{ args.numeric_version }}
3838
versionName '{{ args.version }}'
3939
manifestPlaceholders = {{ args.manifest_placeholders}}
40+
multiDexEnabled true
4041
}
4142

4243

@@ -81,7 +82,7 @@ android {
8182
}
8283

8384
compileOptions {
84-
{% if args.enable_androidx %}
85+
{% if args.enable_androidx %}
8586
sourceCompatibility JavaVersion.VERSION_1_8
8687
targetCompatibility JavaVersion.VERSION_1_8
8788
{% else %}
@@ -127,5 +128,7 @@ dependencies {
127128
{% if args.presplash_lottie %}
128129
implementation 'com.airbnb.android:lottie:3.4.0'
129130
{%- endif %}
131+
implementation 'com.android.support:support-v4:26.1.0'
132+
implementation 'com.android.support:multidex:1.0.3'
130133
}
131134

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,18 @@
141141
{% for a in args.add_activity %}
142142
<activity android:name="{{ a }}"></activity>
143143
{% endfor %}
144+
145+
{% if args.fileprovider_paths %}
146+
<provider
147+
android:name="android.support.v4.content.FileProvider"
148+
android:authorities="{{ args.package }}.fileprovider"
149+
android:exported="false"
150+
android:grantUriPermissions="true">
151+
<meta-data
152+
android:name="android.support.FILE_PROVIDER_PATHS"
153+
android:resource="@xml/file_paths"/>
154+
</provider>
155+
{% endif %}
144156
</application>
145157

146158
</manifest>

pythonforandroid/toolchain.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,8 @@ def _fix_args(args):
987987
"""
988988

989989
fix_args = ('--dir', '--private', '--add-jar', '--add-source',
990-
'--whitelist', '--blacklist', '--presplash', '--icon')
990+
'--whitelist', '--blacklist', '--presplash', '--icon',
991+
'--fileprovider-paths')
991992
unknown_args = args.unknown_args
992993

993994
for asset in args.assets:

0 commit comments

Comments
 (0)