13

We are trying to run tests on travis CI. We have a class which uses android.support.v4.widget.DrawerLayout.

When we use android support v4 library
build.gradle->

targetSdkVersion: 19
`compile 'com.android.support:support-v4:20.0.0'`

.travis.yml

- build-tools-19.1.0
- android-19
- extra-android-support
- extra-google-google_play_services
- extra-google-m2repository

we donot get this error but on using

build.gradle ->

targetSdkVersion: 21
com.android.support:support-v4:21.0.+

.travis.yml

- build-tools-21.0.1
- android-21
- extra-android-support
- extra-google-google_play_services
- extra-google-m2repository

We get the error

 private static class IdlingDrawerListener implements DrawerListener, IdlingResource {
                   ^
  class file for android.support.v4.widget.DrawerLayoutImpl not found
/home/travis/build/something/sample/src/test/java/com/abc/somesample/espresso/DrawerActions.java:200: error: cannot find symbol
        private ResourceCallback callback;
                ^
  symbol:   class ResourceCallback
  location: class IdlingDrawerListener
/home/travis/build/something/sample/src/test/java/com/abc/somesample/espresso/DrawerActions.java:255: error: cannot find symbol
        public void registerIdleTransitionCallback(ResourceCallback callback) {
                                                   ^
  symbol:   class ResourceCallback
  location: class IdlingDrawerListener
/home/travis/build/something/sample/src/test/java/com/abc/somesample/espresso/DrawerActions.java:153: error: method setDrawerListener in class DrawerLayout cannot be applied to given types;
                drawer.setDrawerListener(IdlingDrawerListener.getInstance(existingListener));
                      ^
  required: DrawerListener
  found: IdlingDrawerListener
  reason: actual argument IdlingDrawerListener cannot be converted to DrawerListener by method invocation conversion
/home/travis/build/something/sample/src/test/java/com/abc/somesample/espresso/DrawerActions.java:192: error: cannot find symbol
                instance = new IdlingDrawerListener();
                           ^
  symbol:   constructor IdlingDrawerListener()
  location: class IdlingDrawerListener
/home/travis/build/something/sample/src/test/java/com/abc/somesample/espresso/DrawerActions.java:193: error: method registerIdlingResources in class Espresso cannot be applied to given types;
                Espresso.registerIdlingResources(instance);
                        ^
  required: IdlingResource[]
  found: IdlingDrawerListener
  reason: argument type IdlingDrawerListener does not conform to vararg element type IdlingResource
/home/travis/build/something/sample/src/test/java/com/abc/somesample/espresso/DrawerActions.java:205: error: non-static variable this cannot be referenced from a static context
            this.parentListener = parentListener;
            ^
/home/travis/build/something/sample/src/test/java/com/abc/somesample/espresso/DrawerActions.java:205: error: cannot find symbol
            this.parentListener = parentListener;
                ^
  symbol: variable parentListener
/home/travis/build/something/sample/src/test/java/com/abc/somesample/espresso/DrawerActions.java:208: error: method does not override or implement a method from a supertype
        @Override
        ^
/home/travis/build/something/sample/src/test/java/com/abc/somesample/espresso/DrawerActions.java:215: error: method does not override or implement a method from a supertype
        @Override
        ^

/home/travis/build/something/sample/src/test/java/com/abc/somesample/espresso/DrawerActions.java:256: error: non-static variable this cannot be referenced from a static context
            this.callback = callback;
            ^
/home/travis/build/something/sample/src/test/java/com/abc/somesample/espresso/DrawerActions.java:256: error: cannot find symbol
            this.callback = callback;
                ^
  symbol: variable callback
/home/travis/build/something/sample/src/test/java/com/abc/somesample/espresso/DrawerActions.java:254: error: method does not override or implement a method from a supertype
        @Override
        ^

Travis even shows that it has downloaded and installed Android Support Library revision 21, but still the above error.

Update:

We tried to run tests on the VM set up by travis guys.

  • The tests failed with the same error when ran on the machine initially.
  • Tried by manually copying internal_impl-21.0.0.jar found inside the support-v4 aar file to our libs/ directory and the tests passed.
  • Manually installed Android SDK tools 23.0.5 on the VM and the tests passed.

Our project .travis.yml has the following lines:

- tools - platform-tools - build-tools-21.1.1 - android-21 - extra-android-support - extra-android-m2repository - extra-google-m2repository Still the tests are failing on travis.

ragdroid
  • 271
  • 3
  • 12
  • How is this being built? v20 of the support library doesn't have a DrawerLayoutImpl at all; v21 has it, but it's not in classes.jar in the archive; it's in libs/internal_impl-20.0.0.jar. However, a test case builds okay for me, so I'm not sure what's different about your setup. Does Gradle build it okay from the command line on your workstation? – Scott Barta Oct 21 '14 at 16:51
  • 2
    A similar bug is reported in the AOSP issue tracker https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=77682 – Gaurav Vashisth Oct 22 '14 at 05:59
  • @ScottBarta yes. gradle is building it okay from the command line on my workstation. On my workstation inside support library v21: I can see `DrawerLayoutImpl` inside the classes.jar. – ragdroid Oct 22 '14 at 06:35
  • 2
    I've got the same problem on Jenkins build system. It works fine on local machine, but crashes on Jenkins for some reason. – Mikooos Oct 22 '14 at 06:48
  • 2
    @Mikooos You can easily check the androidsdk in your machine running jenkins. Is there any difference in the classes in v21 jar in your local machine and v21 jar in the jenkins machine – Gaurav Vashisth Oct 22 '14 at 07:59
  • 1
    I had the same issue with Jenkins. After much experimentation I was able to find a fix for my project. The problem stems from building a freshly cloned project. The first build will fail, and subsequent builds will succeed. You can try this on your local machine to verify. The solution for Jenkins was to delete the step which cleared the workspace, however I can't think of a solution for Travis. – Michael Pardo Oct 27 '14 at 20:12
  • 1
    So right now the only fix is to manually install or manually include the jar mentioned above? Is that what you're doing for the time being? – loeschg Nov 25 '14 at 22:31
  • 1
    yes! that's what we are doing. – ragdroid Nov 27 '14 at 12:04

6 Answers6

1

This sounds like a bug in travis. If it does not use Gradle to build everything but does some building on its own (which it sounds like, given that you have special YAML files listing dependencies), it needs to handle AAR file dependencies by not just including classes.jar, but jars under libs/ as well.

Tor Norbye
  • 9,062
  • 3
  • 29
  • 24
  • What is it that Travis needs to do? Travis runs `gradle build connectedCheck` (http://git.io/4Th6Xg) when an appropriate file is found. What else is required? – banzaiman Oct 26 '14 at 01:37
  • @tor-norbye issue was raised regarding this: [issue link](https://github.com/travis-ci/travis-ci/issues/2897) – ragdroid Nov 14 '14 at 07:16
1

1. ActionBarDrawerToggle: deprecation, new version style for Lollipop and updated samples

DrawerLayout has a nested interface DrawerListener implemented by:

  1. android.support.v4.app.ActionBarDrawerToggle (deprecated on API 21).
  2. android.support.v7.app.ActionBarDrawerToggle (recommended version).

The new support-v7-appcompat version is compatible with Android Lollipop and Material Design style.

See this response to update it, or the Google I/O app implementation and Google sample.

Requires latest SDK version, appcompat-v7.21.0.+, support-v4.21.0.+ and Android Support Repository.


2. Travis configuration: Latest SDK tools, platform-tools, build-tools and extra-m2repository required

Add extra-android-m2repository and build-tools-21.1.1 to android: components:.

Travis CI for Android projects uses tools 23.0.2 by default, Lollipop requires SDK tools 23.0.5.

Important: To download the most recent Android system components from the Android SDK Manager, you must first update the SDK Tools to the most recent release and restart the SDK Manager. If you do not, the latest Android system components will not be available for download.

You need update SDK tools first so you get the latest revisions of the other components. Tools v23.0.5 requires platform-tools v19+ to be updated and v21+ to work. Plus platform, sys-img, etc. Try this:

android:
  components:
    # Uncomment the lines below if you want to
    # use the latest revision of Android SDK Tools
    - platform-tools
    - tools
    - build-tools-21.1.1
    - android-21
    - extra-android-support
    - extra-android-m2repository
    - extra-google-m2repository
    - extra-google-google_play_services
    - sys-img-armeabi-v7a-android-21
  licenses:
    - 'android-sdk-license-5be876d5'

3. Important: Gradle based projects require extra-android-m2repository no extra-android-support

extra-android-m2repository contains the artifacts (.aar files) for gradle/android studio.

Note: If you're developing with Android Studio, select and install the Android Support Repository item instead (of Android Support Library on Eclipse).

Further info for Android Studio: https://developer.android.com/tools/support-library/setup.html


4. The missing DrawerLayoutImpl class contained in android.support:support-v4:21.0.2 internal .jar

Missing DrawerLayoutImpl

You can try to change 21.0.+ to 21.0.2. I'm not sure about Travis-ci dependency resolution workflow.

compile 'com.android.support:support-v4:21.0.2'

compile 'com.android.support:appcompat-v7:21.0.2'

I dont know but perhaps it copies other android.support version without the inner missing class and jar.

Check if the internal jar is there by adding something as this to your build:

export MOD_NAME= yourapplicationmodulename

'cat ${TRAVIS_BUILD_DIR}/${MOD_NAME}/build/intermediates/tmp/dex/debug/libraryList.txt'

If you use 21.0.+ and download the m2repository 21.0.0 version but then looks for updated versions on maven it foundd Android Support Library, revision 21.0.1 without the aar, so try the new 21.0.2 version.


5. Espresso or Double Espresso, DrawerActions, espresso-contrib jar and other dependencies

About Espresso and other transitive dependencies to old support libraries, you could try to upgrade them or exclude the android.support dependencies:

configurations {
    compile.exclude group: 'com.android.support'
}

I'm not familiar with Double espresso, a pure Gradle port of the Espresso testing utility for Android but Jake Wharton writes here (Related issue):

Duplicated Dependencies

Due to a bug in the current Android plugin, you may need to exclude dependencies which are duplicated in both the app and test app.

For example, if you have a dependency on Dagger you will need to manually exclude it from the test dependency for the time being.

androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3') {
exclude group: 'com.squareup.dagger' } The following are the dependencies of Espresso which may need to be temporarily excluded:

com.squareup.dagger:dagger:1.2.1 ... and those of the 'support-v4' module:

com.android.support:support-v4:21.0.0 <-----------

About Espresso, I read that supports up to kitkat but I don't know if Lollipop is now fully supported and I found a related issue about Espresso.registerIdlingResources(instance) and I quote from here:

Sometimes you want to use a version of Espresso where you are in control of the dependencies For example, Espresso utilizes Hamcrest Matchers and therefore has an explicit dependency on it. To avoid errors while Dexing your test code you can use the no dependencies version of Espresso and explicitly declare your dependencies

If you need any functionality from the contrib library, such as DrawerActions, copy the espresso-contrib jar from here. Espresso actions for using a DrawerLayout.


6. ProGuard shrinking step: update rules for API 21 changes

I'm using Google I/O app implementation as I saw you are doing to learn Material Design and all this stuff. They recently updated the app, added app-compat and fixed nav drawer but I think they didn't update ProGuard rules. If you are using a similar configuration, I suggest you update it and check the aapt rules to be sure missing classes are kept.

As an experimental sample, I'm learning it too, I added the new API 21 View constructor and includedescriptorclasses

# Added includedescriptorclasses for unkept android.support descriptors
-keep,includedescriptorclasses public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public <init>(android.content.Context, android.util.AttributeSet, int, int); # Added in API 21
public void set*(...);

And 43 of 44 notes about unkept descriptors were solved, included

Note: the configuration keeps the entry point 'android.support.v4.widget.DrawerLayout { void setDrawerListener(android.support.v4.widget.DrawerLayout$DrawerListener); }', but not the descriptor class 'android.support.v4.widget.DrawerLayout$DrawerListener'

Community
  • 1
  • 1
albodelu
  • 7,931
  • 7
  • 41
  • 84
  • I added another possibility. Perhaps you need v7 appcompat. Plus extra-android-m2repository... – albodelu Nov 15 '14 at 15:22
  • I did a rollback, the solution was in bold in the last line of point 5 but you said that it was a gradle issue http://stackoverflow.com/posts/27358362/revisions and I deleted it when they updated espresso :) – albodelu Oct 27 '15 at 09:24
1

Edited Answer:

This issue is fixed by using the pre-compiled DrawerActions.java class from the espresso-contrib library. For setup instructions see the link.

ragdroid
  • 271
  • 3
  • 12
1

Manually adding the library to the server in build.gradle worked:

testCompile fileTree(dir: "${rootDir}/YourProject/build/intermediates/exploded-aar/com.android.support/support-v4/", include: "**/*.jar")
Aliya
  • 1,168
  • 12
  • 17
0

You may be running into this issue(?) https://code.google.com/p/android/issues/detail?id=77682#c11.

The last comment, by @Tor Norbye, ironically :), says

The class loader issue is fixed for 0.8.14. The gradle sync issue has to be fixed on the model side in Gradle 0.14.

loeschg
  • 29,961
  • 26
  • 97
  • 150
0

After multiple tests, it worked for me adding the dependency:

compile 'com.android.support:internal_impl:22.2.0'

Unfortunately, you have to keep this JAR updated, when you change the 'support' lib version.

Nicola
  • 425
  • 4
  • 17