美文网首页Flutter开发学习拣选文章
Mac Flutter 问题之 Android license

Mac Flutter 问题之 Android license

作者: PHP的点滴 | 来源:发表于2019-10-20 23:22 被阅读0次

    flutter doctor 提示以下错误信息;

    [!] Android toolchain - develop for Android devices (Android SDK 27.0.3)
        ✗ Android license status unknown.
    

    1. 执行 flutter doctor --android-licenses 即可,但是执行的时候又遇到以下错误

    jason@local Doc$ flutter doctor --android-licenses
    A newer version of the Android SDK is required. To update, run:
    /Users/jason/Doc/android_sdk/tools/bin/sdkmanager --update
    

    再执行 */tools/bin/sdkmanager --update 即可

    2. 执行 **/tools/bin/sdkmanager --update 可能提示以下错误

    Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema

    这个是因为安装的java环境版本过高,所以以需要卸载当前java

    3. 卸载java版本

    sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin 
    sudo rm -fr /Library/referencesPanes/JavaControlPanel.prefpane
    
    ls /Library/Java/JavaVirtualMachines/ 
    ## 显示:jdk-10.0.2.jdk
    sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk
    

    卸载成功:java -version //提示 No Java runtime present, requesting install.

    4. 再执行 **/tools/bin/sdkmanager --update 提示JAVA_HOME 错误

    jason@local Commands$ /Users/jason/Doc/android_sdk/tools/bin/sdkmanager --update
    ERROR: JAVA_HOME is set to an invalid directory: /Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home
    Please set the JAVA_HOME variable in your environment to match the
    location of your Java installation.
    

    这是 JAVA_HOME 配置发生变化了,需要重新配置 JAVA_HOME

    5. 配置 JAVA_HOME

    查找JAVA_HOME
    打开Mac的终端,检查JDK是否安装成功:java -version
    查看java指令所在的目录:which java
    输出结果:/usr/bin/java
    显示java指令文件的属性:ls -l /usr/bin/java
    输出结果如下:

    jason@local Commands$ which java
    /usr/bin/java
    jason@local Commands$ ls -l /usr/bin/java
    lrwxr-xr-x  1 root  wheel  74  3 28  2018 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
    

    从输出结果可以知道**/usr/bin/java文件是一个链接文件,实际是指向 /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java 文件
    进入实际指令所在的文件夹:
    执行指令:./java_home
    执行结果如下:

    jason@local ~$ cd /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/
    jason@local Commands$ ./java_home 
    /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home
    

    修改JAVA_HOME 路径配置

    vim ~/.bash_profile

    # export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home
    export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home
    

    刷新配置 source ~/.bash_profile

    6. 成功执行 **/tools/bin/sdkmanager --update

    jason@local Commands$ /Users/jason/Doc/android_sdk/tools/bin/sdkmanager --update
    Warning: File /Users/jason/.android/repositories.cfg could not be loaded.       
    [=======================================] 100% Computing updates...   
    

    7. 继续执行 flutter doctor --android-licenses 出现的y/N 一直回车y 即可

    jason@local Commands$ flutter doctor --android-licenses
    Warning: File /Users/jason/.android/repositories.cfg could not be loaded.       
    6 of 6 SDK package licenses not accepted. 100% Computing updates...             
    Review licenses that have not been accepted (y/N)? y
    

    8. flutter doctor 成功配置 android 虚拟机

    jason@local Commands$ flutter doctor
    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel stable, v1.9.1+hotfix.5, on Mac OS X 10.13.6 17G65, locale zh-Hans-CN)
    [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    [✗] Xcode - develop for iOS and macOS
        ✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
          Download at: https://developer.apple.com/xcode/download/
          Or install Xcode via the App Store.
          Once installed, run:
            sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
        ✗ CocoaPods not installed.
            CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
            Without CocoaPods, plugins will not work on iOS or macOS.
            For more info, see https://flutter.dev/platform-plugins
          To install:
            sudo gem install cocoapods
    [✓] Android Studio (version 3.5)
    [!] Connected device
        ! No devices available
    
    ! Doctor found issues in 2 categories.
    

    相关文章

      网友评论

        本文标题:Mac Flutter 问题之 Android license

        本文链接:https://www.haomeiwen.com/subject/hbqzmctx.html