title: How to integrate an external library (i.e.: FacebookSDK) properly while creating a Unity Android plugin?
body: <p>I'm trying to add a missing functionality (App Invites) to the Unity Facebook SDK</p>
  
  <p>I've followed this post in order to create a basic Unity Android plugin by using Android Studio: <a href="http://www.thegamecontriver.com/2015/04/android-plugin-unity-android-studio.html" rel="nofollow">http://www.thegamecontriver.com/2015/04/android-plugin-unity-android-studio.html</a>. 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:</p>
  
  <pre><code>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);
      }
  </code></pre>
  
  <p>}</p>
  
  <p>Unfortunately, when I try to run my plugin, I'm getting this error:</p>
  
  <blockquote>
    <p>I/Unity﹕ AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/facebook/share/widget/AppInviteDialog;</p>
  </blockquote>
  
  <p>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:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>I've also followed these instructions in order to import the module and create the dependency:</p>
  
  <p>Add library project (module) in Android Studio</p>
  
  <blockquote>
    <p>File -> Import Module</p>
  </blockquote>
  
  <p>Add library project (module) in build path</p>
  
  <blockquote>
    <p>File -> Project Structure</p>
  </blockquote>
  
  <p>Dependency:</p>
  
  <blockquote>
    <p>app -> Dependencies tab -> green + button -> Module dependency</p>
  </blockquote>
  
  <p>What am I missing here? What do I need to change in order to compile and export the FacebookSDK classes integrated on my plugin?</p>
  
  <p>Thanks in advance.</p>