繁体   English   中英

Maven无法构建Android项目(不使用Eclipse)

[英]Maven fails to build Android project (not using Eclipse)

当我尝试使用Maven(mvn软件包)构建当前的Android项目时,出现此错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project gs-maven-tabs: Compilation failure: Compilation failure:
[ERROR] /home/kleber/workspace/basic_tab/src/main/java/org/hello/HelloActivity.java:[5,29] error: cannot find symbol
[ERROR] symbol:   class FragmentTabHost
[ERROR] location: package android.support.v4.app
[ERROR] /home/kleber/workspace/basic_tab/src/main/java/org/hello/HelloActivity.java:[9,12] error: cannot find symbol
[ERROR] symbol:   class FragmentTabHost
[ERROR] location: class HelloActivity
[ERROR] /home/kleber/workspace/basic_tab/src/main/java/org/hello/HelloActivity.java:[16,20] error: cannot find symbol
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

与该类有关:

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;

public class HelloActivity extends FragmentActivity {
    // Fragment TabHost as mTabHost
    private FragmentTabHost mTabHost;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.hello_layout);

        mTabHost = (TabHost)findViewById(android.R.id.tabhost);
        mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);

        mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Tab1"), Tab1Fragment.class, null);
        mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Tab2"), Tab2Fragment.class, null);
        mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("Tab3"), Tab3Fragment.class, null);
    }
}

即使将其添加到我的pom.xml中,也会发生此错误:

    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>support-v4</artifactId>
        <version>r6</version>
    </dependency>

我在这里想念的是什么?

ps .:我完整的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>org.hello</groupId>
    <artifactId>gs-maven-tabs</artifactId>
    <version>0.1.0</version>
    <packaging>apk</packaging>

    <properties>
        <!-- use UTF-8 for everything -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <android.sdk.path>/home/kleber/android-sdk-linux/</android.sdk.path>
    </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>r6</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.9.0-rc.1</version>
                <configuration>
                    <sdk>
                        <platform>19</platform>
                    </sdk>
                    <deleteConflictingFiles>true</deleteConflictingFiles>
                    <undeployBeforeDeploy>true</undeployBeforeDeploy>
                </configuration>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <showDeprecation>true</showDeprecation>
                    <showWarnings>true</showWarnings>
                    <executable>/home/kleber/jdk1.7.0_55/bin/javac</executable>
                    <fork>true</fork>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

快速检查jar之后 ,FragmentTabHost类不在该库中!

在大多数情况下,经过几次更新后,这是维护两个构建(IDE和CLI)的主要问题。

您可以在sdk Extras中找到最新的jar,如果没有,请通过SDK管理器下载。

${SDK_HOME}/extras/android/m2repository/com/android/support/support-v4/21.0.0/support-v4-21.0.0.aar

解压缩并从中获取classes.jar(或将其转换为apklib),并用r6存储库文件替换它,或将其安装为新的jar:

mvn install:install-file -Dfile=<path-to-file> -DgroupId=com.google.android \
-DartifactId=support-v4 -Dversion=21.0.0 -Dpackaging=jar



<dependency>
    <groupId>com.google.android</groupId>
    <artifactId>support-v4</artifactId>
    <version>21.0.0</version>
</dependency>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM