Godot-Android-Share-Plugin icon indicating copy to clipboard operation
Godot-Android-Share-Plugin copied to clipboard

FileProvider issue on Godot 3.5.3

Open marcio-pessoa opened this issue 1 year ago • 15 comments

Hi dears.

I found an issue when building to Android using latest Godot version (3.5.3):

> Task :processDebugMainManifest FAILED
/home/me/Development/drum_tube/android/build/src/debug/AndroidManifest.xml:28:13-64 Error:
	Attribute provider#androidx.core.content.FileProvider@authorities value=(studio.melen.drumtube.fileprovider) from [godot-lib.debug.aar] AndroidManifest.xml:28:13-64
	is also present at [GodotShare.release.aar] AndroidManifest.xml:18:13-51 value=(studio.melen.drumtube).
	Suggestion: add 'tools:replace="android:authorities"' to <provider> element at AndroidManifest.xml:26:9-34:20 to override.
/home/me/Development/drum_tube/android/build/src/debug/AndroidManifest.xml:33:17-61 Error:
	Attribute meta-data#android.support.FILE_PROVIDER_PATHS@resource value=(@xml/godot_provider_paths) from [godot-lib.debug.aar] AndroidManifest.xml:33:17-61
	is also present at [GodotShare.release.aar] AndroidManifest.xml:23:17-60 value=(@xml/file_provider_paths).
	Suggestion: add 'tools:replace="android:resource"' to <meta-data> element at AndroidManifest.xml to override.

Could you please kindle help me to solve this issue?

Thanks a lot.

marcio-pessoa avatar Oct 07 '23 22:10 marcio-pessoa

Hi, here the same issue on Godot 3.5.3:

/Users/meme/Documents/Godot/Juegos/MultiplicarconMax/android/build/src/debug/AndroidManifest.xml:28:13-64 Error: Attribute provider#androidx.core.content.FileProvider@authorities value=(com.mmicoe.elementaryschoolmultiply.android.fileprovider) from [godot-lib.debug.aar] AndroidManifest.xml:28:13-64 is also present at [GodotShare.release.aar] AndroidManifest.xml:18:13-51 value=(com.mmicoe.elementaryschoolmultiply.android). Suggestion: add 'tools:replace="android:authorities"' to element at AndroidManifest.xml:26:9-34:20 to override. /Users/meme/Documents/Godot/Juegos/MultiplicarconMax/android/build/src/debug/AndroidManifest.xml:33:17-61 Error: Attribute meta-data#android.support.FILE_PROVIDER_PATHS@resource value=(@xml/godot_provider_paths) from [godot-lib.debug.aar] AndroidManifest.xml:33:17-61 is also present at [GodotShare.release.aar] AndroidManifest.xml:23:17-60 value=(@xml/file_provider_paths). Suggestion: add 'tools:replace="android:resource"' to element at AndroidManifest.xml to override.

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.

Help is needed because this plugin is very useful for me!

Thanks a lot.

mmicoe avatar Oct 08 '23 09:10 mmicoe

try it:

Add to your AndroidManifest.xml file, inside the application tag:

    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="${applicationId}.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true"
        tools:replace="android:authorities">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths"
            tools:replace="android:resource" />
    </provider>

gumaciel avatar Oct 13 '23 10:10 gumaciel

Thank you @gumaciel

The last solution you sent me works! Thank you very much for your solution!!!!

<provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true"
            tools:replace="android:authorities">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/godot_provider_paths"
                tools:replace="android:resource"  />
        </provider>

All the best!

mmicoe avatar Oct 13 '23 16:10 mmicoe

The snippet from @gumaciel fixed the issue. Thanks buddy!

marcio-pessoa avatar Oct 15 '23 19:10 marcio-pessoa

I closed this issue, but opened it again as the documentation for this plugin should include the @gumaciel snippet. Otherwise the plugin won't work in Godot version 3.5.3 (and later - maybe).

marcio-pessoa avatar Oct 15 '23 19:10 marcio-pessoa

try it:

Add to your AndroidManifest.xml file, inside the application tag:

    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="${applicationId}.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true"
        tools:replace="android:authorities">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths"
            tools:replace="android:resource" />
    </provider>

What's the path of the manifest file to be edited?

Momo90k avatar Nov 02 '23 12:11 Momo90k

