StureS
StureS

Reputation: 237

Visual Studio cannot compile an Android Java file

Visual Studio 2019, Windows 10.

I can successfully compile a Native (C++) Android project and have it running on the phone with Visual Studio.

Now, in order to add some Java I first created a minimal Hello World project in Visual Studio for Android/Java. However I get a note at the top: "Java Developer Kit installation not found (Status JDKRegKeyNotFound). Intellisense is not available" Also the code won't compile:

"EXEC : [javac] error : Source option 5 is no longer supported. Use 7 or later."

Installed: C:\Program Files\Java\jdk-17.0.4.1

JAVA_HOME set to C:\Program Files\Java\jdk-17.0.4.1

Path includes %JAVA_HOME%\bin

Java SE Development Kit set to C:\Program Files\Java\jdk-17.0.4.1 in Options -> Cross Platform -> C++ -> Android in Visual Studio

Android/Java

I've googled for Source option 5 is no longer supported. Use 7 or later. but found only solutions for Android Studio or Eclipse.

Any suggestions how to fix these errors?

Upvotes: 2

Views: 488

Answers (2)

Bruno Bieri
Bruno Bieri

Reputation: 10236

Updating to Visual Studio 2022 17.6.0 I got this warning. It seems the warning is produced from the Visual Studio Extension called "Java Tools for Android Projects (Visual Studio 2022)", which is now deprecated.

I haven't investigated further but uninstalling this extension lets this warning disappear. To uninstall it go to Visual Studio -> Extensions -> Manage Extensions -> "Installed" section -> Look for "[Deprecated] Java Tools for Android Projects (Visual Studio 2022)" -> Uninstall

Upvotes: 0

StureS
StureS

Reputation: 237

For "Java Developer Kit installation not found ", it was a pending update which wasn't completed for some reason.

For "Source option 5 is no longer supported": Edit (as an admin) C:\Microsoft\AndroidSDK\25\tools\ant\build.xml

Change line 71, 72 from

<property name="java.target" value="1.5" />
<property name="java.source" value="1.5" />

to

<property name="java.target" value="1.7" />
<property name="java.source" value="1.7" />

Now it compiles and runs as it should. Note that I have not Xamarin installed as it is not needed.

Upvotes: 1

Related Questions