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:

<modules>
	<module>facebook</module>
	<module>application</module>
</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:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<parent>
		<groupId>YOUR_PARENT_PROJECT_GROUP_ID</groupId>
		<artifactId>YOUR_PARENT_PROJECT_ARTIFACT_ID</artifactId>
		<version>YOUR_PARENT_PROJECT_VERSION</version>
	</parent>

	<groupId>com.facebook.android</groupId>
	<artifactId>facebook-android-sdk</artifactId>
	<version>0.0.1</version>
	<packaging>jar</packaging>
	<name>Facebook Android SDK</name>

	<dependencies>
		<dependency>
			<groupId>com.google.android</groupId>
			<artifactId>android</artifactId>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>com.jayway.maven.plugins.android.generation2</groupId>
				<artifactId>maven-android-plugin</artifactId>
				<configuration>
					<androidManifestFile>${project.basedir}/AndroidManifest.xml
					</androidManifestFile>
					<assetsDirectory>${project.basedir}/assets</assetsDirectory>
					<resourceDirectory>${project.basedir}/res</resourceDirectory>
					<nativeLibrariesDirectory>${project.basedir}/src/main/native
					</nativeLibrariesDirectory>
					<sdk>
						<platform>8</platform>
					</sdk>
					<deleteConflictingFiles>true</deleteConflictingFiles>
					<undeployBeforeDeploy>true</undeployBeforeDeploy>
				</configuration>
				<extensions>true</extensions>
			</plugin>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</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>.

<dependency>
	<groupId>com.facebook.android</groupId>
	<artifactId>facebook-android-sdk</artifactId>
	<version>0.0.1</version>
</dependency>

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

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<parent>
		<groupId>YOUR_PARENT_PROJECT_GROUP_ID</groupId>
		<artifactId>YOUR_PARENT_PROJECT_ARTIFACT_ID</artifactId>
		<version>YOUR_PARENT_PROJECT_VERSION</version>
	</parent>

	<groupId>com.hrupin</groupId>
	<artifactId>facebook-android-maven-sample</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>apk</packaging>
	<name>facebook-android-maven-sample - Application</name>

	<dependencies>
		<dependency>
			<groupId>com.google.android</groupId>
			<artifactId>android</artifactId>
		</dependency>
		<dependency>
			<groupId>com.facebook.android</groupId>
			<artifactId>facebook-android-sdk</artifactId>
			<version>0.0.1</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>com.jayway.maven.plugins.android.generation2</groupId>
				<artifactId>maven-android-plugin</artifactId>
				<configuration>
					<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
					<assetsDirectory>${project.basedir}/assets</assetsDirectory>
					<resourceDirectory>${project.basedir}/res</resourceDirectory>
					<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
					<sdk>
						<platform>8</platform>
					</sdk>
					<deleteConflictingFiles>true</deleteConflictingFiles>
					<undeployBeforeDeploy>true</undeployBeforeDeploy>
				</configuration>
				<extensions>true</extensions>
			</plugin>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

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

cd your_parent_project_dir
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!
Here you can download sample project with Facebook Android SDK as maven module

Download it from github

1 Comment

Elbert Rob · 13 November, 2011 at 14:20

I really like to read this post but I don’t have Android maven multimodule project. I think it’ll be very helpful those who are working with this project. Great post! Thanks 🙂

Comments are closed.