4

我正在用 maven 构建 android 项目。但是我发现当我调用getChildFragmentManagerv4.Fragment,它显示了一个错误,即找不到该方法。我怀疑这个support-v4包不够新,因为如果我使用 ant 来构建我的项目,一切都会很好。

但是,我无法将更新support-v4的内容包含到我的项目中。这是我的 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.meishixing</groupid>
    <artifactid>crazysight</artifactid>
    <version>1.0.0-snapshot</version>
    <packaging>apk</packaging>
    <name>crazysight</name>

    <properties>
        <project.build.sourceencoding>utf-8</project.build.sourceencoding>
        <fest-assert.version>1.0.4</fest-assert.version>
        <junit.version>4.10</junit.version>
        <robolectric.version>2.0</robolectric.version>
        <intellij.annotations.version>12.0</intellij.annotations.version>
    </properties>

    <dependencies>
        <dependency>
            <groupid>com.google.android</groupid>
            <artifactid>android</artifactid>
            <version>4.1.1.4</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupid>com.viewpagerindicator</groupid>
            <artifactid>library</artifactid>
            <version>2.4.1</version>
            <type>apklib</type>
        </dependency>

        <dependency>
            <groupid>com.tjerkw</groupid>
            <artifactid>slideexpandablelistview-library</artifactid>
            <version>1.1.0-snapshot</version>
            <type>apklib</type>
        </dependency>

        <dependency>
            <groupid>com.meishixing</groupid>
            <artifactid>android-async-http</artifactid>
            <version>1.4.2</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupid>com.meishixing</groupid>
            <artifactid>baidu-locationp</artifactid>
            <version>3.3</version>
            <type>jar</type>
        </dependency>

        <dependency>
            <groupid>com.google.code.gson</groupid>
            <artifactid>gson</artifactid>
            <version>2.2.4</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupid>org.apache.commons</groupid>
            <artifactid>commons-lang3</artifactid>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupid>com.github.chrisbanes.pulltorefresh</groupid>
            <artifactid>library</artifactid>
            <version>2.1.1</version>
            <type>apklib</type>
        </dependency>
        <dependency>
            <groupid>com.novoda.imageloader</groupid>
            <artifactid>imageloader-core</artifactid>
            <version>1.5.8</version>
        </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.6.2-snapshot</version>
                <configuration>
                    <sdk>
                        <platform>17</platform>
                    </sdk>
                    <manifest>
                        <debuggable>true</debuggable>
                    </manifest>
                </configuration>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>
</project>
4

1 回答 1

2

我已经被这个问题难住了好几个小时(这就是为什么我还增加了赏金),但这就是我最终解决它的方法。

首先,使用检查项目的类路径依赖项

mvn dependency:build-classpath

我可以立即在输出中看到问题:

<home>/.m2\repository\android\extras\android-support\v4\android-support-v4.jar
<home>/.m2\repository\android\platforms\android\android-18\android-android-18.jar
<home>/.m2\repository\com\actionbarsherlock\actionbarsherlock\4.4.0\actionbarsherlock-4.4.0.apklib
<home>/.m2\repository\com\google\android\support-v4\r7\support-v4-r7.jar
<... more jars>

包含两个支持 jar,并且support-v4-r7.jar覆盖了我较新的android-support-v4.jar.

较旧的是 ActionBarSherlock 在我的项目中加载的(在您的项目中,罪魁祸首可能是任何 apklib 依赖项),所以我在我的项目 pom 中排除了它:

<dependency>
        <groupId>com.actionbarsherlock</groupId>
        <artifactId>actionbarsherlock</artifactId>
        <version>4.4.0</version>
        <type>apklib</type>
        <exclusions>
            <exclusion>
                <groupId>com.google.android</groupId>
                <artifactId>support-v4</artifactId>
            </exclusion>
        </exclusions>
</dependency>

希望这可以帮助某人。

于 2013-10-24T13:47:12.980 回答