Incorrect FILE_PROVIDER_PATHS - android

For some reason my update script doesn't work anymore. It basically downloads an .APK file, compares the version with the installed version and when newer -> updates the old app with the new one.
However, since today the FILE_PROVIDER_PATHS doesn't seem to work anymore.
java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Hanenberg/latest-version.apk
So my question: what do I need to add to my filepaths.xml to make this work again? I always use the Hanenberg folder inside the root on emulator/real device.
filepaths.xml:
<?xml version="1.0" encoding="utf-8" ?>
<paths>
<files-path path="/" name="external_storage_root" />
<files-path path="/storage/emulated" name="emulated" />
</paths>
AndroidManifest.xml:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.myfileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/filepaths"/>
</provider>

Try this
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external_files"
path="." />
</paths>

Related

SOLVED Xamarin.Forms Java.Lang.RuntimeException: 'Unable to get provider androidx.startup.InitializationProvider

I have this App that fully works on IOS, but when I try to start on Android Device (Phisical, or Emulated) before hit any Method (OnCreate, OnStart, etc) app crashes and give me this error:
Java.Lang.RuntimeException: 'Unable to get provider androidx.startup.InitializationProvider: java.lang.ClassNotFoundException: Didn't find class "androidx.startup.InitializationProvider" on path: DexPathList[[zip file "/data/app/com.myapp.myapp123-enX6MwKxPJAu9d6bm6sajg==/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp.myapp123-enX6MwKxPJAu9d6bm6sajg==/lib/arm64, /data/app/com.myapp.myapp123-enX6MwKxPJAu9d6bm6sajg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]'
Then after a long search I think the problem may come from two possible points:
-SplashScreen on Android Project
or
-Binding an .AAR file (.AAR file build action is LibraryProjectZip)
But all attempts to fix the problem have failed.
UPDATE
This is Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application android:requestLegacyExternalStorage="true" android:label="My App" android:theme="#style/MainTheme">
<provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:grantUriPermissions="true" android:exported="false">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/filepaths" />
</provider>
</application>
UPDATE 2
Code inside filepaths.xml in resources:
<paths>
<external-path path="." name="mydocuments" />
<external-path name="external_files" path="."/>
<files-path name="files" path="."/>
<internal-path name="internal_files" path="."/>
</paths>
UPDATE 3
I try to:
Delete my code in path and replace it whit the whole code that ColeX has mentioned in the link above (nothing)
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="my_images" path="Pictures" />
<external-files-path name="my_movies" path="Movies" />
</paths>
Keep my code and add the code mentioned (nothing)
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path path="." name="mydocuments" />
<external-path name="external_files" path="."/>
<files-path name="files" path="."/>
<internal-path name="internal_files" path="."/>
<external-files-path name="my_images" path="Pictures" />
<external-files-path name="my_movies" path="Movies" />
</paths>
Replace "external-path" for "external-files-path" and "internal-path" for "internal-files-path" (nothing )
Add and remove
xmlns:android="http://schemas.android.com/apk/res/android"
in all this tries (nothing too)
I can fix the problem, there's nothing wrong in code shared here or in any file, so I think problem has origin from repository where App is loaded. I simply delete the branch (branch equal to master) and create a new one. And now the App in android works well.
Special thanks to ColeX that supports me in this issue and help me to understand that there's nothing wrong in my code

Android app does not start when file provider added to manifest

This is my manifest file
<application>
<provider
android:authorities="${applicationId}.fileprovider"
android:name="android.support.v4.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
</application>
This is my file_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<root-path name="root" path="" />
<external-path name="external_storage_root" path="." />
<external-path name="external_storage_download" path="Download" />
</paths>
When I try and execute my app I get the following errors
Error failed processing manifest. Error resource xml/file_paths
(aka com.companyname.ProjectName:xml/file_paths) not found.
This error is likely caused by an issue with the AndroidManifest.xml
file or an Android manifest generation attribute in a source code
file. Project Name
C:..\source\repos\ProjectName\Properties\AndroidManifest.xml
I searched google and tried alot of solutions but non of them actually worked soo here i am now, hopefully someone can help me.
Did you create a folder named xml in your Resources folder ?
like below:

Upgrade from Xamarin Forms 4.8x to 5.0x throws Android Exception

I upgraded an existing Xamarin Forms 4.8x to XF 5.0x and it is throwing an exception on loading the app in the emulator:
Java.Lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path:
I truncated after emulator: as the rest seemed quite specific to my app.
I am stuck - any help is appreciated!
If you receive the following error, it is because you are using AndroidX. To resolve this error, follow the instructions).
Remove the previous <provider android:name="android.support.v4.content.FileProvider"> tag
(AndroidX) Add the following to your AndroidManifest.xml inside the <application> tags:
<provider android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths"></meta-data>
</provider>
Add a new folder called xml into your Resources folder and add a new XML file called file_paths.xml. Make sure that this XML file has a Build Action of: AndroidResource.
Add the following code:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="my_images" path="Pictures" />
<external-files-path name="my_movies" path="Movies" />
</paths>

Get names of paths used by FileProvider

I have a FileProvider set up in my manifest:
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
and a file_paths.xml as follows:
<paths>
<external-path
name="my-external"
path="." />
<cache-path
name="my-cache"
path="." />
</paths>
I want to then determine whether a Uri is one of these paths. So for example, content://my-cache/blah.jpg is therefore in the cache-path.
Of course, I can do this simply by comparing against a hard-coded string, "my-cache", but is there a way to programmatically obtain the contents of file_paths.xml above?

Android Studio, Element path must be declared for FileProvider

I rerally didn't want to ask this question, but I couldn't find any solutions.
In my manifest I have declared FileProvider:
<provider android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths"/>
</provider>
It requires #xml/provider_paths to work. In my resources folder I have created provider_paths.xml file and copy-pasted this code:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="files" path="."/>
</paths>
However Android Studio IDE throws me that kind of error:
Element paths must be declared
My screenshot:
Move the provider_path.xml from values directory to
res/xml/provider_paths.xml
To specify the directories, start by creating the file filepaths.xml in the res/xml/ subdirectory of your project. In this file, specify the directories by adding an XML element for each directory.
Refer Specify Sharable Directories

Categories

Resources