简体   繁体   中英

How can I reference library project in an Android Test-Project (ant build)

There are 3 projects:

  1. Main project
  2. A library project (ActionBarSherlock) referenced by main
  3. A robotium test project.

These three projects are checked out by Jenkins into 3 folders in the workspace.

However, the Robotium test project cannot reference the library project:

  • if only standard "android update test-project" is used, then the test project won't compile because it indirectly references the library project

     [javac] /home/jenkins_test/test/src/com/**********/test/core/**********TestCase.java:15: cannot access com.actionbarsherlock.app.SherlockFragmentActivity [javac] class file for com.actionbarsherlock.app.SherlockFragmentActivity not found [javac] ActivityInstrumentationTestCase2<Home> { [javac] ^ [javac] /home/jenkins_test/test/src/com/**********/test/core/**********TestCase.java:55: cannot find symbol [javac] symbol : constructor Solo(android.app.Instrumentation,com.**********.activity.Home) [javac] location: class com.jayway.android.robotium.solo.Solo [javac] solo = new Solo(getInstrumentation(), getActivity()); [javac] ^ 
  • "android update test-project" does not have --library flag support

  • if android.library.reference.1=../ActionBarSherlock is added to the test project's project.properties, then the test project can compile but at run time it will complain the main activity's class is not found (NoClassDefFoundError)

Unfortunately this fails with ant but tests can be built and run by Eclipse. The only thing you should take into account is checking the robotium library in Java Build Path -> Order and Export in your test project

在此处输入图片说明

and also check that your library project is NOT referenced in the test project's properties

在此处输入图片说明

If you want to test the library project separately you can follow the instructions described in android: testing library projects .

I know this may not be the solution because you are using Jenkins, but at least it will let you start from solid ground.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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