1、前言
之前写了一篇文章关于 flutter 初体验的一篇,https://www.cnblogs.com/niceyoo/p/9240359.html,当时一顿骚操作,然后程序就跑起来了。
隔了好一段时间,换了个电脑,重新装了个AndroidStudio,继续搭建 Flutter ,然后哐哧哐哧用了一会就把需要配置弄好了,然后用 AS 创建了个项目,好家伙,直接报错。
Launching libmain.dart on ONEPLUS A5010 in debug mode... Initializing gradle... Resolving dependencies... * Error running Gradle: Exit code 1 from: F:android_studio_workspaceflutter_app2flutter_app2androidgradlew.bat app:properties: NDK is missing a "platforms" directory. If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to E:AndroidSDK dk-bundle. If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning. Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error. FAILURE: Build failed with an exception. * Where: Build file 'F:android_studio_workspaceflutter_app2flutter_app2androidappuild.gradle' line: 25 * What went wrong: A problem occurred evaluating project ':app'. > Could not resolve all files for configuration 'classpath'. > Could not find lint-gradle-api.jar (com.android.tools.lint:lint-gradle-api:26.1.2). Searched in the following locations: https://jcenter.bintray.com/com/android/tools/lint/lint-gradle-api/26.1.2/lint-gradle-api-26.1.2.jar * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 2s Finished with error: Please review your Gradle project setup in the android/ folder.
2、问题分析
先看最后一条信息:
finished with error: please review your gradle project setup in the android/ folder.
说,让我检查 gradle,然后各种找,发现没错啊。
还是从第一条错误开始看吧:
NDK is missing a "platforms" directory. If you are using NDK, verify the ndk_ ......
好家伙,这又是个什么鬼.
NDK缺少一个“platforms”目录。如果您正在使用NDK,请验证NDK。将dir设置为有效的NDK目录。
目前它被设置为D: AndroidSDK dk-bundle。
如果不使用NDK,请从ANDROID_NDK_HOME或local中卸载NDK变量。属性删除此警告。
2.1 解决第一个问题
既然说少了就装个吧。
下载链接:https://developer.android.google.cn/ndk/downloads/
下载,解压zip文件 得到一个 android-ndk-rXXb 的文件夹,直接解压,然后把该文件夹下的所有文件都移动到你的,sdk,ndk-bundle 文件夹下。
再配置个环境变量,重启 AS 解决问题。
2.2 解决第二个问题
Build file 'F:android_studio_workspaceflutter_app2flutter_app2androidappuild.gradle' line: 25
找到 flutter SDK 路径下的 flutterpackagesflutter_toolsgradleflutter.gradle 文件。
把 gradle 版本改低一点。
博客地址:https://www.cnblogs.com/niceyoo