anko
anko copied to clipboard
AnkoLogger (and others) not working with androidx
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?
See also #624 Anko does not work with androidx
I have the same problem with:
toast("test")
At least for me is working anko doAsync { ... }
I'm using the 0.10.5 version.
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.
Does anko
work with AndroidX now?
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
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'
}
@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.