12

私はしばらくの間、壁に頭をぶつけて、メイヴン、ロボレクトリック、アクションバーシャーロック、インテリジをすべてうまくプレイできるようにしようとしてきました。私は今のところintellijでの構築をあきらめ、Mavenに焦点を合わせています。

Mavenビルドのテストをスキップすると、アクションバーを備えたアプリがあります(これにより、ActionBar統合の最前線に進むことができます)。IntelliJビルドはManifestParsingTest.javaで失敗し、junitがどこにあるか(他の問題の中でも)わからないと文句を言います。

Robolectric統合

私はすでにプロジェクトでRobolectricを正常に実行していました。Jake Whartonの要点からsrc/test/java/com/blah/blah/support/(にあるものを除いShadowSherlockFragmentActivity.javaて)ファイルをコピーし、src/test/java/com/blah/blah/support/shadows/この行をカスタムテストランナー(supportフォルダーにある)のコンストラクターに配置しました。

ActionBarSherlock.registerImplementation(ActionBarSherlockRobolectric.class);

mvnエラー

私はこれらのビルドエラーに遭遇しています(IntelliJにも同じものの赤い波線があります):

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:testCompile (default-testCompile) on project Blah: Compilation failure: Compilation failure:
[ERROR] /Users/clatislaw/Documents/Code/Android/projectName/src/test/java/com/blah/blah/support/SherlockResourceLoader.java:[29,9] cannot find symbol
[ERROR] symbol  : constructor ResourceLoader(int,java.lang.Class,java.util.List<java.io.File>,java.io.File)
[ERROR] location: class com.xtremelabs.robolectric.res.ResourceLoader
[ERROR] /Users/clatislaw/Documents/Code/Android/projectName/src/test/java/com/blah/blah/support/SherlockResourceLoader.java:[45,5] method does not override or implement a method from a supertype
[ERROR] /Users/clatislaw/Documents/Code/Android/projectName/src/test/java/com/blah/blah/support/ActionBarSherlockTestRunner.java:[39,37] resourceLoaderForRootAndDirectory has private access in com.xtremelabs.robolectric.RobolectricTestRunner
[ERROR] /Users/clatislaw/Documents/Code/Android/projectName/src/test/java/com/blah/blah/support/ActionBarSherlockTestRunner.java:[47,30] cannot find symbol
[ERROR] symbol  : method getResourcePath()
[ERROR] location: class com.xtremelabs.robolectric.RobolectricConfig
[ERROR] /Users/clatislaw/Documents/Code/Android/projectName/src/test/java/com/blah/blah/support/ActionBarSherlockTestRunner.java:[48,9] resourceLoaderForRootAndDirectory has private access in com.xtremelabs.robolectric.RobolectricTestRunner
[ERROR] /Users/clatislaw/Documents/Code/Android/projectName/src/test/java/com/blah/blah/support/ActionBarSherlockTestRunner.java:[38,3] method does not override or implement a method from a supertype

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.blah.blah</groupId>
    <artifactId>projectName</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>apk</packaging>
    <name>Project Name App</name>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>4.0.1.2</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.pivotallabs</groupId>
            <artifactId>robolectric</artifactId>
            <version>1.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>4.8.2</version>
             <scope>test</scope>
        </dependency>

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

        <dependency>
            <groupId>com.actionbarsherlock</groupId>
            <artifactId>library</artifactId>
            <version>4.1.0</version>
            <type>apklib</type>
        </dependency>
    <build>
        <finalName>${project.artifactId}</finalName>

        <plugins>
            <plugin>
                <!-- See http://code.google.com/p/maven-android-plugin/ -->
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <sdk>
                        <platform>15</platform>
                    </sdk>
                </configuration>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>
</project>

不足しているプロジェクト構成はありますか?

4

2 に答える 2

10

Squareでは、このユースケースをサポートするために、Robolectricの修正バージョンを使用しています。私たちはPivotalと協力して、フォークと必要な変更をメインリポジトリの上流で使用することをやめさせています。必要な変更は、リソースロードシステムへのフックです。これらのメソッドは現在プライベートであり、これが表示されているコンパイルの失敗の原因です。

Pivotalは、頻繁にリリースを行うわけではないため、変更によってアップストリームにリリースされる場合はSNAPSHOT、しばらくの間そのバージョンを使用する必要があります。

于 2012-12-05T17:04:21.577 に答える
2

私はそれを機能させることができました。

これを試して:

  • robolectricとjunitの依存関係を最後に移動します。

  • ビルドタグで、finalnameの後、プラグインの前にsrcとテストパスを示します。

  • 再構築して、Mavenツールバーからテストを実行します。

    <dependencies>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <version>4.0.1.2</version>
        <scope>provided</scope>
    </dependency>
    
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>support-v4</artifactId>
        <version>r6</version>
    </dependency>
    
    <dependency>
        <groupId>org.roboguice</groupId>
        <artifactId>roboguice</artifactId>
        <version>2.0</version>
    </dependency>
    
    <dependency>
        <groupId>com.octo.android.robospice</groupId>
        <artifactId>robospice-spring-android</artifactId>
        <version>1.2.0</version>
    </dependency>
    
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.9</version>
    </dependency>
    
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.2.2</version>
    </dependency>
    
    <dependency>
        <groupId>com.actionbarsherlock</groupId>
        <artifactId>actionbarsherlock</artifactId>
        <version>4.2.0</version>
        <type>apklib</type>
    </dependency>
    
    <dependency>
        <groupId>com.actionbarsherlock</groupId>
        <artifactId>actionbarsherlock</artifactId>
        <version>4.2.0</version>
    </dependency>
    
    <dependency>
        <groupId>com.pivotallabs</groupId>
        <artifactId>robolectric</artifactId>
        <version>1.1</version>
        <scope>test</scope>
    </dependency>
    
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope>
    </dependency>
    
    </dependencies>
    
    <build>
    <finalName>${project.artifactId}</finalName>
    
    <sourceDirectory>src</sourceDirectory>
    <testSourceDirectory>test</testSourceDirectory>
    
    <plugins>
        <plugin>
            <!-- See http://code.google.com/p/maven-android-plugin/ -->
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <version>3.2.0</version>
            <configuration>
                <sdk>
                    <platform>15</platform>
                </sdk>
            </configuration>
            <extensions>true</extensions>
        </plugin>
    </plugins>
    </build>
    
于 2013-01-10T14:43:26.623 に答える