如何在创建 Unity Android 插件时正确集成外部库(即:FacebookSDK)?

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

我正在尝试向 Unity Facebook SDK 添加缺少的功能(应用程序邀请)

为了使用 Android Studio 创建一个基本的 Unity Android 插件,我遵循了这个 post:http://www.thegamecontriver.com/2015/04/android-plugin-unity-android-studio.html。一切都按预期工作,我能够 运行 我的项目中的插件。 然后,我添加了 FacebookSDK 和 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);
    }

}

不幸的是,当我尝试 运行 我的插件时,出现了这个错误:

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

我看了一下自己编译好的jar插件中包含的类,其实里面并没有facebook类。所以,我怀疑我的项目设置或我的 gradle 文件有问题。 这是我的 gradle 文件:

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)

我还按照这些说明导入模块并创建依赖项:

在 Android Studio

中添加库项目(模块)

File -> Import Module

在构建路径中添加库项目(模块)

File -> Project Structure

依赖性:

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

我在这里错过了什么?我需要更改什么才能编译和导出集成在我的插件上的 FacebookSDK 类?

提前致谢。

Facebook 统一 SDK 支持 App Invites

您可以使用 Facebook AppRequest API 邀请使用应用程序。 https://developers.facebook.com/docs/unity/reference/current/FB.AppRequest