What's the path of the manifest file to be edited?

What's the path of the manifest file to be edited?

Momo90k avatar Nov 05 '23 12:11 Momo90k

Thank you @gumaciel

The last solution you sent me works! Thank you very much for your solution!!!!

<provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true"
            tools:replace="android:authorities">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/godot_provider_paths"
                tools:replace="android:resource"  />
        </provider>

All the best!

What's the path of the manifest file to be edited?

Momo90k avatar Nov 05 '23 12:11 Momo90k

I modified the "project root/android/build/Androidmanifest.xml" file. By adding @gumaciel's <provider> tag as a child of the <application> tag, I succeeded in building it. Unfortunately, I found that the photo sharing feature did not work on Android.

Here's the output from my logcat

11-25 02:08:53.635 17107 17221 D godot : sharePic called
11-25 02:08:53.636 17107 17221 E godot : The selected file can't be shared: /data/data/xxx.yyy.zzz/files/tmp.png

zungm2 avatar Nov 24 '23 17:11 zungm2

I've resolved the issue following the guidance provided by @gumaciel with the following modifications:

  1. In the "GodotProjectRoot/android/build/AndroidManifest.xml" file, I added the following <provider> tag as a child of the <application> tag:
<!-- Any tag in this line after android:icon will be erased when doing custom builds. -->
<!-- If you want to add tags manually, do before it. -->
<!-- WARNING: This should stay on a single line until the parsing code is improved. See GH-32414. -->
<application android:label="@string/godot_project_name_string" android:allowBackup="false" android:isGame="true" android:hasFragileUserData="false" android:requestLegacyExternalStorage="false" tools:ignore="GoogleAppIndexingWarning" android:icon="@mipmap/icon">

	<provider
		android:name="androidx.core.content.FileProvider"
		android:authorities="${applicationId}"
		android:exported="false"
		android:grantUriPermissions="true"
		tools:replace="android:authorities">
		<meta-data
			android:name="android.support.FILE_PROVIDER_PATHS"
			android:resource="@xml/godot_provider_paths"
			tools:replace="android:resource"  />
	</provider>
	
	<!-- Records the version of the Godot editor used for building -->
	<meta-data
		android:name="org.godotengine.editor.version"
		android:value="${godotEditorVersion}" />
	
	...

It was crucial to set the value of android:authorities to ${applicationId} to resolve the issue. This value should match the applicationId specified in the "GodotProjectRoot/android/build/build.gradle" file under android.defaultConfig.applicationId. By default, it is set in the build.gradle file as follows:

applicationId getExportPackageName()

  1. Created the directory "GodotProjectRoot/android/build/res/xml".

  2. Created the file "GodotProjectRoot/android/build/res/xml/godot_provider_paths.xml".

  3. Configured the godot_provider_paths.xml file as follows:

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <files-path name="share_path" path="."/>
    <!-- 'files-path' points to the 'files' directory within the app's internal storage. -->
    <!-- 'path="."' means it includes all files within the files directory. -->
</paths>
  1. Shared the code used in my game to capture and share the screen using this plugin:
func take_screenshot():
	var share_plugin = null
	if Engine.has_singleton("GodotShare"):
		share_plugin = Engine.get_singleton("GodotShare")
	
	if share_plugin == null:
		print("share plugin is null")
		return

	var _screenshot = get_viewport().get_texture().get_data()
	_screenshot.flip_y()

	# Set the amount to crop from the top of the captured image
	var top_space_height = 0

	var crop_height = _screenshot.get_height() - top_space_height

	var cropped_img := Image.new() as Image
	cropped_img.create(_screenshot.get_width(), crop_height, false, _screenshot.get_format())
	cropped_img.blit_rect(_screenshot, Rect2(0, top_space_height, _screenshot.get_width(), crop_height), Vector2.ZERO)

	var _image_save_path = OS.get_user_data_dir() + "/tmp.png"

	var _rand = cropped_img.save_png(_image_save_path)

	share_plugin.sharePic(_image_save_path, "AAA", "BBB", "CCC")

Thanks to this plugin, I was able to easily share my game screen. I am always grateful to the developers for their work.

zungm2 avatar Nov 25 '23 04:11 zungm2

@zungm2 I followed your steps exactly but I have a erorr in building the project because of SDK 32 Godot v 3.5.3 GodotShare Version 3.0.0

