0

Whenever I use Fragmet KTX in my projects, specifically binding viewModel using property delegates (viewModels & activityViewModels) I face an compiler error:

Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6

So to fix that I have to set the jvmTarget to 1.8 in build.gradle

What I don't understand is that why is the jvmTarget set to 1.6 by default and does changing it cause any compatibility issues?

Vandit Goel
  • 620
  • 2
  • 9
  • 19
  • Are you updating an old project? The default for a new project is Java 8. It used to be Java 6 years ago. – Tenfour04 Aug 17 '20 at 18:53

1 Answers1

0

The main issue is just the obvious one: classes compiled for a 1.8 target can't be run on a platform that doesn't support it.  In particular, since Android didn't support* all of 1.8 for a long time, that's been a major reason for Kotlin allowing a lower target version.

(* I must admit I don't know the details of this, and a quick web search hasn't shown anything definitive.  Please comment if you can shed light on this!)

If you know that all the platforms you're going to be running on are 1.8 or higher, then there's no reason not to set that as your target.

gidds
  • 16,558
  • 2
  • 19
  • 26
  • 1
    Android doesn't directly support Java 8. The dex compiler supports a subset of Java 8 features through bytecode manipulation with a process called *desugaring*, so it works on all versions of Android down to whatever today's minimum `minSdkVersion` is. Desugaring adds a dex file to your build that contains an alternate version of Java 8 APIs, and it manipulates your byte code to convert it to Java 7 and using the library code instead. https://developer.android.com/studio/write/java8-support#library-desugaring – Tenfour04 Aug 17 '20 at 20:27