anko icon indicating copy to clipboard operation
anko copied to clipboard

AnkoLogger (and others) not working with androidx

Open hardysim opened this issue 6 years ago • 8 comments

When adding AnkoLogger to any class in a project using androidx (and android.enableJetifier=true) it will not compile with the error Unresolved reference: AnkoLogger.

Is there any way to get anko working with the new androidx packages?

hardysim avatar May 30 '18 11:05 hardysim

See also #624 Anko does not work with androidx

dutchmo avatar Jun 01 '18 02:06 dutchmo

I have the same problem with: toast("test")

hoornet avatar Jun 22 '18 12:06 hoornet

At least for me is working anko doAsync { ... } I'm using the 0.10.5 version.

anargu avatar Jun 30 '18 04:06 anargu

I'm using 0.10.5 version and the only thing that does not work for me is 'act'. Is very useful for work with context in fragment. But, 'toast' etc is working fine now.

EmmanuelGuther avatar Jul 04 '18 10:07 EmmanuelGuther

Does anko work with AndroidX now?

spkingr avatar Aug 01 '18 08:08 spkingr

Here is workaround: Create Extensions.kt file, and paste there this aliases:

inline fun androidx.fragment.app.Fragment.toast(message: CharSequence): Toast? {
    return activity?.toast(message)
}

inline fun androidx.fragment.app.Fragment.toast(message: Int): Toast? {
    return activity?.toast(message)
}
inline fun androidx.fragment.app.Fragment.browse(url: String, newTask: Boolean = false) 
        = activity?.browse(url, newTask)

inline fun androidx.fragment.app.Fragment.selector(
        title: CharSequence? = null,
        items: List<CharSequence>,
        noinline onClick: (DialogInterface, Int) -> Unit
) = activity?.selector(title, items, onClick)

other apis are similarly

stanbar avatar Aug 20 '18 17:08 stanbar

See this thread on the issue tracker: https://issuetracker.google.com/issues/111195890

Adding the latest jetifier (to your global build.gradle) like below works. At least for me and I use anko heavily in one of my projects.

dependencies {
        classpath 'com.android.tools.build.jetifier:jetifier-processor:1.0.0-alpha10'
}

rubengees avatar Aug 20 '18 18:08 rubengees

@4u7

Is the androidx branch where the work is going on for transforming into androidx compatible layouts ? Can we make PRs / contribute to that, or is something in-house being worked on that is not on Github yet ?

I would love to help migrate to androidx, as I need it myself.

championswimmer avatar Dec 02 '18 16:12 championswimmer