10

So I am in the process of Maven-ing the facebook-android-sdk to include in our CI process.

facebook/pom.xml:

<?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>

<groupId>com.facebook.android</groupId>
<artifactId>facebook-android-sdk</artifactId>
<version>3.0.0-SNAPSHOT</version>
<name>facebook-android-sdk</name>
<packaging>apklib</packaging>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <version>4.1.1.4</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>support-v4</artifactId>
        <version>r7</version>
        <type>jar</type>
    </dependency>
</dependencies>

<build>
    <finalName>${project.artifactId}</finalName>
    <sourceDirectory>src</sourceDirectory>

    <plugins>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <version>3.4.1</version>
            <configuration>
                <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
                <assetsDirectory>ignored</assetsDirectory>
                <resourceDirectory>${project.basedir}/res</resourceDirectory>
                <nativeLibrariesDirectory>ignored</nativeLibrariesDirectory>
                <sdk>
                    <platform>16</platform>
                </sdk>
            </configuration>
            <extensions>true</extensions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <configuration>
                <skip>true</skip>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>maven-replacer-plugin</artifactId>
            <version>1.4.1</version>
            <executions>
                <execution>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>replace</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <ignoreMissingFile>false</ignoreMissingFile>
                <file>target/generated-sources/r/com/facebook/android/R.java</file>
                <outputFile>target/generated-sources/r/com/facebook/android/R.java</outputFile>
                <regex>false</regex>
                <token>static final int</token>
                <value>static int</value>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>attach-artifact</goal>
                    </goals>
                    <configuration>
                        <artifacts>
                            <artifact>
                                <type>jar</type>
                                <file>${project.build.directory}/${project.build.finalName}.jar</file>
                            </artifact>
                        </artifacts>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

So running mvn clean package install builds and installs to the local repository as expected.


So that I can use it in my Android App pom.xml like so:

<!--Facebook sdk-->
<dependency>
    <groupId>com.facebook.android</groupId>
    <artifactId>facebook-android-sdk</artifactId>
    <version>3.0.0-SNAPSHOT</version>
    <type>apklib</type>
</dependency>

Building and running in Intellij works great no problem it pulls the dependency and adds into the correct places.


Problem

When I run via the Maven Travis CI commands which are:

mvn install -DskipTests=true

Then:

mvn test

Testing will fail with missing classes (that being the facebook ones). It seems like when trying to install and test via maven it doesn't pull in the facebook-android-sdk correctly.

So, is there an issue in building the dependency or do i need to run another magical maven command before it tries to run the mvn test?

The facebook fork is avaliable here: https://github.com/Bizzby/facebook-android-sdk

JJD
  • 50,076
  • 60
  • 203
  • 339
Chris.Jenkins
  • 13,051
  • 4
  • 60
  • 61
  • The original project layout is pretty nasty, The two test projects TestApp/ and tests/ are put under library project facebook/, Yes this is recommended by dev guide, but not something Maven like. If you really need them, you need mavenize those two test project too and re-organize them as a multi-module project, i.e. pull them out and make them at the same level as library project, all under a parent project. – yorkw Dec 20 '12 at 22:17
  • yeah I don't really need them. Just want the sdk part. – Chris.Jenkins Dec 20 '12 at 22:19
  • Then you can simply delete or just leave them, note that test phase in an Mavenized Android project is specifically designed which bind to Test project, in general, by running `mvn test` on a pure application or library project probably does nothing other than a compile. – yorkw Dec 20 '12 at 22:36
  • yeah i've removed them, yeah i don't expect it to run tests on the lib, only to include it in my App test phase. which it seems to be failing at athough compiling/install seems to complete. which is odd. I'll add the error when maven starts serving me files again. – Chris.Jenkins Dec 20 '12 at 22:44
  • @yorkw see my answer, seems was to do with my apk pom not the apklib. – Chris.Jenkins Dec 22 '12 at 11:51

3 Answers3

12

You can use available Maven repository created to host the Maven port of the latest facebook android api :

https://github.com/avianey/facebook-api-android-maven

avianey
  • 5,545
  • 3
  • 37
  • 60
  • Thanks for making this! I had a little trouble with it - it wasn't generating the BuildConfig.java file, giving me [ERROR] class Utility [ERROR] target/unpack/apklibs/com.github.avianey_facebook-android-api_apklib_3.0.1/src/com/facebook/Settings.java:[145,19] error: cannot find symbol. I had to manually add the generated BuildConfig.java file to the source, then repackage the apklib. Kind of wonky, but it worked. – phreakhead Jun 12 '13 at 01:22
  • facebook is now pushing the official libs in Maven Central : http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22facebook-android-sdk%22 – avianey Nov 03 '14 at 12:39
2

Right seems that my apklib pom.xml is fine! What isn't fine is my APK pom.xml. Seems that there is a backwards compatibility issue from the old compiler version to the new ones. Simply I changed:

<plugin>
    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
    <artifactId>android-maven-plugin</artifactId>
    <version>3.3</version>
    <configuration>
        <sdk>
            <platform>${android.platform}</platform>
        </sdk>
    </configuration>
</plugin>

to:

<plugin>
    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
    <artifactId>android-maven-plugin</artifactId>
    <version>3.4.1</version>
    <configuration>
        <sdk>
            <platform>${android.platform}</platform>
        </sdk>
    </configuration>
</plugin>

And it magically started working! Lesson learned, dep/plugin management is very handy!

JJD
  • 50,076
  • 60
  • 203
  • 339
Chris.Jenkins
  • 13,051
  • 4
  • 60
  • 61
  • Great solution! Thanks. I got this error: "Could not find tool aapt. Please provide proper Android SDK directory path as configuration parameter". Fixed it by changing the plugin version to 3.6.0 as suggested here: http://stackoverflow.com/questions/16927306/could-not-find-tool-aapt-please-provide-proper-android-sdk-directory-path-as-co – bentzy Dec 09 '13 at 09:17
0

Just run

mvn clean install

that way it will run the tests and everything just fine.

Btw a fully mavenized facebook sdk is available on my github account at

https://github.com/mosabua/facebook-android-sdk/tree/maven

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
  • Tried that, also your SDK out of date, Facebook SDK is up to version 3. – Chris.Jenkins Dec 20 '12 at 23:51
  • I know.. I have no need to update it at the moment and no time to push facebook to actually push the artifacts into the central repository. I tried though – Manfred Moser Dec 21 '12 at 05:28
  • 1
    Yeah they are pretty useless, poor code and project setup + no understanding of resources, anyway offtopic. Any other sugestions? Or could you try it see if compiles for you? I have even `rm -rf repository/` my local repository to no luck. – Chris.Jenkins Dec 21 '12 at 11:10