Search code examples
androidfacebooklibgdx

Android libgdx does not recognize Facebook ShareDialog (Facebook SDK)


I have a problem in integration Facebook Sharedialog with my android libgdx game:

  1. In build.gradle (Project), I added mavenCentral() in the buildscript { repositories {}} section.

  2. In build.gradle (Module: android) I added implementation 'com.facebook.android:facebook-share:7.1.0' and implementation 'com.facebook.android:facebook-common:7.1.0' in dependencies.

  3. But in my MyGdxGame when I declared ShareDialog, it came with following error:

    Cannot resolve symbol ShareDialog, Add library 'Gradle:com.facebook.amdroid:facebook-common:7.1.0@aar' to classpath.

    Even it did not recognize the import com.facebook.share.widget.ShareDialog.

I've tried the same with a normal Android app that is not Libgdx game and seen Facebook ShareDialog worked well.

Could you please advise if I did anything wrong?

I also tried with another library: gdx-facebook (https://github.com/TomGrill/gdx-facebook) but failed because the method publish_actions was deprecated. The detail can be found here: https://developers.facebook.com/blog/post/2018/07/31/platform-update-publish-permission/


Solution

  • You declared your dependency in the android module, but MyGdxGame is in your core module - that's the problem here. You need to follow the documentation for working with platform dependant code.