Robolectric with Maven in an Android library project

227 views
Skip to first unread message

Tyler Treat

unread,
Mar 1, 2013, 2:48:21 AM3/1/13
to robol...@googlegroups.com
I'm trying to use Robolectric with a library project. Since it's a library project and I need a jar for the Maven repository, I need to use the jar packaging and not apklib in my pom.xml. My problem is that, while my Robolectric tests pass when I use apklib packaging, they encounter an error when using jar packaging because it cannot find R.java. Does anyone have any possible workarounds?

Thanks!

Fred Medlin

unread,
May 2, 2013, 4:07:29 PM5/2/13
to robol...@googlegroups.com
Just create an empty res/values/strings.xml in your library project. I've had to do this a couple of times.

Tim Hepner

unread,
May 7, 2013, 5:07:20 PM5/7/13
to robol...@googlegroups.com
I just used a work around for this but I'm not sure if it's a good permanent solution.  You can keep your project as an apklib.  Maven will actually build the jar in the process of producing the apklib.  The problem is it doesn't publish it.  You can have this deployed for other projects using the attach-artifact goal of the build-helper-maven-plugin like this: 

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <id>attach-jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/${project.build.finalName}.jar</file>
                                    <type>jar</type>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Tim Hepner

unread,
May 7, 2013, 5:28:12 PM5/7/13
to robol...@googlegroups.com
Hello,

I use a custom resource directory to combine resources for different
maven build profiles. In my android-maven-plugin configuration I have:

<resourceDirectory>${project.build.directory}/combined-resources/res</resourceDirectory>

This works great except with robolectric. Robolect can see resources in
my res/ folder but not my custom target/combined-resources/res folder.
Is there a way I can configure this with robolectric? Isn't it using
the R.java that maven created with aapt?

thanks,
Tim
Reply all
Reply to author
Forward
0 new messages