Jack(Java Android编译器工具包)将如何影响Scala开发人员 [英] How Jack (Java Android Compiler Kit) will affect Scala developers

查看:146
本文介绍了Jack(Java Android编译器工具包)将如何影响Scala开发人员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现宣布

解决方案

了解引入了 2工具非常重要:





所以听起来这里有 2个单独的问题




  • Scala兼容性

    Scala wil我没有Jack支持,因为Jack编译Java源代码。

    但是Scala 2.11编译为Java 1.6字节码,因此Jill将能够选择该代码并转换为jack文件以提供Jack编译器。

    请参阅 Android N Java 8功能(杰克编译器)和Kotlin互操作(Kotlin与Scala相同,因为它是JVM语言)


  • Java 8,因此Scala 2.12 +,兼容性

    这部分正在开发中,如果Jack / Jill支持Java 8,那么它也将支持Scala 2.12+(通过Jill)。如果没有,Java 8开发人员与Scala 2.12开发人员在同一条船上。

    如果Jack支持Java 8而不支持Jill,那么Java 8库开发人员将与Scala 2.12开发人员在同一条船上。

    请参阅 https://www.guardsquare.com/blog/DroidconLondon2015



Now with announcement of Jack Google clarified the foreseeable future of Java in relation to Android. But what are the implications to Scala and other JVM-based languages developers. In particular:

  1. Scala does it's magic due to own compiler that produces Java bytecode. But Jack toolchain doesn't deal with bytecode. Will generated bytecode gain any optimization benefits of Jack processing?
  2. Starting from Scala 12 only Java 8+ is supported. That is the generated bytecode is Java 8+ too. Can Jack utilize Java 8 bytecode (without or with limitations)?
  3. Can newly supported Java 8 features be used for developing for older Android versions (minSdkVersion < 'N') or i should maintain separate branch for each Java version? (it is not clear from documentation).

All these questions boil down to one: Can Scala be used for Android development in future without sacrificing the benefits of new Scala features and new Android tool chain?

Related reading:

please share related links in comments or answers

Related questions:

Related:

Please vote for Jack tool feature request:


EDIT:

I'm trying to reason about (NOT to answer) my question hoping that experts will correct me if i'm wrong.

Below is a hypothetical flow of Jack build with some extra blocks that was added basing on my logic and what i have learned from available docs.

Base assumption is that Dalvik supports up to Java 7 bytecode instructions. If that is correct Java 8 instructions can not be directly passed to Dalvik, they should be somehow transformed to Java 7. (May be something similar to that Scala compiler always does).

Than the question is where is that transformation happens? Seems Jill can't process Java 8 bytecode as for now, so that possibly happens in block (3) of hypothetical flow. If that is correct than only Java source project files are subject to transformation and the answer to 2-nd question is - No. Java 8 classes from libraries can not be utilized until Jill will be able to do it (if it's possible at all). That is we can not use Scala 12+.

If all code optimization is performed in block (6) than the answer to 1-st question is - Yes. Scala code being converted to library .jar can benefit from Jack optimizations. But preliminarily it should be transformed to .jayce (AST-like representation) that will increase build time.

And finally Jack produces .dex Dalvik bytecode to maintain compatibility with older Dalvik runtimes (ART consumes Dalvik bytecode too). So the answer to 3-d question is: Yes, Java 8 features can be used. But only in project Java sources. App is still compatible with any runtime. But Java 8 advantages are dropped due to converting to Java 7 (Dalvik bytecode).


解决方案

It’s important to understand that there is 2 tool introduced:

So it sounds like there is 2 separate problem here:

  • Scala compatibility:
    Scala will not be supported by Jack, as Jack compiles Java source code.
    However Scala 2.11 compiles to Java 1.6 bytecode and therefore Jill will be able to pick that code and convert to jack files to feed the Jack compiler.
    See Android N Java 8 features (Jack compiler) and Kotlin interop (Kotlin as the same issue as Scala as it’s a JVM language)

  • Java 8, and therefore Scala 2.12+, compatibility:
    This part is under development, if Jack/Jill supports Java 8, then it will also support Scala 2.12+ (through Jill). If not, Java 8 developers are in the same boat as Scala 2.12 developers.
    In the case Jack supports Java 8 but not Jill, then Java 8 libraries developers will be in the same boat as Scala 2.12 developers.
    See https://www.guardsquare.com/blog/DroidconLondon2015

这篇关于Jack(Java Android编译器工具包)将如何影响Scala开发人员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