Issue
First of all I would like to declare my frustration for the lack of proper testing infrastructure in Android... or maybe I am retarded, I don't know...
I eventually managed to setup android-test-plugin and I wrote a couple of tests for an activity that includes in its layout a CustomMapFragment which is a class I wrote that extends SupportMapFragment.
All my tests that try to get an instance of this activity using:
activity = Robolectric.buildActivity(MyActivity.class).create().get();
fail with:
java.lang.NoClassDefFoundError: com/google/android/gms/maps/GoogleMap$OnInfoWindowClickListener
at activity's setContentView.
The activity's xml is the following:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyActivity">
<fragment
android:id="@+id/customMapFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.myproject.CustomMapFragment"/>
</RelativeLayout>
Is there a workaround/solution for this? Any help would be appreciated.
Solution
I have temporary solution. The problem seems to be that the android-test-plugin in unable to read an aar file. My solution is to add a dependency to the jar file instead only to testCompile, like this
testCompile files('YOUR_ANDROID_SDK_FOLDER/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar')
Like this I'm able to run a simple test, for example creating a LatLng and checking if it's not null, without errors. Hope it helps.
Edit
A better solution thanks to SuperJugy on github is to apply the fix in this commit https://github.com/SuperJugy/gradle-android-test-plugin/commit/d5b7836cf7278dc9d0fe765b635de60c33911d72
Answered By - alex
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.