使用Facebook SDK在Android的工作室 [英] using facebook sdk in android studio

查看:339
本文介绍了使用Facebook SDK在Android的工作室的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面的<一个href="https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android-using-android-studio/3.0/">Facebook SDK的采用Android工作室的机器人。当我运行我的应用我收到以下提到的警告。

 摇篮:模块的Facebook不会被编译。不幸的是,你不能有非摇篮Java模块和Android的摇篮模块中的一个项目。
 

我应该如何解决这个问题?在此先感谢!

UPDATE1:

我试过@Scott巴塔的回答,并得到以下错误消息。

 发生配置项目中的问题:应用程序。
&GT;未能通知项目评估听众。
   &GT;出现了故障配置项目:图书馆:Facebook的。
      &GT;未能通知项目评估听众。
         &GT;未能解决所有依赖关系配置:图书馆:Facebook的:_DebugCompile。
            &GT;找不到任何匹配com.android.support:support-v4:+版本。
              要求:
                  MyApplication2.libraries:Facebook的:不详
 

解决方案

注意

有关Android的工作室0.5.5或更高版本,以及更高版本的Facebook的SDK中,这个过程比下面是什么文件(这是早期版本的两个写的)要简单得多。如果您运行的是最新的,所有你需要做的是这样的:

  1. 下载Facebook的SDK从<一个href="https://developers.facebook.com/docs/android/">https://developers.facebook.com/docs/android/
  2. 解压缩存档
  3. 在Android的工作室0.5.5或更高版本,从文件菜单中选择导入模块。
  4. 在向导,设置模块的源路径导入为解压压缩文件内的脸谱的目录。 (注:如果您选择了整个父文件夹,它会带来的不仅是库本身,也是所有示例应用程序,每一个单独的模块,这可能工作,但可能不是你想要的。)
  5. 打开项目结构按Ctrl + Shift + Alt键+ S 然后再选择相关性选项卡。点击 + 按钮,然后选择模块依赖关系。在新窗口中弹出选择:Facebook的
  6. 您应该是好去。

说明旧的Andr​​oid的工作室及以上的Facebook SDK

这适用于Android的工作室0.5.4及更早版本,而最有意义的Facebook的SDK之前的Facebook提供的摇篮建立文件分发版本。我不知道在哪个SDK的版本,他们所做的更改。

在Facebook的说明导入SDK到Android的工作室项目在他们的<一个href="https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android-using-android-studio/3.0/">https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android-using-android-studio/3.0/网页是错误的摇篮为基础的项目(即你的项目是采用Android Studio的新建项目向导建立和/或拥有 build.gradle 提交您的应用程序模块)。按照这些指示,而不是:

  1. 创建一个文件夹项目的主目录下。 例如,如果你的项目是HelloWorldProject,您将创建 一个 HelloWorldProject /库文件夹。

  2. 现在将整个的Facebook 目录从SDK 安装到文件夹,您刚刚创建。

  3. 删除文件夹中的的Facebook 目录。如果你喜欢, 删除 project.properties 的build.xml 的.classpath 的.project 。的文件。你不需要他们。

  4. 创建了的Facebook 与目录中的 build.gradle 文件 内容如下:

      buildscript {
        库{
            mavenCentral()
        }
        依赖{
            类路径com.android.tools.build:gradle:0.6.+
        }
    }
    
    应用插件:机器人库
    
    依赖{
        编译com.android.support:support-v4:+
    }
    
    安卓{
        compileSdkVersion 17
        buildToolsVersion19.0.0
    
        defaultConfig {
            的minSdkVersion 7
            targetSdkVersion 16
        }
    
        sourceSets {
            主要 {
                manifest.srcFile的Andr​​oidManifest.xml
                java.srcDirs = ['src'中]
                resources.srcDirs = ['src'中]
                res.srcDirs = ['水库']
            }
        }
    }
     

    请注意,根据你按照这些说明时相比,这是写的时候,您可能需要调整类路径com.android.tools.build:gradle:0.6 +行引用摇篮插件的更新版本。不久,我们将需要0.7或更高版本。试试吧,如果你得到的摇篮插件的更新版本,需要一个错误,那就是你必须编辑该行。

  5. 请确保在 Android的支持库在SDK管理器安装。

  6. 修改 settings.gradle 文件在你的应用程序的主目录 并加入这一行:

     包括':库:Facebook的
     

  7. 如果您的项目已经在Android的Studio中打开,点击同步工程与摇篮文件工具栏中的按钮。一旦完成,将的Facebook 模块应该会出现。

  8. 打开项目结构对话框。选择从所述左手模块 列表中,单击应用程序的模块,点击依赖 选项​​卡,然后单击+按钮添加一个新的依赖。
  9. 选择 模块依赖。它会弹出一个对话框,列表 模块可供选择;选择:库:脸谱。
  10. 单击OK(确定) 所有的对话框。 Android的Studio将自动重新同步您的项目(因此不必单击同步工程与摇篮文件再次按钮)和 拿起新的依赖。你应该是好去。

