10

所以我正在对 facebook-android-sdk 进行 Maven-ing 以包含在我们的 CI 流程中。

脸书/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>

因此,按预期运行mvn clean package install构建并安装到本地存储库。


这样我就可以在我的 Android App pom.xml 中使用它,如下所示:

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

在 Intellij 中构建和运行效果很好,它可以提取依赖项并添加到正确的位置。


问题

当我通过 Maven Travis CI 命令运行时:

mvn install -DskipTests=true

然后:

mvn test

测试将因缺少类(即 facebook 类)而失败。似乎在尝试通过 maven 安装和测试时,它没有正确地拉入 facebook-android-sdk。

那么,在构建依赖项时是否存在问题,或者我是否需要在它尝试运行之前运行另一个神奇的 maven 命令mvn test

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

4

3 回答 3

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

于 2013-02-05T12:30:19.640 回答
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!

于 2012-12-22T11:50:29.650 回答
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

于 2012-12-20T23:29:50.003 回答