Shin-NiL / Godot-Android-Share-Plugin

Android share plugin for Godot Game Engine 3.2 or higher
MIT License
52 stars 16 forks source link

FileProvider issue on Godot 3.5.3 #27

Open marcio-pessoa opened 1 year ago

marcio-pessoa commented 1 year ago

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.

mmicoe commented 1 year ago

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.

gumaciel commented 1 year ago

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>
mmicoe commented 1 year ago

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!

marcio-pessoa commented 1 year ago

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

marcio-pessoa commented 1 year ago

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).

Momo90k commented 1 year ago

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 commented 12 months ago

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

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

Momo90k commented 12 months ago

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?

zungm2 commented 11 months ago

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 commented 11 months ago

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.

fakhridz40 commented 11 months ago

@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

Momo90k commented 11 months ago

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.

fakhridz40 commented 11 months ago

@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"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/godot_provider_paths" tools:replace="android:resource" />

PseudoC0de commented 10 months ago

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

parlajatwit commented 9 months ago

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.