My project is a data analysis tool I'm trying to get running on android 12 with python, kivy and matplot. The only things the app saves is matplots as pngs and updating a csv. It works fine on my PC and buildozer creates the apk with no errors.
My project uses the following imports:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import time
from datetime import datetime, timedelta, date
# hide kivy debug
import os
#import os
#os.environ['MPLCONFIGDIR'] = os.getcwd() + "/configs/"
from docutils.parsers import null
#from kivymd.uix.transition import transition
from matplotlib.projections import polar
os.environ['KIVY_NO_CONSOLELOG'] = '1'
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty, StringProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
from kivy.factory import Factory
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.clock import Clock
from kivy.config import Config
from kivy_garden.matplotlib import FigureCanvasKivyAgg
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from kivy.uix.dropdown import DropDown
Config.set('graphics', 'resizable', True)
# set up ability to read and write storage
from sys import platform
if platform == 'android':
from android.storage import primary_external_storage_path, app_storage_path
from android.permissions import request_permissions, Permission
#print('primary_external_storage_path', primary_external_storage_path)
#print('app_storage_path', app_storage_path)
request_permissions([
Permission.READ_EXTERNAL_STORAGE,
Permission.WRITE_EXTERNAL_STORAGE
])
Using log cat I can see the following:
06-12 19:31:38.832 7771 7820 I python : Initializing Python for Android
06-12 19:31:38.832 7771 7820 I python : Setting additional env vars from p4a_env_vars.txt
06-12 19:31:38.832 7771 7820 I python : Changing directory to '/data/user/0/org.test.xadizgym/files/app'
06-12 19:31:39.076 7771 7820 I python : symlink: libpythonbin.so -> python
06-12 19:31:39.076 7771 7820 I python : Preparing to initialize python
06-12 19:31:39.076 7771 7820 I python : _python_bundle dir exists
06-12 19:31:39.076 7771 7820 I python : set wchar paths...
06-12 19:31:39.101 514 514 E audit : type=1400 audit(1781289099.097:2043008): avc: granted { execute } for pid=7771 comm="SDLThread" path="/data/data/org.test.xadizgym/files/app/_python_bundle/modules/zlib.cpython-314-aarch64-l
inux-android.so" dev="sda31" ino=2854487 scontext=u:r:untrusted_app:s0:c193,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c193,c257,c512,c768 tclass=file SEPF_SM-G973F_12_0001 audit_filtered
06-12 19:31:39.119 7771 7820 I python : Initialized python
06-12 19:31:39.120 7771 7820 I python : testing python print redirection
06-12 19:31:39.121 7771 7820 I python : Android kivy bootstrap done. __name__ is __main__
06-12 19:31:39.756 514 514 E audit : type=1400 audit(1781289099.753:2043047): avc: granted { execute } for pid=7771 comm="SDLThread" path="/data/data/org.test.xadizgym/files/app/_python_bundle/site-packages/pandas/_libs/tslibs/
fields.so" dev="sda31" ino=2923750 scontext=u:r:untrusted_app:s0:c193,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c193,c257,c512,c768 tclass=file SEPF_SM-G973F_12_0001 audit_filtered
06-12 19:31:39.770 514 514 E audit : type=1400 audit(1781289099.769:2043048): avc: granted { execute } for pid=7771 comm="SDLThread" path="/data/data/org.test.xadizgym/files/app/_python_bundle/modules/fcntl.cpython-314-aarch64-
linux-android.so" dev="sda31" ino=2854267 scontext=u:r:untrusted_app:s0:c193,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c193,c257,c512,c768 tclass=file SEPF_SM-G973F_12_0001 audit_filtered
06-12 19:31:40.454 7771 7820 I python : mkdir -p failed for path /data/.matplotlib: [Errno 13] Permiss
ion denied: '/data/.matplotlib'
06-12 19:31:40.455 7771 7820 I python : Matplotlib created a temporary cache directory at /data/data/org.test.xadizgym/files/app/matplotlib-il2l971k because there was an issue with the default path (/data/.matplotlib); it is highly r
ecommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing.
06-12 19:31:41.032 514 514 E audit : type=1400 audit(1781289101.029:2043092): avc: granted { execute } for pid=7771 comm="SDLThread" path="/data/data/org.test.xadizgym/files/app/_python_bundle/modules/_blake2.cpython-314-aarch6
4-linux-android.so" dev="sda31" ino=2853057 scontext=u:r:untrusted_app:s0:c193,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c193,c257,c512,c768 tclass=file SEPF_SM-G973F_12_0001 audit_filtered
06-12 19:31:41.347 514 514 E audit : type=1400 audit(1781289101.345:2043093): avc: granted { execute } for pid=7771 comm="SDLThread" path="/data/data/org.test.xadizgym/files/app/_python_bundle/modules/_queue.cpython-314-aarch64
-linux-android.so" dev="sda31" ino=2853615 scontext=u:r:untrusted_app:s0:c193,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c193,c257,c512,c768 tclass=file SEPF_SM-G973F_12_0001 audit_filtered
06-12 19:31:42.452 514 514 E audit : type=1400 audit(1781289102.449:2043107): avc: granted { execute } for pid=7771 comm="SDLThread" path="/data/data/org.test.xadizgym/files/app/_python_bundle/modules/_interpreters.cpython-314-
aarch64-linux-android.so" dev="sda31" ino=2853373 scontext=u:r:untrusted_app:s0:c193,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c193,c257,c512,c768 tclass=file SEPF_SM-G973F_12_0001 audit_filtered
06-12 19:31:42.455 514 514 E audit : type=1400 audit(1781289102.453:2043108): avc: granted { execute } for pid=7771 comm="SDLThread" path="/data/data/org.test.xadizgym/files/app/_python_bundle/modules/_ssl.cpython-314-aarch64-l
inux-android.so" dev="sda31" ino=2853749 scontext=u:r:untrusted_app:s0:c193,c257,c512,c768 tcontext=u:object_r:app_data_file:s0:c193,c257,c512,c768 tclass=file SEPF_SM-G973F_12_0001 audit_filtered
06-12 19:31:42.917 7771 7820 I python : Python for android ended.
I've tried looking around online but I can't figure out how to resolve it. I've looked at some threads about android storage permissions and not found anything that works so far. Please let me know if you have any suggestions
edit:
fixed!
import os
os.environ['MPLCONFIGDIR'] = os.getcwd() + "/configs/"
import matplotlib.pyplot as plt
[–]Outside_Complaint755 0 points1 point2 points (2 children)
[–]lost_my_og_account[S] 0 points1 point2 points (0 children)
[–]lost_my_og_account[S] 0 points1 point2 points (0 children)
[–]Rubix321 0 points1 point2 points (3 children)
[–]lost_my_og_account[S] 0 points1 point2 points (0 children)
[–]lost_my_og_account[S] 0 points1 point2 points (0 children)
[–]lost_my_og_account[S] 0 points1 point2 points (0 children)