Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android X support #19

Open
markchristopherng opened this issue Mar 28, 2019 · 13 comments · May be fixed by #20
Open

Android X support #19

markchristopherng opened this issue Mar 28, 2019 · 13 comments · May be fixed by #20

Comments

@markchristopherng
Copy link

Hi
I ran the following plugin and it reports that this library requires jetifier and doesn't support Android X. Will you be releasing an Android X version soon.

https://github.com/plnice/can-i-drop-jetifier/tree/master/canidropjetifier/src/main/kotlin/com.github.plnice/canidropjetifier

@JakeWharton
Copy link
Owner

Out of curiosity and for prioritization, how many other libraries do you use that do not offer AndroidX versions?

@markchristopherng
Copy link
Author

Quite a few, firebase and playservices being the main ones which Google will update one day.

Jetifier adds to the build time but I imagine we will be using Jefitier for most of this year!

  • com.jakewharton.espresso:okhttp3-idling-resource:1.0.0
  • com.squareup.rx.idler:rx2-idler:0.9.1
  • com.squareup.leakcanary:leakcanary-android:1.6.1
  • com.google.android.gms:play-services-auth:16.0.1
  • com.google.android.gms:play-services-maps:16.1.0
  • com.google.android.gms:play-services-location:16.0.0
  • com.google.android.gms:play-services-awareness:16.0.0
  • com.google.android.gms:play-services-auth-api-phone:16.0.0
  • com.google.firebase:firebase-messaging:17.4.0
  • com.google.firebase:firebase-ml-vision:19.0.2
  • com.google.firebase:firebase-core:16.0.7
  • me.dm7.barcodescanner:zxing:1.9.8
  • com.github.JakeWharton:ViewPagerIndicator:2.4.1
  • com.github.barteksc:android-pdf-viewer:2.8.2
  • com.google.firebase:firebase-messaging:17.4.0
  • com.google.android.support:wearable:2.4.0
  • com.google.android.gms:play-services-wearable:16.0.1

@JakeWharton
Copy link
Owner

The build time is only paid once per machine, per version though since the output is cached and re-used. There's no actual build-to-build overhead. There's still downsides, though.

@JakeWharton
Copy link
Owner

JakeWharton commented Apr 8, 2019 via email

@technoir42 technoir42 linked a pull request Jun 5, 2019 that will close this issue
@wbervoets
Copy link

nice, can this be released in a new version? :)

@ZakTaccardi
Copy link

We actually want to avoid using Jetifier because of the following issue: https://stackoverflow.com/questions/57363475/how-can-i-lazily-depend-on-an-aar-that-created-by-a-task

This is one of the last libraries we use that has not been upgraded to AndroidX, so if the PR could be accepted, it would be 👍

@ZakTaccardi
Copy link

One workaround is to use both the support lib and AndroidX in the same module without jetifier.

import com.jakewharton.espresso.OkHttp3IdlingResource
import android.support.test.espresso.IdlingResource as SupportIdlingResource
import android.support.test.espresso.IdlingResource.ResourceCallback as SupportResourceCallback
import androidx.test.espresso.IdlingResource as AndroidXIdlingResource
import androidx.test.espresso.IdlingResource.ResourceCallback as AndroidXResourceCallback

/**
 * Allows [SupportIdlingResource] and [AndroidXIdlingResource] to exist in the same module.
 *
 * This will be needed until [OkHttp3IdlingResource] is migrated to AndroidX.
 * https://github.com/JakeWharton/okhttp-idling-resource/issues/19#issuecomment-518369287
 */
internal fun SupportIdlingResource.asAndroidX(): AndroidXIdlingResource = AndroidXIdlingResource(this)

class AndroidXIdlingResource(private val delegate: SupportIdlingResource) : AndroidXIdlingResource {

    override fun getName(): String = delegate.name

    override fun isIdleNow(): Boolean = delegate.isIdleNow

    override fun registerIdleTransitionCallback(callback: AndroidXResourceCallback) = delegate
        .registerIdleTransitionCallback(callback.asSupport())
}

class SupportResourceCallback(private val delegate: AndroidXResourceCallback) : SupportResourceCallback {
    override fun onTransitionToIdle() = delegate.onTransitionToIdle()

}

internal fun AndroidXResourceCallback.asSupport(): SupportResourceCallback = SupportResourceCallback(this)

Then:

 OkHttp3IdlingResource.create(
                "OkHttp", okHttpClient
            )
                .asAndroidX()

@yasiralijaved
Copy link

yasiralijaved commented Sep 25, 2019

Big effort by @ZakTaccardi
Here is java version of @ZakTaccardi 's workaround if anyone interested.

import androidx.test.espresso.IdlingResource;

public class AndroidXIdlingResource implements IdlingResource {

    private android.support.test.espresso.IdlingResource mDelegate;

    private AndroidXIdlingResource(android.support.test.espresso.IdlingResource supportIdlingResource) {
        mDelegate = supportIdlingResource;
    }

    @Override
    public String getName() {
        return mDelegate.getName();
    }

    @Override
    public boolean isIdleNow() {
        return mDelegate.isIdleNow();
    }

    @Override
    public void registerIdleTransitionCallback(ResourceCallback callback) {
        mDelegate.registerIdleTransitionCallback(new SupportResourceCallback(callback));
    }

    public static AndroidXIdlingResource asAndroidX(android.support.test.espresso.IdlingResource supportIdlingResource) {
        return new AndroidXIdlingResource(supportIdlingResource);
    }


    public class SupportResourceCallback implements android.support.test.espresso.IdlingResource.ResourceCallback {

        private ResourceCallback mDelegate;

        SupportResourceCallback(ResourceCallback androidXResourceCallback) {
            mDelegate = androidXResourceCallback;
        }

        @Override
        public void onTransitionToIdle() {
            mDelegate.onTransitionToIdle();
        }
    }
}

Usage:

@Before
public void setup() {
        OkHttpClient client = //
        IdlingResource idlingResource = OkHttp3IdlingResource.create("OkHttp", client);
        Espresso.registerIdlingResources(AndroidXIdlingResource.asAndroidX(idlingResource));
    }

@neiljaywarner
Copy link

@JakeWharton Do you have a recommendation on this library and/or a release coming? I feel like it should be "safe" and a good choice to use still right?

@fkirc
Copy link

fkirc commented Jan 13, 2020

@JakeWharton what about #20 ?

It would be nice to get this thing merged.
Even if you don't have time for it:
Merging #20 without any testing and without any release seems better than abandoning this library.

@AurelienKun
Copy link

@JakeWharton now that all version above Espresso 3.1.0 is based on AndroidX, could you review your prioritization please ?

@JakeWharton
Copy link
Owner

JakeWharton commented Nov 5, 2020 via email

@nokite
Copy link

nokite commented May 1, 2024

@JakeWharton it would be nice to add a "Deprecated" message in the readme. Thanks for your work btw :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants