大龙的博客

常用链接

统计

最新评论

How to include Facebook Android SDK in project as maven module---转自 http://www.hrupin.com/2011/11/how-to-include-facebook-android-sdk-in-project-as-maven-module)

This post will be usefull if you have Android maven multimodule project and want to include Facebook Android SDK  in your project as module.

How do this?

As you see here https://github.com/facebook/facebook-android-sdk the Facebook SDK used not as maven module.

Below you can download source code of Android project

To do this you need:

1. Download the Facebook Android SDK from github.

2. Add Facebook Android SDK lib project in your workspace near other modules of your maven project. Look at screenshot below:

Eclipse Package Manager Screenshot

 

3. Ensure that your facebook dir contauns next files and dirs. Look at screenshot below:

File manager Screenshot

4. Add to parent project’s pom.xml new module. The block may look like this:

1.<modules>
2.<module>facebook</module>
3.<module>application</module>
4.</modules>

5. Add in to facebook dir next pom.xml file. Don’t forget setup group_id, artifact_id and version of your parent project. I noticed in code where you need to do this:

03.<modelVersion>4.0.0</modelVersion>
04. 
05.<parent>
06.<groupId>YOUR_PARENT_PROJECT_GROUP_ID</groupId>
07.<artifactId>YOUR_PARENT_PROJECT_ARTIFACT_ID</artifactId>
08.<version>YOUR_PARENT_PROJECT_VERSION</version>
09.</parent>
10. 
11.<groupId>com.facebook.android</groupId>
12.<artifactId>facebook-android-sdk</artifactId>
13.<version>0.0.1</version>
14.<packaging>jar</packaging>
15.<name>Facebook Android SDK</name>
16. 
17.<dependencies>
18.<dependency>
19.<groupId>com.google.android</groupId>
20.<artifactId>android</artifactId>
21.</dependency>
22.</dependencies>
23.<build>
24.<plugins>
25.<plugin>
26.<groupId>com.jayway.maven.plugins.android.generation2</groupId>
27.<artifactId>maven-android-plugin</artifactId>
28.<configuration>
29.<androidManifestFile>${project.basedir}/AndroidManifest.xml
30.</androidManifestFile>
31.<assetsDirectory>${project.basedir}/assets</assetsDirectory>
32.<resourceDirectory>${project.basedir}/res</resourceDirectory>
33.<nativeLibrariesDirectory>${project.basedir}/src/main/native
34.</nativeLibrariesDirectory>
35.<sdk>
36.<platform>8</platform>
37.</sdk>
38.<deleteConflictingFiles>true</deleteConflictingFiles>
39.<undeployBeforeDeploy>true</undeployBeforeDeploy>
40.</configuration>
41.<extensions>true</extensions>
42.</plugin>
43.<plugin>
44.<artifactId>maven-compiler-plugin</artifactId>
45.<configuration>
46.<source>1.6</source>
47.<target>1.6</target>
48.</configuration>
49.</plugin>
50.</plugins>
51.</build>
52.</project>

6. Change path to java source files from src/com/facebook/android to src/main/java/com/facebook/android

7. Delete all projects from your Eclipse’s package explorer.

8. Import project as Maven project. If you do it right you can see next:

Screenshot-Import Maven projects in EclipseWhen you import this project the Eclipse will create target dir in your facebook project with APK file.

Eclipse - package explorer8. Add Facebook Android SDK dependencies in your application. To do this open pom.xml of your app and add next code in <dependencies>.

1.<dependency>
2.<groupId>com.facebook.android</groupId>
3.<artifactId>facebook-android-sdk</artifactId>
4.<version>0.0.1</version>
5.</dependency>

And whole pom.xml of your app need to be looks like this:

01.<?xml version="1.0" encoding="UTF-8"?>
04.<modelVersion>4.0.0</modelVersion>
05. 
06.<parent>
07.<groupId>YOUR_PARENT_PROJECT_GROUP_ID</groupId>
08.<artifactId>YOUR_PARENT_PROJECT_ARTIFACT_ID</artifactId>
09.<version>YOUR_PARENT_PROJECT_VERSION</version>
10.</parent>
11. 
12.<groupId>com.hrupin</groupId>
13.<artifactId>facebook-android-maven-sample</artifactId>
14.<version>0.0.1-SNAPSHOT</version>
15.<packaging>apk</packaging>
16.<name>facebook-android-maven-sample - Application</name>
17. 
18.<dependencies>
19.<dependency>
20.<groupId>com.google.android</groupId>
21.<artifactId>android</artifactId>
22.</dependency>
23.<dependency>
24.<groupId>com.facebook.android</groupId>
25.<artifactId>facebook-android-sdk</artifactId>
26.<version>0.0.1</version>
27.</dependency>
28.</dependencies>
29.<build>
30.<plugins>
31.<plugin>
32.<groupId>com.jayway.maven.plugins.android.generation2</groupId>
33.<artifactId>maven-android-plugin</artifactId>
34.<configuration>
35.<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
36.<assetsDirectory>${project.basedir}/assets</assetsDirectory>
37.<resourceDirectory>${project.basedir}/res</resourceDirectory>
38.<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
39.<sdk>
40.<platform>8</platform>
41.</sdk>
42.<deleteConflictingFiles>true</deleteConflictingFiles>
43.<undeployBeforeDeploy>true</undeployBeforeDeploy>
44.</configuration>
45.<extensions>true</extensions>
46.</plugin>
47.<plugin>
48.<artifactId>maven-compiler-plugin</artifactId>
49.<configuration>
50.<source>1.6</source>
51.<target>1.6</target>
52.</configuration>
53.</plugin>
54.</plugins>
55.</build>
56.</project>

That’s all. Try to build your project with maven:

1.cd your_parent_project_dir
2.mvn clean install

This sample is not detailed. If you have some troubles you can leave me comment and i will try to ask you.

Hope, it help you!
Download the source code. Here you can download sample project with Facebook Android SDK as maven module

posted on 2012-08-22 13:05 大龙 阅读(372) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理