Android Studio - Additional JDK not needed (Solution to Java is none error)

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Android Studio - Additional JDK not needed (Solution to Java is none error)

Post by Bernard » Sat Oct 24, 2020 2:51 pm

Like many people on this forum in recent years, I got the "Java: none" error after installing Java 1.8 and then installing Android Studio (as per instructions from Livecode here: http://lessons.livecode.com/m/2571/l/62 ... oid-studio). Many people have been confused by these instructions in recent years (for example: viewtopic.php?t=26477 and here: http://forums.livecode.com/viewtopic.php?t=34315). I was staggered to see that for years users have been struggling with setting up for Android and since following the Lesson and reading various possible solutions in Forum posts but nothing worked for me, I decided to get to the bottom of the problem so that others don't have to go through this frustrating experience. I must have spent more than 8 hours trying to figure this out (on both Windows and OS X), involving multiple installs of JDK/Android Studio on both.

tldr:
a) The Livecode lesson is wrong (since 2016 Android Studio does not need a separate JDK install),
b) how LC preferences pane looks up the relevant JDK is way too complex (the IDE needs to just set the path based on the Android Studio (AS) install (which is different to the AS SDK path).

SDK path (Windows) in the LC Prefs windows looks like this:
C:/Users/Bernard/AppData/Local/Sdk

Below it the JDK path needs to look like this:
JDK Path: D:/Programs/Android/Android Studio/jre


I'm not really surprised by this confusion, as there were plenty of other misleading trails when the fix is really simple.

Android Studio version is 4+ (the downloaded file has 201 in the crazy numbering).
dlandstudio41.png
as204dl.PNG
as204dl.PNG (4.13 KiB) Viewed 79886 times
If one looks inside some of the .bat files once AS is installed, these batch files branch depending on if Windows is version "NT" or not - if not, it's assumed to be Win95/WinME! Mind-boggling to think that at the cutting edge of Android development (1gb of RAM for AS/emulator to run) they are providing for Win95 users.

However, in investigating what AS installs I found that version 2.2+ comes with its own OpenJDK - see https://stackoverflow.com/a/42172066 (since June 2016 Google's install instructions for Android Studio dropped any reference to installing a JDK). What AS install does not do is set the variables/registry keys LC expects when looking for an appropriate JDK (so the JDK bundled inside AS is not found by the LC IDE).

Here's what the studio-config.html says:

"A copy of the latest OpenJDK comes bundled with Android Studio 2.2 and higher, and this is the JDK version we recommend you use for your Android projects". From <https://stackoverflow.com/questions/421 ... o/42172066> I found plenty of other instructions (external to Livecode) referring to parts of Android Studio which were wrong (either the referenced feature has been moved or renamed).

After installing Android Studio (v4.1 i.e. file named ide-201.xx version as in screenshot) I checked Android Studio worked and that an x86 emulator could be created. Once assured that was working, I knew that AS was finding and using a JDK even when LC could not. I needed to find out why LC was failing to find the needed JDK. I enabled the (hidden) "ChooseJDK" button on the LC prefs pane to inspect what LC was looking for in setting the JDK version. Depending on the platform, LC relies on the OS being able to provide a pointer to the right JDK. In my experience this failed on both MacOS and Windows.

With the relevant section of the Preferences window open, I put this in MessageBox

Code: Select all

set the visible of button "ChooseJDK" of group "Android SDK" of card "Mobile Support" of stack "revPreferencesGUI" to true
This button is normally only visible if platform() is "linux". This button enables one to choose the JDK within the Android Studio installation (the folder containing e.g. java.exe and javac.exe). So for me it is this:

JDK Path: D:/Programs/Android/Android Studio/jre

Meanwhile the line above JDK Path (pointing to SDK root) will say something like:

C:/Users/Bernard/AppData/Local/Sdk

After ensuring that the two Android relevant fields pointed to the SDK home and the (Android bundled) JDK, I created a test stack, saved it and set the standalone settings, then chose the Android emulator listed in the menu "Development/Test Target) and tested my basic stack on the emulator. Bingo.

So, here's what LC needs to do:
a) edit the lesson to remove any reference to JDK
b) change how the Prefs pane looks for a JDK e.g. let the user point to the root directory of the Android Studio binaries and build up a path to Android's included JRE directory.

