
Android KTX: Kotlin Development for Android - ingve
https://android-developers.googleblog.com/2018/02/introducing-android-ktx-even-sweeter.html
======
vesinisa
> You may notice that Android KTX uses package names that begin with androidx.
> This is a new package name prefix that we will be using in future versions
> of Android Support Library. We hope the division between android.* and
> androidx.* makes it more obvious which APIs are bundled with the platform,
> and which are static libraries for app developers that work across different
> versions of Android.

Ugh, okay. It's going to be a blast refactoring all my existing code and
custom tools to reference this new package.

~~~
jontro
Hopefully just a couple of simple global search and replaces? Anyways I think
the current support library structure is confusing and it's a good thing that
they will refactor it.

~~~
izacus
Android Studio handles that pretty well and it'll probably fix most of those
in a single "Optimize imports" pass.

------
Rockvole
As an alternative to learning Kotlin on Android, you can spend the time
learning flutter. Then you get concise code which works on Android and IOS now
and on other platforms in the future - including desktops.

~~~
nolok
And it's made by Google, unsurprinsingly.

A big plus for Kotlin is that being a jetbrains project, it has top of the
line intellij tooling support right at release date.

~~~
ClassyJacket
If it's made by Google, shouldn't we avoid it as it's likely to be
discontinued in a few months?

~~~
akmittal
Flutter will be official development platform for Google Fuchsia, their next
big OS*. Google is supporting Android and iOS with flutter So that they can
have plenty of apps available already when Fuchsia is launched.

With the big investment they are doing in Fuchsia it seem unlikely they will
abandon it soon.

~~~
cube2222
Big investment? Their next big os?

Please give us some sources, as to me it's just a project a team there is
developing, and so far it can just as well be an experiment with no future.

------
barbs
Not to be confused with Kotlin Android Extensions, which although handy is
really just a convenient way to reference views in XML.

[https://kotlinlang.org/docs/tutorials/android-
plugin.html](https://kotlinlang.org/docs/tutorials/android-plugin.html)

~~~
mncolinlee
Kotlin Android Extensions is a tad more than that. It's also a View cache that
grabs all view references in a single pass. I routinely have to explain to
other senior Android developers that findViewById() traverses the entire view
hierarchy until it finds that ID each time you call it. This won't be
noticeable with simple views, but becomes a bigger problem as complexity
increases. Which also results in more wasteful calls to findViewById().

Android Data Binding does something very similar to Kotlin Android Extensions,
which is why it also perplexes me to see experienced devs bind a model to a
view and then call findViewById() to alter it. I'll see calls to
binding.getRoot().findViewById(), which is crazy redundant.

------
bitwize
Still working in Java on Android. Have a feeling that I will be left behind
soon.

~~~
wootie512
Same here. On my my most recent project the client requested we use Java,
since after they take over they can use devs with Java knowledge.

~~~
firefruit
It will take a week or two to convert experienced Java devs to Kotlin.

~~~
wootie512
Yea I agree. I like Kotlin a lot and found the transfer from Java to Kotlin
fairly straightforward.

Just not all clients are open to one more thing for their devs to do/learn. In
the specific case for us, the devs were new to Android so they wanted to use a
language they were comfortable in.

~~~
pennaMan
If they are new to Android how are they comfortable in Androids' take on Java?
Trying to use paradigms from enterprise/server side Java in Android is going
to backfire hard on all but the most trivial projects.

------
MBlume
Curious, is anyone inside of Google using Kotlin for their Android apps, or is
this all for third party developers?

~~~
mncolinlee
I heard the Android data binding compiler was written in Kotlin. At
KotlinConf, they announced that Google had dropped Java altogether for writing
Lint rules because of Kotlin's much greater capabilities for handling
deprecated code and IDE quick fixes.

~~~
ptx
Wasn't the linter thing just about moving the lint rules (for checking proper
Android API usage) to a language-independent format so that they could be
shared by Java and Kotlin? Previously they only worked for Java code.

