FragmentActivity can not be tested via ActivityInstrumentationTestCase2

前端 未结 3 1809
轮回少年
轮回少年 2020-12-02 20:51

I have a problem executing android unit tests against android applications that utilize the recently released Fragment support API. When the test is run against a FragmentAc

相关标签:
3条回答
  • 2020-12-02 21:04

    For any IntelliJ users who run into this problem the equivalent fix is to set the scope of your dependency to 'Provided' as follows:

    File > Project Structure > Modules > [select your test app] > dependencies tab > select 'Provided' in scope drop down.

    0 讨论(0)
  • 2020-12-02 21:14

    I spent half the night on this, and finally found a solution. The key line is:

    04-05 18:00:11.276, (Lcom/example/android/app/FragmentLayoutSupport; had used a different Landroid/support/v4/app/FragmentActivity; during pre-verification). 
    

    The problem is that the android-support-v4.jar which you are using in your test project is different from that one in your application project. Remove all of the references to android-support-v4.jar from your test project. Then go to your application project Properties->Java Build Path->Order and Export and check android-support-v4.jar to export it. Now both projects will be using the same library, and dalvik won't complain.

    0 讨论(0)
  • 2020-12-02 21:21

    The IntelliJ answer by Rupert didn't get me all the way there. I solved this by exporting the jar like the Eclipse answer suggested.

    File > Project Structure > Modules > [select your main app] > dependencies tab > click export check box next to the support jar

    IntelliJ Project Structure

    0 讨论(0)
提交回复
热议问题