====
Update: forgot to mention that one needs to set the PATH environment variable so that it points to the relevant (home) directory for the sdk java tools. LC in launching those tools could include the full path to that home. For anyone trying to do what I've done, once the path variable is set then opening a new terminal one should be able to call
java -version
javac -version
and the OS should find those executables and launch them. My guess is that within the LC IDE is that these programs are called without a full path to them, hence the need to set the path.
====
On OS X the "home" folder is within the "Android Studio.app" and the path should point to that folder (javac is within a folder within home/).

To discover the location of the SDK of Android Studio, in the preferences/configuration of that tool under the "Android SDK" entry you can find a field marked "Android SDK Location". On OS X that will be something like /Users/bernard/Library/Android/sdk. To be able to choose that location using OS X (Big Sur at any rate) you will need to use cmd+shift+g to open up a field to be able to navigate to that location so that you can click on the "sdk" folder to satisfy LC's file dialog.

When it came to getting LC prefs to find the JDK with the one bundled with Android Studio even using cmd+shift+g was not sufficient to enter into the Android Studio package contents from inside LC's file dialog. I used Finder to open the AS app contents, then created an alias that pointed to the enclosed "jre" folder. I copied the alias to "jre" outside of the package (to the folder containing Android Studio). Then, from within LC's pref file dialog (accessed from the tip above to make the selection button visible), I navigated through the alias to the folder to select "jre/jdk/Contents/Home". This was accepted by LC prefs and inserted as the content of the field marked "JDK Path:" in LC prefs.

In compiling an app using 9.6.2 on a M1 Mac I'm getting an error "could not encode class bundle". This is being thrown at the point where LC tries to call Android's dx tool. By putting the following
answer (shell("which javac"))
before each point where LC shells out to the relevant Android compilation stages, it is clear that LC is switching from using the Android Studio Javac to using /usr/bin/javac at this point and then failing. This suggests to me that at this point the OS path used by LC is getting screwed up. The DX tool is being called without knowing how to find the JDK.

I finally got passed the "could not encode class" error, which was due to something strange the LC code is doing. When it comes to the DX part of the compilation/install to device, LC does not set the Java path when the OS is MacOS (this doesn't matter at the earlier steps in the process of compiling for Android, as the Java path is passed into the doShellCommand function in those steps, but now with the DX phase).

This is the change I made in the stack "edit the script of stack "revSaveAsAndroidStandalone":
private function doShellCommand pCommand, pArguments
[... snip.... ]
else if the platform is "macos" then
# put tCommandPath & ":" before $PATH
# above the line found in that stack is now disabled, my replacement is on the line below, making the Mac branch consistent with Win/Linux
put tCommandPath & ":" & sJavaRoot & "/bin" & ":" before $PATH
else if the platform is "linux" then
[... snip.... ]
Once I'd changed that conditional to have it include the Java path before calling the DX command, compilation for OS X works.

I can't explain why this failure occurred on my new M1 Mac when my original use of Android Studio (with its JVM) was working on my old Intel Mac. I can only assume there was some step I had used before that I missed from my instructions, and that this missed step somehow set up the Java environment at the OS level, such that this DX step not setting that up did not matter. Maybe it's to do with Big Sur defaulting to /bin/zsh rather than /bin/bash?
Last edited by Bernard on Tue Jul 20, 2021 11:59 pm, edited 8 times in total.

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Android Studio - Additional JDK not needed (Solution to Java is none error)

Post by sphere » Mon Oct 26, 2020 8:39 pm

This may be partly true.
As some people prefer not to install Android Studio but only the Command Line version. Although with the latest versions it is a bit more work to download SDK's and related stuff as it then all goes via command line. Also one could choose to use OpenJdk or Oracle's.
I don't know if a Java is also installed with the command line. If not, one still needs to install it separate.

Anyway thanks. I'm using Studio too, also because i'm a bit focusing on Flutter now. And probably can remove Oracles Java JDK now.

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: Android Studio - Additional JDK not needed (Solution to Java is none error)

Post by Bernard » Tue Oct 27, 2020 12:41 am

Once I'd got it all installed and working, I started to strip out as much of the Android IDE as I could (in fact, I'm testing on physical devices). However, when searching for what to do with Android (I've not done anything with it for some years, and didn't any longer have a machine with Android tools and Livecode on it), the Lesson on Android Studio was the one that search engines returned as the most relevant. So I assumed that was what one now had to use. But seeing lots of people going round in circles (as indeed was I), I wanted to find the simplest, most standard Android way of doing things. Having got that working, and getting LC to work with that on Win/Mac I then wanted to strip down the Android tools to the least needed. In doing that, I realised that I could probably just install command line tools. But having done all this work (and not assuming everyone will want to have a minimal install like me) I thought I'd write it up so that LC could offer a single, simple Lesson on how to get a standard install working. That could then link to a more advanced, stripped-down install.