fakhridz40 avatar Nov 25 '23 21:11 fakhridz40

try it:

Add to your AndroidManifest.xml file, inside the application tag:

    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="${applicationId}.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true"
        tools:replace="android:authorities">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths"
            tools:replace="android:resource" />
    </provider>

Didn't work. Another error pops up.

Momo90k avatar Nov 25 '23 21:11 Momo90k

@zungm2 I followed your steps exactly but I have a erorr in building the project because of SDK 32 Godot v 3.5.3 GodotShare Version 3.0.0

its working fine I'm dumb i forget to add this codre below sorry and thank you so much <provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}" android:exported="false" android:grantUriPermissions="true" tools:replace="android:authorities">

fakhridz40 avatar Nov 25 '23 22:11 fakhridz40

Thank you @gumaciel and @zungm2 ! No way I would have ever figured this out myself. This should be in the documentation 100%

PseudoC0de avatar Dec 13 '23 23:12 PseudoC0de

I've resolved the issue following the guidance provided by @gumaciel with the following modifications:

1. In the "GodotProjectRoot/android/build/AndroidManifest.xml" file, I added the following `<provider>` tag as a child of the `<application>` tag:
<!-- Any tag in this line after android:icon will be erased when doing custom builds. -->
<!-- If you want to add tags manually, do before it. -->
<!-- WARNING: This should stay on a single line until the parsing code is improved. See GH-32414. -->
<application android:label="@string/godot_project_name_string" android:allowBackup="false" android:isGame="true" android:hasFragileUserData="false" android:requestLegacyExternalStorage="false" tools:ignore="GoogleAppIndexingWarning" android:icon="@mipmap/icon">

	<provider
		android:name="androidx.core.content.FileProvider"
		android:authorities="${applicationId}"
		android:exported="false"
		android:grantUriPermissions="true"
		tools:replace="android:authorities">
		<meta-data
			android:name="android.support.FILE_PROVIDER_PATHS"
			android:resource="@xml/godot_provider_paths"
			tools:replace="android:resource"  />
	</provider>
	
	<!-- Records the version of the Godot editor used for building -->
	<meta-data
		android:name="org.godotengine.editor.version"
		android:value="${godotEditorVersion}" />
	
	...

It was crucial to set the value of android:authorities to ${applicationId} to resolve the issue. This value should match the applicationId specified in the "GodotProjectRoot/android/build/build.gradle" file under android.defaultConfig.applicationId. By default, it is set in the build.gradle file as follows:

applicationId getExportPackageName()

2. Created the directory "GodotProjectRoot/android/build/res/xml".

3. Created the file "GodotProjectRoot/android/build/res/xml/godot_provider_paths.xml".

4. Configured the godot_provider_paths.xml file as follows:
<?xml version="1.0" encoding="utf-8"?>
<paths>
    <files-path name="share_path" path="."/>
    <!-- 'files-path' points to the 'files' directory within the app's internal storage. -->
    <!-- 'path="."' means it includes all files within the files directory. -->
</paths>
5. Shared the code used in my game to capture and share the screen using this plugin:
func take_screenshot():
	var share_plugin = null
	if Engine.has_singleton("GodotShare"):
		share_plugin = Engine.get_singleton("GodotShare")
	
	if share_plugin == null:
		print("share plugin is null")
		return

	var _screenshot = get_viewport().get_texture().get_data()
	_screenshot.flip_y()

	# Set the amount to crop from the top of the captured image
	var top_space_height = 0

	var crop_height = _screenshot.get_height() - top_space_height

	var cropped_img := Image.new() as Image
	cropped_img.create(_screenshot.get_width(), crop_height, false, _screenshot.get_format())
	cropped_img.blit_rect(_screenshot, Rect2(0, top_space_height, _screenshot.get_width(), crop_height), Vector2.ZERO)

	var _image_save_path = OS.get_user_data_dir() + "/tmp.png"

	var _rand = cropped_img.save_png(_image_save_path)

	share_plugin.sharePic(_image_save_path, "AAA", "BBB", "CCC")

Thanks to this plugin, I was able to easily share my game screen. I am always grateful to the developers for their work.

I'm in love with you. Please marry me. You have saved my life.

parlajatwit avatar Jan 26 '24 03:01 parlajatwit