on Electronics

Fixing “Unknown Kotlin JVM Target: 21” Error in Flutter


Recently, I faced this annoying issue while building a Flutter project:

FAILURE: Build failed with an exception.

What went wrong:
Could not determine the dependencies of task ':#####:compileDebugKotlin'.
Unknown Kotlin JVM target: 21

No matter what I tried, setting the JDK version for Gradle in Android Studio didn’t work. Running flutter doctor kept showing that the JDK version was 21.

Here’s what I found out:

  • Flutter was using the JDK bundled with Android Studio (jbr directory), which is JDK 21.
  • The problem is that Kotlin’s JVM doesn’t support JDK 21 yet.

The Solution:

I finally came across a fix that worked! You need to explicitly tell Flutter to use a different JDK version. Here’s how to do it:

  1. Find the path to an older JDK version (like JDK 18) on your system.
  2. Run this command in your terminal:
    flutter config –jdk-dir <dir> Replace with the actual path to your JDK installation.
  3. Run flutter doctor again to confirm that Flutter is now using the correct JDK.
  4. Restart Android Studio and rebuild your project.


Why This Works:

By default, Flutter uses the JDK bundled with Android Studio. This command forces Flutter to use the JDK version you specify, avoiding the compatibility issue with JDK 21.

Key Tip:


If you’re using Kotlin with Flutter, stick to JDK versions like 18 or 19 until Kotlin adds support for JDK 21.

Hopefully, this helps someone else struggling with the same issue! If you’ve faced a similar problem or have a different solution, let me know! 😊

 

Custom Packet Sniffer Is A Great Way To Learn CAN

Whilst swapping out the stereo in his car for a more modern Android based solution, [Aaron] noticed that it only utilised a single CAN differential pair to communicate with the car as opposed to a whole bundle of wires employing analogue signalling. This is no surprise, as modern cars invariably use the CAN bus to establish communication between various peripherals and sensors.

In a series of videos, [Aaron] details how he used this opportunity to explore some of the nitty-gritty of CAN communication. In Part 1 he designs a cheap, custom CAN bus sniffer using an Arduino, a MCP2515 CAN controller and a CAN bus driver IC, demonstrating how this relatively simple hardware arrangement could be used along with open source software to decode some real CAN bus traffic. Part 2 of his series revolves around duping his Android stereo into various operational modes by sending the correct CAN packets.

These videos are a great way to learn some of the basic considerations associated with the various abstraction layers typically attributed to CAN. Once you’ve covered these, you can do some pretty interesting stuff, such as these dubious devices pulling a man-in-the-middle attack on your odometer! In the meantime, we would love to see a Part 3 on CAN hardware message filtering and masks [Aaron]!

 

Share Internet from WiFi via Ethernet on Ubuntu 17.10

Share Internet from WiFi via Ethernet on Ubuntu 17.10

There is a hidden method to share your WiFi over Ethernet in the latest Gnome.

  1. Type nm-connection-editor in your terminal.
  2. Add a shared network connection by pressing the Add button.
  3. Choose Ethernet from the list and press Create.
  4. Click IPv4 Settings in the left.
  5. Choose Shared to other computers by clicking the Method drop-down menu.
  6. Enter a new name like Shared WiFi LAN as the Connection name at the top
  7. Select the newly created connection from wired connection.
 

Create Cheap Philips Hue Compatible Devices

The Philips Hue range is a great way to add wirelessly controllable lighting to your home, but the protocol is proprietary which makes it difficult to add our own custom hardware. [Peter] found a way to create his own Hue compatible devices based on cheap JN5168 modules that are able to connect to the Hue bridge. This means you can roll out your own lamps using cheap RGB or White LEDs, a power supply and the JN5168 Zigbee Light Link module.

He started off by trying to clone a Zigbee Light Link device to a MeshBee — Seeed studio’s open source Zigbee Pro module based on the NXP JN5168. Even though the MeshBee used the same device as a Hue lamp, it would not connect to the Hue bridge. But another clone lamp called Innr that he purchased from the local hardware store did connect quite easily. Using NXP’s open source tools, he was able to download the flash and EEPROM contents from the Innr and copy them to the MeshBee which did the trick.

After the EEPROM transfer trick, he figured out how to modify the two keys used for the ZigBee protocol — one for Home Automation and the other for the Light Link. With this final discovery, he is able to take the ZigBee Light Link demo project, edit it using Beyond Studio, and then load the binaries on the MeshBee device so it can connect to the Hue bridge.

All of this work culminates in two custom firmware binaries; one for white dimmable lights and another for RGB dimmable ones. It even runs on these cheap JN5168 breakout kits he found for a few bucks. With all of the software taken care of, and having cheap ZigBee Light Link compatible modules on hand, building low-cost Hue compatible lights becomes pretty straight forward.

Thanks [wind-rider] for the tip.

View @hackaday.com