Even with iOS it's possible to just launch emulators from the command line without running XCode, but I guess the people who are using iOS know that.

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Android Studio - Additional JDK not needed (Solution to Java is none error)

Post by sphere » Tue Oct 27, 2020 7:06 pm

Thanks Bernard, people will appreciate it.
Even with iOS it's possible to just launch emulators from the command line without running XCode
Yes true

rcmills
Posts: 42
Joined: Wed Nov 21, 2018 8:27 pm

Re: Android Studio - Additional JDK not needed (Solution to Java is none error)

Post by rcmills » Thu Feb 18, 2021 10:15 pm

I have set the visible of the button to find the JDK, using the command in the MessageBox as Bernard suggested, and tried using it to point to the jre folder in the contents of Android Studio.app on my mac. The dialog box which opens after clicking the button, however, grays out the Android Studio.app, and I am unable to select it.

Any suggestions?

Thanks.

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: Android Studio - Additional JDK not needed (Solution to Java is none error)

Post by Bernard » Tue Mar 02, 2021 7:44 pm

I assume you're on OS X. Are you logged in as Admin (just a wild guess)?

It's possible there's some difference between your version of OS X and mine (my Apple box is about 5 years old, just pondering a M1 Mac).
rcmills wrote:
Thu Feb 18, 2021 10:15 pm
I have set the visible of the button to find the JDK, using the command in the MessageBox as Bernard suggested, and tried using it to point to the jre folder in the contents of Android Studio.app on my mac. The dialog box which opens after clicking the button, however, grays out the Android Studio.app, and I am unable to select it.

LCWilli
Posts: 3
Joined: Wed Mar 24, 2021 5:52 pm

Re: Android Studio - Additional JDK not needed (Solution to Java is none error)

Post by LCWilli » Sun Mar 28, 2021 8:00 pm

Hello Bernard, I followed your instructions and was successful to create an Android App under Windows 10. I went the way as you mentioned, followed the LC lessons how to setup, failed, churned the Internet for hints. First experience was, that LC needs registry setting to JAVA. Most instructions assume that you install JAVA JDK with an executable and this sets registry as needed. But private users don't get an exe installation program anymore. They only get openJDK zipfiles and must do installation manually and set registry by themselves. Because I wasn't aware of necessary registry setting, I tried to set environment variables. Passed this problem, the next one was "could not compile service support class". Your hints showed the way how to solve. It's a pity that such informations, that an Android Studio jre ist a JAVA JDK, ist very hard to find. You must know that I'm a mainframe systems programmer in retirement. So I'm experienced to follow logic steps and analyze error causes, but such difficulties with LC and Android leads to get grey hair.
:D

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Android Studio - Additional JDK not needed (Solution to Java is none error)

Post by sphere » Sun Mar 28, 2021 8:16 pm

LCWilli wrote:
Sun Mar 28, 2021 8:00 pm
But private users don't get an exe installation program anymore. They only get openJDK zipfiles and must do installation manually and set registry by themselves.
A private person can still download Oracle's JAVA jdk as an executable exe. One has to register and log-in these days. No need to do registry things yourself.

LCWilli
Posts: 3
Joined: Wed Mar 24, 2021 5:52 pm

Re: Android Studio - Additional JDK not needed (Solution to Java is none error)

Post by LCWilli » Mon Mar 29, 2021 6:41 am

Hi, you are right, I was not exactly with the new Oracle policy. I started to register, but they want a company name and a phone number. Or could it be that I used a wrong register form? Because I'm don't own a company and don't want to distribute my phone number, I stopped registration.

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Android Studio - Additional JDK not needed (Solution to Java is none error)

Post by Klaus » Wed Apr 07, 2021 6:30 pm

