在android工作室使用facebook sdk [英] using facebook sdk in android studio

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

问题描述

我正在关注面向Android的Facebook SDK使用Android Studio 。当我运行我的应用程序时,我得到以下提到的警告。

  Gradle:模块'facebook'将不会被编译。不幸的是,您不能在一个项目中使用非Gradle Java模块和Android-Gradle模块。 

我该如何解决?感谢提前!



更新1:



我尝试过@Scott Barta的答案得到以下错误消息。

 配置项目':App'时出现问题。 
>无法通知项目评估侦听器。
>配置项目':libraries:facebook'时出现问题。
>无法通知项目评估侦听器。
>无法解析配置的所有依赖项:库:facebook:_DebugCompile'。
>找不到符合com.android.support:support-v4:+的任何版本。
必填项:
MyApplication2.libraries:facebook:unspecified


解决方案

注意



对于Android Studio 0.5.5及更高版本以及随后的SDK SDK版本,比以下文档简单(这是为两者的早期版本编写的)。如果您正在运行最新版本,那么您需要做的就是:


  1. https://developers.facebook.com/docs/android/

  2. 解压缩存档

  3. 在Android Studio 0.5.5或更高版本中,从文件菜单中选择导入模块。

  4. 在向导中,设置源路径将要导入的模块作为解压缩存档中的facebook目录。 (注意:如果您选择整个父文件夹,它不仅会导入库本身,还会引入所有示例应用程序,每个应用程序作为单独的模块,这可能会起作用,但可能不是您想要的)。 li>
  5. 通过 Ctrl + Shift + Alt + S 打开项目结构,然后选择依赖选项卡。点击 + 按钮,然后选择模块依赖关系。在新窗口弹出选择:facebook。

  6. 你应该很好去。






旧版Android Studio和旧版SDK SDK的说明

这适用于Android Studio 0.5.4及更早版本,在Facebook提供Gradle构建文件进行分发之前,最有意义的是SDK SDK的版本。我不知道他们在哪个版本的SDK发生了变化。



Facebook的指导将SDK导入到Android Studio项目中的 https://developers.facebook.com/ docs / get-started / facebook-sdk-for-android-using-android-studio / 3.0 / 页面对于基于Gradle的项目是错误的(即,您的项目是使用Android Studio的新建项目向导构建的,应用程序模块的 build.gradle 文件)。请按照以下说明操作:


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


  2. 现在,将SDK
    安装中的整个 facebook 目录复制到文件夹中你刚刚创建


  3. 删除 facebook中的 libs 文件夹目录。如果你喜欢,
    删除 project.properties build.xml .classpath .project 。文件以及。您不需要它们。


  4. 在<$ c $中创建一个 build.gradle c> facebook 目录中的
    以下内容:

      buildscript {
    存储库{
    mavenCentral()
    }
    依赖关系{
    classpath'com.android.tools.build:gradle:0.6.+'
    }
    }

    应用插件:'android-library'

    依赖关系{
    compile'c​​om.android.support:support-v4:+'
    }

    android {
    compileSdkVersion 17
    buildToolsVersion19.0.0

    defaultConfig {
    minSdkVersion 7
    targetSdkVersion 16
    }

    sourceSets {
    main {
    manifest.srcFile'AndroidManifest.xml'
    java.srcDirs = ['src']
    resources.srcDirs = ['src']
    res.srcDirs = ['res']
    }
    }
    }

    请注意,根据何时按照这些说明进行比较,您可能需要调整 classpath'com.android.tools.build:gradle:0.6。 +'行以引用更新版本的Gradle插件。很快,我们将需要0.7或更高版本。尝试一下,如果您发现需要更新版本的Gradle插件,那就是您必须编辑的行。


  5. 确保


  6. 编辑您的 settings.gradle 文件在您的应用程序的主目录
    并添加以下行:

      include':libraries:facebook'


  7. 如果您的项目已在Android Studio中打开,请单击与Gradle文件同步项目按钮。一旦完成,就会出现 facebook 模块。


  8. 打开项目结构对话框。从左侧
    列表中选择模块,单击应用程序的模块,单击依赖项
    选项卡,然后单击+按钮添加新的依赖关系。

  9. 选择
    模块依赖。它将弹出一个对话框,列出
    模块可供选择;选择:图书馆:脸书。

  10. 单击$ b上的确定$ b所有的对话框。
    Android Studio将自动重新同步您的项目(无需再次单击同步项目与Gradle文件按钮)和
    拾取新的依赖关系。你应该很好去。


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.

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

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