Does Android Jetpack require the use of the Kotlin language?

雨燕双飞 提交于 2021-02-16 10:01:58

问题


I can't seem to find a clear answer to this in Google, and all the documentation and samples I've seen for Jetpack seem to refer to and use Kotlin.

But do you HAVE to use Kotlin in order to use Jetpack? Or can Jetpack be used with traditional Java programs?

I was looking at Kotlin but it adds almost a MB to your app size. And seeing as my entire app is only about 200KB currently, I don't think Kotlin is worth increasing the size of my app by 500%!


回答1:


Jetpack is a collection of libraries plus guidance on how Google recommends building Android applications. These libraries all have Java APIs, so you don't need to move to Kotlin to use any of them. Both languages are still completely supported for Android development.

As for the APK size consideration, it's true that Kotlin will definitely increase it. It's hard to tell how much larger it'll be, but Proguard should strip out a lot of the standard library that you end up not using, so it could be much less than an entire MB. Here's an article that compared Java and Kotlin APK sizes of an essentially empty Hello world app that found the increase to be just 11 KBs, for example. So unless you're in a market where this is extremely important, you could probably get away with using Kotlin.

More importantly though, switching to Kotlin is more than just pulling in a library - it's a new language to learn, which means you have to put some effort into it, and it can change a lot about how you write your applications. You should look into the language more and see if you like what it offers.




回答2:


You just get more syntactic sugar when you use kotlin instead of java, but they have same functionality and you can even use them hybird.

Also android Jetpack is great, it shouldn't be limited by language. Although android-sunflower - the official demonstrate app of Android Jetpack wrote in Kotlin, it can still implement by java. In order to support Android Jetpack, I translated all kotlin implementations to Java, and added [app-java] module as the Java version of android-sunflower app, please check out android-sunflower-java.




回答3:


Quoting Android documentation

Jetpack is a collection of Android software components to make it easier for you to develop great Android apps. These components help you follow best practices, free you from writing boilerplate code, and simplify complex tasks, so you can focus on the code you care about.

Jetpack comprises the androidx.* package libraries, unbundled from the platform APIs. This means that it offers backward compatibility and is updated more frequently than the Android platform, making sure you always have access to the latest and greatest versions of the Jetpack components.

Nowhere in the docs you'll find something saying that using Kotlin is required for Jetpack development. Also, if you open Android Studio 3.2 (Currently beta 5), in the New Project Dialog, you'll see the option to add Kotlin support just like the previous version of Android Studio, so you'll be completely fine going with Java without checking this box.



来源:https://stackoverflow.com/questions/51853130/does-android-jetpack-require-the-use-of-the-kotlin-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!