Maven和Android Facebook SDK apklib

Chr*_*ins 10 android pom.xml maven facebook-android-sdk android-maven-plugin

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

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>
Run Code Online (Sandbox Code Playgroud)

因此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>
Run Code Online (Sandbox Code Playgroud)

在Intellij中构建和运行非常有用,它可以提取依赖性并添加到正确的位置.


问题

当我通过Maven Travis CI命令运行时,它们是:

mvn install -DskipTests=true
Run Code Online (Sandbox Code Playgroud)

然后:

mvn test
Run Code Online (Sandbox Code Playgroud)

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

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

facebook fork在这里可用:https://github.com/Bizzby/facebook-android-sdk

avi*_*ney 12

您可以使用创建的可用Maven存储库来托管最新facebook android api的Maven端口:

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


Chr*_*ins 2

看来我的 apklib pom.xml没问题!不好的是我的 APK pom.xml。似乎从旧编译器版本到新编译器版本存在向后兼容性问题。只是我改变了:

<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>
Run Code Online (Sandbox Code Playgroud)

到:

<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>
Run Code Online (Sandbox Code Playgroud)

它神奇地开始工作了!经验教训,dep/插件管理非常方便!