我希望在我正在接手的项目中使用 Roboelectric 和 roboguice。为此,我需要将当前项目转换为 Maven。我一直在看这个
http://code.google.com/p/maven-android-plugin/wiki/GettingStarted
我想知道是否需要做任何不同的事情来转换项目,因为我不是从头开始。
将项目推送到github时有什么特别需要做的吗?
最佳答案
这就是我对一个已经用 eclipse 创建的项目的做法。
首先,我将 ANDROID_HOME 添加到我的/etc/launch.conf
setenv ANDROID_HOME /usr/local/Cellar/android-sdk/r12
为了获取 SDK 的本地 jar 并将其放入本地 Maven 存储库,我使用了 maven-android-sdk-deployer
只需克隆存储库并运行 mvn install (仅一个版本可选 add -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>
关于android - 将 Android 项目转换为 Maven,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12690163/