Reputation: 31
i was trying to make use of unreal engine 4 template for AR but i got this error. This step kinda connect android studio with unreal but i just don't work.
Upvotes: 3
Views: 16826
Reputation: 21
I didn't have a tools directory but I did have it in the cmdline-tools
directory so I just replaced the code with this.
@REM set SDKMANAGER=%STUDIO_SDK_PATH%\tools\bin\sdkmanager.bat
@REM IF EXIST "%SDKMANAGER%" (
@REM echo Using sdkmanager: %SDKMANAGER%
@REM ) ELSE (
@REM set SDKMANAGER=%STUDIO_SDK_PATH%\cmdline-tools\latest\bin\sdkmanager.bat
@REM IF EXIST "%SDKMANAGER%" (
@REM echo Using sdkmanager: %SDKMANAGER%
@REM ) ELSE (
@REM echo Unable to locate sdkmanager.bat. Did you run Android Studio and install cmdline-tools after installing?
@REM pause
@REM exit /b 1
@REM )
@REM )
set SDKMANAGER=%STUDIO_SDK_PATH%\cmdline-tools\latest\bin\sdkmanager.bat
IF EXIST "%SDKMANAGER%" (
echo Using sdkmanager: %SDKMANAGER%
) ELSE (
set SDKMANAGER=%STUDIO_SDK_PATH%\tools\bin\sdkmanager.bat
IF EXIST "%SDKMANAGER%" (
echo Using sdkmanager: %SDKMANAGER%
) ELSE (
echo Unable to locate sdkmanager.bat. Did you run Android Studio and install cmdline-tools after installing?
pause
exit /b 1
)
)
but then i got...
Android Studio Path: C:\Program Files\Android\Android Studio
Android Studio SDK Path: C:\Users\meta\AppData\Local\Android\Sdk
Using sdkmanager: C:\Users\meta\AppData\Local\Android\Sdk\cmdline-tools\latest\bin\sdkmanager.bat
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/sdklib/tool/sdkmanager/SdkManagerCli has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:757)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
Update failed. Please check the Android Studio install.
Press any key to continue . . .
So i fixed that by download oracle java which is currently at version 20 and then setting my JAVA_HOME in the windows user variables
to C:\Program Files\Java\jdk-20
then i ran the edited C:\Program Files\Epic Games\UE_4.27\Engine\Extras\Android\SetupAndroid.bat
and everything passed
Upvotes: 2
Reputation: 1
It Simple just rename the folder inside cmdline-tools to latest and it should find it
Upvotes: 0
Reputation: 106
I spent 2 hours to figure out what's wrong with it.
So, provided earlier solutions should fix it:
Simply just replace incorrect path to correct one or, just DELETE most outer IF
block and first line where %SDKMANAGER%
var first set to invalid (I suppose, outdated path) value.
This is a part of the source code of SetupAndroid.bat from Epic Games. I've checked version 4.27 and 5.1. These lines are kind of identical in both versions (however version 5.1 still has the same exact error, but it works due to changing the order of which path is tried first):
set SDKMANAGER=%STUDIO_SDK_PATH%\tools\bin\sdkmanager.bat
IF EXIST "%SDKMANAGER%" (
echo Using sdkmanager: %SDKMANAGER%
) ELSE (
set SDKMANAGER=%STUDIO_SDK_PATH%\cmdline-tools\latest\bin\sdkmanager.bat
IF EXIST "%SDKMANAGER%" (
echo Using sdkmanager: %SDKMANAGER%
) ELSE (
echo Unable to locate sdkmanager.bat. Did you run Android Studio and install cmdline-tools after installing?
pause
exit /b 1
)
)
And this specific part does not work! I don't know why those who developed that did not check it or they simply don't know how batch file variables work.
The thing here is that on recent Android SDK installations there's no folder tools
at the path %STUDIO_SDK_PATH%
. So the first condition check fails and then they try to overwrite variable value to correct one with path %STUDIO_SDK_PATH%\cmdline-tools\latest\bin
. But this overwrite DOES NOT WORK. You can't just do that in a batch file (which is kind of stupid, but it is). More on that issue with batch vars here: How to overwrite an existing variable using another variable in batch files?
"Good" job! Epic Games
Upvotes: 0
Reputation: 11
Try next:
AppData\Local\Android\Sdk
foldersdkmanager.bat
SetupAndroid.bat
with Notepad (or other editor of your choice)sdkmanager.bat
\cmdline-tools\latest\bin\sdkmanager.bat
)This worked for me.
Upvotes: 1
Reputation: 1
the same here, i tried to search "sdkmanager" at both of my Drive and couldn't find any. couldn't find any cmdline-tools drive as well.
Upvotes: 0
Reputation: 61
Ran into the same issue and fixed it by editing the SetupAndroid.bat file.
Not sure why it doesnt set the location of the SDKManager after it fails the first one. But manually replacing the first location works.
Upvotes: 6
Reputation: 1
if you encountered this issue when running "SetupAndroid.bat", the reason might be simple. If you check the "SetupAndroid.bat"(right click, edit. Or turn it into a txt), the default sdkmanager path might be different from the actual location.
You might need to search "sdkmanager" from the Android Studio SDK root folder manually(it suppose to display on the cmd interface), find the actual directory and correct the "SetupAndroid.bat", then try it again.
Upvotes: 0