Android Studio成功集成Flutter插件以后,就可以新建一个Flutter项目了。创建Flutter项目成功之后,运行Flutter项目出现如下异常:
* Where:
Build file ‘/Users/guotianhui/Downloads/flutter_app2/flutter_appw2/android/app/build.gradle’ line: 25
* What went wrong:
A problem occurred evaluating project ‘:app’.
> Could not resolve all artifacts for configuration ‘classpath’.
> Could not download guava.jar (com.google.guava:guava:23.0)
> Could not get resource ‘https://jcenter.bintray.com/com/google/guava/guava/23.0/guava-23.0.jar’.
> Could not GET ‘https://d29vzk4ow07wi7.cloudfront.net/7baa80df284117e5b945b19b98d367a85ea7b7801bd358ff657946c3bd1b6596?response-content-disposition=attachment%3Bfilename%3D%22guava-23.0.jar%22&Policy=eyJTdGF0ZW1lbnQiOiBbeyJSZXNvdXJjZSI6Imh0dHAqOi8vZDI5dnprNG93MDd3aTcuY2xvdWRmcm9udC5uZXQvN2JhYTgwZGYyODQxMTdlNWI5NDViMTliOThkMzY3YTg1ZWE3Yjc4MDFiZDM1OGZmNjU3OTQ2YzNiZDFiNjU5Nj9yZXNwb25zZS1jb250ZW50LWRpc3Bvc2l0aW9uPWF0dGFjaG1lbnQlM0JmaWxlbmFtZSUzRCUyMmd1YXZhLTIzLjAuamFyJTIyIiwiQ29uZGl0aW9uIjp7IkRhdGVMZXNzVGhhbiI6eyJBV1M6RXBvY2hUaW1lIjoxNTYwNzUwMTk3fSwiSXBBZGRyZXNzIjp7IkFXUzpTb3VyY2VJcCI6IjAuMC4wLjAvMCJ9fX1dfQ__&Signature=BoSQcFEL3Wy5BF-bG56IkHfoEYKYHwgjjlfYH9mJ-fZtvTZeigVj9CtP01QtxQJHQsCsNeiFKD2j7SuxOupMU7zjaiG4xrk2-0f-xpFJo~dto51u3n~kmRXqZEBjDZcFUch3LAusdsMbP1p-EOoZvmv9E6VjVeVkc-zR-JMuTpPYuy0TTDGEc2JfhSwVa0JE75yy1ikrlOlqAoH3JGMZjcUhQYeiCe56LKlX5f5QEFsU-aMQhuAwe12bco5~XuSf4IzdFRr~iUQ-n10e8OBykoV7ke9apVI45DMAVALTSozU0ZwyyFPvnFWO8LLNhRjdvY65RAE6mfE8RSRJFZSZMA__&Key-Pair-Id=APKAIFKFWOMXM2UMTSFA’.
> Connect to d29vzk4ow07wi7.cloudfront.net:443 [d29vzk4ow07wi7.cloudfront.net/99.84.231.221, d29vzk4ow07wi7.cloudfront.net/99.84.231.76, d29vzk4ow07wi7.cloudfront.net/99.84.231.93, d29vzk4ow07wi7.cloudfront.net/99.84.231.174] failed: Read timed out
* 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 6m 26s
Command: /Users/guotianhui/Downloads/flutter_app2/flutter_appw2/android/gradlew app:properties
Finished with error: Please review your Gradle project setup in the android/ folder.
这里提示在Android目录找不到Guava包,并提示错误在app bulid.gradle文件的第25行:
apply from: “$flutterRoot/packages/flutter_tools/gradle/flutter.gradle”
定位到flutterRoot指向的是flutter.sdk的配置。
def flutterRoot = localProperties.getProperty(‘flutter.sdk’)
if (flutterRoot == null) {
throw new GradleException(“Flutter SDK not found. Define location with flutter.sdk in the local.properties file.”)
}
我们在local.properties文件里面可以查看到flutter sdk的路径:
flutter.sdk=/Users/guotianhui/Android/flutter
目前除了找不到GradleException这个异常类之外,其他都没有发现异常问题。然后百度了通过dependencies依赖类库的方式:
testImplementation ‘com.google.guava:guava:24.0-android’
testImplementation ‘com.google.guava:guava:24.0-jre’
集成到项目里面,但是依然没有解决问题。还是报下面的错误:
* Error running Gradle:
ProcessException: Process “/Users/guotianhui/Downloads/flutter_app2/flutter_appw2/android/gradlew” exited abnormally:
Command: /Users/guotianhui/Downloads/flutter_app2/flutter_appw2/android/gradlew app:properties
Finished with error: Please review your Gradle project setup in the android/ folder.
使用Android studio 集成Flutter插件,除了在Android Studio IDE里面通过File–>Settings–>
Plugins–>下载Flutter插件,下载Flutter插件时会提示你是否下载Dart插件,点击确认下载就行。
到这里我们就在Android Studio IDE里面集成了Flutter插件,但是我们还是不能直接开发Flutter项目,在我们启动Studio的时候,我们发现多了一个可以新建Flutter项目选项。但是我们并没有配置好Flutter的开发环境,也就是Flutter的Sdk。类似与Java Sdk,我们需要配置Flutter Sdk的绝对路径到Path环境变量。
Winddows用户操作比较简单,选中电脑–>属性–>高级选项–>环境变量–>新建一个FLUTTER_PATH环境变量,设置值为你直接从Flutter官网下载的SDK绝对路径。下载完Flutter文件之后,我们就不需要再去Dart官网下载Dart Sdk文件了,因为Fluter Sdk的bin/cache/目录下就包含了dart-sdk文件。
那么我们说一些Mac用户如何配置Flutter Sdk环境变量,当然你也可以查看官网的配置教程:
open .bash_profile
这个是本人比较喜欢的Mac添加环境变量的命令,直接打开环境变量文件,然后更改里面的环境变量,添加下面配置:
export PATH=安装路径/flutter/bin:$PATH
最后更改好之后,直接关闭文件,默认就保存了。但是还要记得执行下面的命令来保存你更改的环境变量配置:
source .bash_profile
最后我们可以运行下面的命令查看Flutter Sdk有没有保存成功:
flutter doctor
如果出现下面的界面,说明你的Flutter Sdk安装成功了。
成功安装Flutter插件和Dart插件,还有配置好Flutter 和Dart的绝对路径之后,我们再去新建一个Flutter项目发现并没有报错。但是运行之后报下面的错:
What went wrong:
A problem occurred configuring root project ‘android’.
> Could not resolve all artifacts for configuration ‘:classpath’.
> Could not download kotlin-gradle-plugin.jar (org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71)
> Could not get resource ‘https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.71/kotlin-gradle-plugin-1.2.71.jar’….
这是因为我们升级了kotlin的版本导致的,项目找不到1.2.71的kotlin jar包。我们打开android项目配置里面的build.gradle文件成和你项目一致的kotlin版本和android studio版本就可以了。
buildscript {
ext.kotlin_version = ‘1.3.31’
repositories {
google()
jcenter()
}
dependencies {
classpath ‘com.android.tools.build:gradle:3.4.1’
classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version”
}
}
这里我们的android studio 的版本是3.4.1,对应的最新的kotlin版本是1.3.31,如果你不知道你的studio版本,可以查看IDE的导航栏,查看help->搜索about studio 查看版本,查看kotlin的最新版本可以查看Tools->kotlin->Configeru Kotlin Plugin Updates。需要查看kotlin版本对应的android studio版本,可以前往Kotlin Plugin官网。
但是现在虽然我的项目可以单独运行android项目了,但是直接在Flutter项目里面运行还是会报下面的错:
* What went wrong:
A problem occurred configuring root project ‘android’.
> Could not resolve all artifacts for configuration ‘:classpath’.
> Could not download kotlin-compiler-embeddable.jar (org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.31)
> Could not get resource ‘https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.3.31/kotlin-compiler-embeddable-1.3.31.jar’.
> Could not GET ‘https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.3.31/kotlin-compiler-embeddable-1.3.31.jar’.
> Read timed out
> Could not download kotlin-build-common.jar (org.jetbrains.kotlin:kotlin-build-common:1.3.31)
> Could not get resource ‘https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-build-common/1.3.31/kotlin-build-common-1.3.31.jar’.
> Could not GET ‘https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-build-common/1.3.31/kotlin-build-common-1.3.31.jar’.
> Read timed out
> Could not download kotlin-daemon-client.jar (org.jetbrains.kotlin:kotlin-daemon-client:1.3.31)
> Could not get resource ‘https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-daemon-client/1.3.31/kotlin-daemon-client-1.3.31.jar’.
> Could not GET ‘https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-daemon-client/1.3.31/kotlin-daemon-client-1.3.31.jar’.
> Read timed out
这里提示我下载不了kotlin compiler编译器读取超时,百度了一下说是链接链接超时的问题,需要替换成阿里的链接。把google() 和 jcenter()这两行去掉。改为阿里的链接:
maven { url ‘https://maven.aliyun.com/repository/google’ }
maven { url ‘https://maven.aliyun.com/repository/jcenter’ }
maven { url ‘http://maven.aliyun.com/nexus/content/groups/public’ }
替换成功之后,再次运行就可以成功运行了。
总结一下遇到的问题:
如果你下载了Flutter插件和Dart插件之后,新建Flutter项目之后;
第一,如果你的项目报编译错误,那么可能是你没有正确的配置好Flutter和Dart Sdk的路径。
第二,如果你配置好了Flutter和Dart 插件的Sdk路径,但是运行时报Kotlin jar包找不到,需要检查你的kotlin版本和android studio版本是否配对,然后在确认respositorier的路径是否改成阿里的地址。
以上就是全部坑,希望对大家有用!
1、本站所有资源均从互联网上收集整理而来,仅供学习交流之用,因此不包含技术服务请大家谅解!
2、本站不提供任何实质性的付费和支付资源,所有需要积分下载的资源均为网站运营赞助费用或者线下劳务费用!
3、本站所有资源仅用于学习及研究使用,您必须在下载后的24小时内删除所下载资源,切勿用于商业用途,否则由此引发的法律纠纷及连带责任本站和发布者概不承担!
4、本站站内提供的所有可下载资源,本站保证未做任何负面改动(不包含修复bug和完善功能等正面优化或二次开发),但本站不保证资源的准确性、安全性和完整性,用户下载后自行斟酌,我们以交流学习为目的,并不是所有的源码都100%无错或无bug!如有链接无法下载、失效或广告,请联系客服处理!
5、本站资源除标明原创外均来自网络整理,版权归原作者或本站特约原创作者所有,如侵犯到您的合法权益,请立即告知本站,本站将及时予与删除并致以最深的歉意!
6、如果您也有好的资源或教程,您可以投稿发布,成功分享后有站币奖励和额外收入!
7、如果您喜欢该资源,请支持官方正版资源,以得到更好的正版服务!
8、请您认真阅读上述内容,注册本站用户或下载本站资源即您同意上述内容!
原文链接:https://www.shuli.cc/?p=7050,转载请注明出处。
评论0