~~~
mncolinlee
You can watch the KotlinConf session video by Tor Norbye. It was what you said
and more. To clarify, I meant they dropped Java internally for their own lint
rules, not that they dropped support.

[https://www.youtube.com/watch?v=p8yX5-lPS6o&list=PLQ176FUIyI...](https://www.youtube.com/watch?v=p8yX5-lPS6o&list=PLQ176FUIyIUY6UK1cgVsbdPYA3X5WLam5&index=9)

------
merb
some examples are fine, but come on...

> Uri.parse(myUriString)

vs.

> myUriString.toUri()

I'm not sure if I would prefer the second one...

~~~
kornish
Discoverability via autocomplete is much higher in the second one. Extension
methods probably seem really strange to anyone coming from a FP background
(myself included), but in practice they've ended up being pretty useful when
paired with Intellij.

~~~
TheAceOfHearts
Doesn't it get a bit overwhelming to get a huge list of choices with
autocomplete? I've never done any serious work with Java or Kotlin, so I'm
genuinely curious.

As long as you have good docs, I find discoverability is rarely an issue. One
of the first things I do when picking up a language is look through its built-
in constructs, to familiarize myself with the available options.

~~~
izacus
Hmm, have you used any of the Java-based autocompletion systems? - IntellJ /
Android Studio autocompletion system is context aware and will only list
relevant methods (which means that the list is rather short and useful for the
context). Which is a stark contrast to many ctags-like autocompletion systems,
which will just dump all the symbols on you and aren't very useful in my
experience.

Using autocompletion means you don't have to leave the editor window and I've
found it hugely useful for methods which have several overrides - instead of
leaving the editor, you just choose the one you need as you type.

~~~
TheAceOfHearts
Most of my experiences with Java were during college with Eclipse. I just
remember finding it rather frustrating to have the autocomplete regularly
popping up and showing me dozens of options without an easy way of learning
more about em.

At some point I read through the Kotlin docs and found it interesting, but
didn't have any projects in mind for it. I might try my hand again along with
IntelliJ / Android Studio.

I've happily used other JetBrain products such as RubyMine and WebStorm.

~~~
ReidZB
With autocomplete open in IntelliJ, you can press F1 to view the docs for that
currently highlighted autocomplete method inline. Works really well.

------
saagarjha
We've already seen something similar before: when Apple "modernized" many of
the their Cocoa Touch APIs to work better with Swift.

~~~
1123581321
Can you elaborate on what we have seen? Modernization in quotes suggests that
Apple wasn’t successful.

~~~
saagarjha
I put modernization in quotes because in most cases it was really a shim
placed ontop of the existing Objective-C API that changed some names or
parameter types; so, in this case it wasn't _quite_ as extensive as a
Java->Kotlin transition would be since Objective-C already supports many
"modern" features such as closures.

------
vorg
Laughed when I saw this Apache Groovy code slinking away at the bottom of the
article:

> To start using Android KTX in your Android Kotlin projects, add the
> following to your app module's build.gradle file:
    
    
      repositories {
        google()
      }
    
      dependencies {
        // Android KTX for framework API
        implementation 'androidx.core:core-ktx:0.1'
        ...
      }

~~~
swsieber
Yes - that's Gradle's language de jour right now, though there is a ton of
effort being put into supporting Kotlin as an alternative scripting language
for it. I think you could use it right now actually.

------
karag
Florina killed it again! go go girl (She's a genius)

------
evancox100
Why is it that these large web companies can put out such sophisticated tools,
and yet can't make a functional web page? Literally cannot see the content you
are trying to show me.

[https://imgur.com/a/lXY8J](https://imgur.com/a/lXY8J)

And no, there's no scrolling or zooming allowed.

Seriously, let's stop the focus on web framework du jour and actually make web
sites that work, please.

~~~
dguaraglia
Well, if you think about it in terms of priority, making better tools that
literally millions of engineers will be using to develop apps for billions of
people has a higher impact than improving a blogging platform that is used by
a handful of people at Google.

That's not to excuse the shitty state of web on mobile, but let's face it: we
are talking about completely different teams and priorities.

