问题
I am trying to install Flutter without Android Studio and here is what I did:
- Installed Java 8
- Installed and Unzipped Flutter SDK to
C:\src
. - Installed and Unzipped Android Command-line tools (sdkmanager) to
C:\Android
. - Added the environment variables (ANDROID_HOME: C:\Android)
Now when I try to run sdkmanager
to install Android SDK, I get this error:
"Error: Could not find or load main class com.android.sdklib.tool.sdkmanager.SdkManagerCli"
I have tried reinstalling Flutter sdk and the sdkmanager with no luck.
Here is Flutter Doctor's output:
sdkmanager error:
回答1:
Download the SDK tools ZIP (Under Command Line Tools in https://developer.android.com/studio).
Unzip using 7zip. Avoid using default windows extractor - that doesn't do the extraction correctly.
After unzipping using 7zip, place the contents into the sdk folder (C:\Users<username>\AppData\Local\Android\Sdk\tools\bin and C:\Users<username>\AppData\Local\Android\Sdk\lib) and run sdkmanager on command prompt.
回答2:
Open the sdkmanager.bat
in a text editor and add echo %CLASSPATH%
just below the CLASSPATH=%APP_HOME%\...\sdkmanager-classpath.jar
. Then run sdkmanager --help
which will echo the CLASSPATH of the required file. And check whether is it the valid path.
In my case, it was the wrong path,
It said my sdkmanger-classpath.jar
is in lib
folder. But it was not! It was actually inside the lib/_
folder. So as the simple solution what I did was copy the content in side lib/_
folder to lib
. Then it worked fine!
回答3:
As @Chrishan wrote Avoid using default windows extractor
.
You can use the PowerShell:
Expand-Archive commandlinetools....zip C:\Android\Sdk
回答4:
I fixed by adding '--sdkroot ' pointing to the root folder (i.e. parent of bin). e.g. % ./bin/sdkamanager --sdkroot .
回答5:
On Windows Server 2019, as of commandlinetools-win-6609375_latest.zip we were facing same issue. We placed package inside "Program Files" i.e. "C:\Program Files\Android\cmdline-tools\tools\bin".
It seems this will not work if there is space in path. So we placed it in folder path without spaces i.e. "C:\Android\cmdline-tools\tools\bin" and it is working fine.
来源:https://stackoverflow.com/questions/60727326/sdkmanager-error-could-not-find-or-load-main-class-com-android-sdklib-tool-sdk