How to integrate an external library (i.e.: FacebookSDK) properly while creating a Unity Android plugin?

I'm trying to add a missing functionality (App Invites) to the Unity Facebook SDK

I've followed this post in order to create a basic Unity Android plugin by using Android Studio: http://www.thegamecontriver.com/2015/04/android-plugin-unity-android-studio.html. Everything worked as expected and I was able to run the plugin in my project. Then, I've added the FacebookSDK and a static method accessible by Unity:

public static void inviteContacts(Activity root, String linkURL, String previewImageURL)
{      
    if (AppInviteDialog.canShow()) {
        Log.i(TAG, "AppInviteDialog.canShow()!");
        AppInviteContent content = new AppInviteContent.Builder()
                .setApplinkUrl(linkURL)
                .setPreviewImageUrl(previewImageURL)
                .build();
        AppInviteDialog.show(root, content);
    }

}

Unfortunately, when I try to run my plugin, I'm getting this error:

I/Unity﹕ AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/facebook/share/widget/AppInviteDialog;

I took a look at the classes included in my compiled jar plugin, and in fact, there's no facebook classes in it. So, I suspect that there's something wrong with my project setup or my gradle file. This is my gradle file:

apply plugin: 'com.android.library'
android {
            compileSdkVersion 22
    buildToolsVersion "22.0.1"
    sourceSets {
                main {
                    //Path to your source code
                    java {
                        srcDir 'src/main/java'
                    }
                }
            }
            defaultConfig {
                minSdkVersion 15
                targetSdkVersion 22
            }
            buildTypes {
                release {
                    minifyEnabled false
                    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                }
            }
            lintOptions {
                abortOnError false
            }
        }
        dependencies {
            compile project(':facebook')
            compile fileTree(include: ['*.jar'], dir: 'libs')
            compile 'com.android.support:appcompat-v7:22.2.1'
            compile files('libs/classes.jar')
        }
        //task to delete the old jar
        task deleteOldJar(type: Delete) {
            delete 'release/AppInvite.jar'
        }
        //task to export contents as jar
        task exportJar(type: Copy) {
            from('build/intermediates/bundles/release/')
            into('release/')
            include('classes.jar')
            ///Rename the jar
    rename('classes.jar', 'AppInvite.jar')
        }
        exportJar.dependsOn(deleteOldJar, build)

I've also followed these instructions in order to import the module and create the dependency:

Add library project (module) in Android Studio

File -> Import Module

Add library project (module) in build path

File -> Project Structure

Dependency:

app -> Dependencies tab -> green + button -> Module dependency

What am I missing here? What do I need to change in order to compile and export the FacebookSDK classes integrated on my plugin?

Thanks in advance.

Upvotes: 0

Views: 409

Answers (1)

Zohaib Javed
Zohaib Javed

Reputation: 343

Facebook unity SDK supports App Invites.

You can use Facebook AppRequest API to invite to use app. https://developers.facebook.com/docs/unity/reference/current/FB.AppRequest

Upvotes: 1

Related Questions