【问题标题】:Convert Android Project to Maven将 Android 项目转换为 Maven
【发布时间】:2012-09-23 07:10:39
【问题描述】:

我希望在我接手的项目中使用 Roboelectric 和 roboguice。为此,我需要将当前项目转换为 maven。我一直在看这个

http://code.google.com/p/maven-android-plugin/wiki/GettingStarted

我想知道是否需要做任何不同的事情来转换项目,因为我不是从头开始的。

在将项目推送到 github 时,我还有什么特别需要做的吗?

【问题讨论】:

    标签: android maven github


    【解决方案1】:

    这就是我使用 eclipse 创建的项目的方式。

    首先我将 ANDROID_HOME 添加到我的 /etc/launch.conf 中

    setenv ANDROID_HOME /usr/local/Cellar/android-sdk/r12
    

    为了获取 SDK 的本地 jar 并放入本地 Maven 存储库,我使用了 maven-android-sdk-deployer

    只需克隆存储库并运行 mvn install (仅一个版本可选添加 -P 4.2 )

    然后我使用了来自 roboelectric 的 pom.xml 作为示例,并编辑了我需要的东西。 Roboelectric Quick Start

    确保文件夹结构与/src/main/java和/src/main/test的maven文件夹结构相同

    我的项目没有使用 RoboGuice,但应该只是包含

      <dependency>
        <groupId>org.roboguice</groupId>
        <artifactId>roboguice</artifactId>
        <version>2.0</version>
    </dependency>
    

    这是我的 pom.xml 文件的内容,我使用目标 16 和 17 一样,我收到 Roboelectric 1.1 的错误。

    <dependencies>
        <!-- To get this locally use https://github.com/mosabua/maven-android-sdk-deployer -->
        <dependency>
            <groupId>android</groupId>
            <artifactId>android</artifactId>
            <version>4.2_r1</version>
            <scope>provided</scope>
        </dependency>
    
    
        <!-- Make sure this is below the android dependencies -->
    
        <dependency>
            <groupId>com.pivotallabs</groupId>
            <artifactId>robolectric</artifactId>
            <version>1.1</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <artifactId>sqlite-jdbc</artifactId>
                    <groupId>org.xerial</groupId>   
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>${project.artifactId}</finalName>
        <pluginManagement>
            <plugins>
                <plugin>
                    <!-- http://code.google.com/p/maven-android-plugin/ -->             <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <version>3.5.0</version>
                    <extensions>true</extensions>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <configuration>
                    <sdk>
                        <platform>16</platform>
                    </sdk>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-29
      • 1970-01-01
      • 2012-07-24
      • 2017-03-25
      • 2017-10-19
      • 2013-10-29
      • 2015-12-13
      • 1970-01-01
      相关资源
      最近更新 更多