I'm following Facebook SDK for android using Android Studio. When I run my application I'm getting the below mentioned warning.

Gradle: module 'facebook' won't be compiled. Unfortunately you can't have non-Gradle Java module and Android-Gradle module in one project.

How should I solve this? Thanks in advance!

UPDATE1 :

I tried @Scott Barta's answer and get the following error message.

    A problem occurred configuring project ':App'.
> Failed to notify project evaluation listener.
   > A problem occurred configuring project ':libraries:facebook'.
      > Failed to notify project evaluation listener.
         > Could not resolve all dependencies for configuration ':libraries:facebook:_DebugCompile'.
            > Could not find any version that matches com.android.support:support-v4:+.
              Required by:
                  MyApplication2.libraries:facebook:unspecified

解决方案

NOTE

For Android Studio 0.5.5 and later, and with later versions of the Facebook SDK, this process is much simpler than what is documented below (which was written for earlier versions of both). If you're running the latest, all you need to do is this:

  1. Download the Facebook SDK from https://developers.facebook.com/docs/android/
  2. Unzip the archive
  3. In Android Studio 0.5.5 or later, choose "Import Module" from the File menu.
  4. In the wizard, set the source path of the module to import as the "facebook" directory inside the unpacked archive. (Note: If you choose the entire parent folder, it will bring in not only the library itself, but also all of the sample apps, each as a separate module. This may work but probably isn't what you want).
  5. Open project structure by Ctrl + Shift + Alt + S and then select dependencies tab. Click on + button and select Module Dependency. In the new window pop up select :facebook.
  6. You should be good to go.


Instructions for older Android Studio and older Facebook SDK

This applies to Android Studio 0.5.4 and earlier, and makes the most sense for versions of the Facebook SDK before Facebook offered Gradle build files for the distribution. I don't know in which version of the SDK they made that change.

Facebook's instructions under "Import the SDK into an Android Studio Project" on their https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android-using-android-studio/3.0/ page are wrong for Gradle-based projects (i.e. your project was built using Android Studio's New Project wizard and/or has a build.gradle file for your application module). Follow these instructions instead:

  1. Create a libraries folder underneath your project's main directory. For example, if your project is HelloWorldProject, you would create a HelloWorldProject/libraries folder.

  2. Now copy the entire facebook directory from the SDK installation into the libraries folder you just created.

  3. Delete the libs folder in the facebook directory. If you like, delete the project.properties, build.xml, .classpath, and .project. files as well. You don't need them.

  4. Create a build.gradle file in the facebook directory with the following contents:

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.6.+'
        }
    }
    
    apply plugin: 'android-library'
    
    dependencies {
        compile 'com.android.support:support-v4:+'
    }
    
    android {
        compileSdkVersion 17
        buildToolsVersion "19.0.0"
    
        defaultConfig {
            minSdkVersion 7
            targetSdkVersion 16
        }
    
        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                res.srcDirs = ['res']
            }
        }
    }
    

    Note that depending on when you're following these instructions compared to when this is written, you may need to adjust the classpath 'com.android.tools.build:gradle:0.6.+' line to reference a newer version of the Gradle plugin. Soon we will require version 0.7 or later. Try it out, and if you get an error that a newer version of the Gradle plugin is required, that's the line you have to edit.

  5. Make sure the Android Support Library in your SDK manager is installed.

  6. Edit your settings.gradle file in your application’s main directory and add this line:

    include ':libraries:facebook'
    

  7. If your project is already open in Android Studio, click the "Sync Project with Gradle Files" button in the toolbar. Once it's done, the facebook module should appear.

  8. Open the Project Structure dialog. Choose Modules from the left-hand list, click on your application’s module, click on the Dependencies tab, and click on the + button to add a new dependency.
  9. Choose "Module dependency". It will bring up a dialog with a list of modules to choose from; select ":libraries:facebook".
  10. Click OK on all the dialogs. Android Studio will automatically resynchronize your project (making it unnecessary to click that "Sync Project with Gradle Files" button again) and pick up the new dependency. You should be good to go.

这篇关于使用Facebook SDK在Android的工作室的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