Hi Bernard,

I just wanted to say a big THANK YOU!
With your help here in this thread I could finally tell LC successfully where to find my SDK!

But now I get:
--------------------------------------------------------------------------
Unable to build app for testing:
unable to locate play service dependency base version 9.0.4
--------------------------------------------------------------------------
Anyway, a big step further. :-)

Why on earth is it that complicated?
Rhetorical question! :D


Best

Klaus

Klaus
Posts: 13793
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Android Studio - Additional JDK not needed (Solution to Java is none error)

Post by Klaus » Thu Apr 08, 2021 11:10 am

Hi all,

Panos showed me a workaround for my problem:
https://quality.livecode.com/show_bug.cgi?id=22384
This affects all stacks with a Android Barcode Scanner widget.


Best

Klaus

garmeister
Posts: 29
Joined: Sat Apr 10, 2021 6:56 pm

Re: Android Studio - Additional JDK not needed (Solution to Java is none error)

Post by garmeister » Sun May 16, 2021 6:46 pm

Bernard,
I wanted to give you a big THANKS as well (at least for Win 10). Mac OS has been very troublesome with the hidden folder that Android SDK is installed in (able to workaround), the fact that there are TWO JavaVirtualMachines folders in the Mac OS (see attached pic from Eclipse IDE).

/Users/garychike/Library/Java/JavaVirtualMachines/
/Library/Java/JavaVirtualMachines/

Java SE 8, recommended by LiveCode, installs into the latter directory with no option to select the directory. LiveCode seems to direct itself, as you mentioned, to the OpenJDK which is located in the former directory and LiveCode will not accept the default Java 8 SDK directory probably due to Android Studio defaulting to the OpenJDK version. So it seems Android development on the Mac is dead in the water, at least for now. But thankfully LiveCode Win works, but unfortunately there are other issues with the Win version (such as the highlighted text displaying the background color) which LiveCode Mac doesn't display.

Cheers,

Gary
Attachments
JavaVM.jpg
Gary E Chike DMD
"Experience is what you get when you don't get what you want"

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Android Studio - Additional JDK not needed (Solution to Java is none error)

Post by jacque » Mon May 17, 2021 5:18 pm

I've been creating Android apps on Mac regularly without any problems (I just did one yesterday.) I downloaded the SDK from Oracle and it installed into my user folder. I avoid Android Studio for the most part.

It looks like you have several versions of Java. I'd delete them all except the one that LC needs.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: Android Studio - Additional JDK not needed (Solution to Java is none error)

Post by Bernard » Fri Jun 18, 2021 5:02 pm

You're very welcome. I'm just starting with a new M1 mac, so now I'm going to have to use my own notes as guidance to make sure I can get everything working again myself.

I've been away for months doing work with Tcl and Postgresql, so now back getting my head into thinking in Livecode. It sure feels like these context-switches get harder as I get older.
Klaus wrote:
Wed Apr 07, 2021 6:30 pm
Hi Bernard,

I just wanted to say a big THANK YOU!
With your help here in this thread I could finally tell LC successfully where to find my SDK!

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: Android Studio - Additional JDK not needed (Solution to Java is none error)

Post by Bernard » Sun Jun 20, 2021 1:56 pm

rcmills wrote:
Thu Feb 18, 2021 10:15 pm
I have set the visible of the button to find the JDK, using the command in the MessageBox as Bernard suggested, and tried using it to point to the jre folder in the contents of Android Studio.app on my mac. The dialog box which opens after clicking the button, however, grays out the Android Studio.app, and I am unable to select it.
Now that I'm trying to install Android Studio on a new Mac, I think I have the answer for this (but I guess it's too late).

Within the LC file dialog you need to be able to "go in" to the package. Normally one can do this in Finder by using cmd+shift+G, but this won't work in the LC file dialog (nothing happens on typing in the path to enter the app Contents, except a "beep"). So what I did was to create an alias (from entering the package Contents using Finder and aliasing a sub-folder), then copied this alias to the folder containing the app. Then from the LC file dialog one can enter through that folder alias and drill down.

Whilst that got LC to recognise the JDK inside Android Studio, I still haven't got LC passed the class compilation stage. I'll update this thread when I get passed this.

It is crazy that LC haven't sorted this out.

Post Reply

Return to “Android Deployment”