[英]New Flutter Project in VSCode. Could not resolve Kotlin plugin
How do I correctly use Kotlin plugin when creating a new flutter project in VSCode?在 VSCode 中创建新的 Flutter 项目时,如何正确使用 Kotlin 插件?
I'm trying to create a new flutter project in VSCode.我正在尝试在 VSCode 中创建一个新的 Flutter 项目。
Flutter has been working for me since the start of the year but for some reason I'm getting this error in debug console when I try to run on my device. Flutter 自今年年初以来一直在为我工作,但由于某种原因,当我尝试在我的设备上运行时,我在调试控制台中收到此错误。
Launching lib/main.dart on SM A520F in debug mode...
* Error running Gradle:
ProcessException: Process "/Users/jackstewart/Desktop/Work/All App Projects/Stiffness Method Solver/Flutter/newtest/android/gradlew" exited abnormally:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71.
Required by:
project :
> Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71.
> Could not get resource 'https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.71/kotlin-gradle-plugin-1.2.71.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.71/kotlin-gradle-plugin-1.2.71.pom'.
> Connect to 10.1.1.150:19000 [/10.1.1.150] failed: Connection refused (Connection refused)
> Could not resolve 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.pom'.
> Could not GET 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.71/kotlin-gradle-plugin-1.2.71.pom'.
> Connect to 10.1.1.150:19000 [/10.1.1.150] failed: Connection refused (Connection refused)
* 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
Command: /Users/jackstewart/Desktop/Work/All App Projects/Stiffness Method Solver/Flutter/newtest/android/gradlew app:properties
Please review your Gradle project setup in the android/ folder.
Exited (sigterm)
My android/gradle.build is我的 android/gradle.build 是
buildscript {
ext.kotlin_version = '1.2.71'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My other flutter projects use java as their android code.我的其他 flutter 项目使用 java 作为他们的 android 代码。 This is the first time i'm using kotlin as it now seems to be the default.这是我第一次使用 kotlin,因为它现在似乎是默认设置。 I'm not sure if i have the right kotlin plugin or how to install it i just assumed VSCode would do that automatically in setting up the New Project.我不确定我是否有正确的 kotlin 插件或如何安装它,我只是假设 VSCode 会在设置新项目时自动执行此操作。
Steps to reproduce重现步骤
1. Open new window in VSCode
2. View > command palate > Flutter: New Project
3. Type “newtest” and hit enter
4. Select a folder to create the project
5. Connect device
6. In vscode click debug > start debugging
My flutter sdk at the bottom bar on vscode is showing我在 vscode 底部栏上的 flutter sdk 正在显示
Flutter: 1.9.1+hotfix.6
My gradlew file is我的gradlew文件是
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
What I've tried我试过的
The console error suggests trying to run with: --stacktrace, --info , --debug, --scan.控制台错误建议尝试运行:--stacktrace、--info、--debug、--scan。 I figured out how to do that from this post我从这篇文章中想出了如何做到这一点
My stacktrace is long and similar.我的堆栈跟踪很长而且很相似。 The info results were similar and the debug results were too long (if you really want I can include them) The scan results were short and odd.信息结果相似,调试结果太长(如果你真的想要我可以包括它们)扫描结果又短又奇怪。 It seems its saying I can't scan but then suggests to scan… |:似乎它说我无法扫描但随后建议扫描... |:
It seems my main issue is with kotlin in this line看来我的主要问题是这一行中的 kotlin
Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71
But not much comes up when I google this但是当我用谷歌搜索时并没有出现太多
This SO post led me to this kotlin documentation that said to use a new version in gradle files like 这篇 SO 帖子让我找到了这个 kotlin 文档,该文档说在 gradle 文件中使用新版本,例如
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"
but i get the same error with the new version但我在新版本中遇到了同样的错误
Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61
My question is how do I correctly use Kotlin plugin when creating a new flutter project in VSCode?我的问题是在 VSCode 中创建新的 Flutter 项目时如何正确使用 Kotlin 插件?
EDIT :编辑:
In the end I gave up with kotlin and went back to java.最后我放弃了 kotlin,回到了 java。
This is a shame because kotlin is the default in flutter which means it is preferred and I've heard there are some advantages to using it over java.这是一种耻辱,因为 kotlin 是 flutter 中的默认值,这意味着它是首选,而且我听说使用它比 java 有一些优势。 This is why I didn't put this as an answer.这就是为什么我没有把它作为答案。 Here are my steps to convert back to java这是我转换回java的步骤
in terminal run在终端运行中
flutter create --org com.example.newtest -a java newtest
or more generally或更一般地
flutter create --org [package] -a java [project]
In vscode click debug > start debugging在 vscode 中点击调试 > 开始调试
EDIT 2 :编辑 2 :
Since last edit I can't even get a hello world project to run.自上次编辑以来,我什至无法运行 hello world 项目。
EDIT 3 :编辑 3 :
I reinstalled Android studio twice (the first reinstall may have had problems maybe because I dragged my old Android SDK into Android studio folder as it wasn't included).我重新安装了 Android Studio 两次(第一次重新安装可能有问题,可能是因为我将旧的 Android SDK 拖到了 Android Studio 文件夹中,因为它不包含在内)。 After reinstalling again kotlin now works easily in a new project.重新安装后,kotlin 现在可以在新项目中轻松工作。 The second time I uninstalled I used these commands to help https://stackoverflow.com/a/18458893/9713633第二次卸载我用这些命令帮助https://stackoverflow.com/a/18458893/9713633
Could not GET ' https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.71/kotlin-gradle-plugin-1.2.71.pom '.无法获取“ https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.71/kotlin-gradle-plugin-1.2.71.pom ”。 Connect to 10.1.1.150:19000 [/10.1.1.150] failed: Connection refused (Connection refused)连接到 10.1.1.150:19000 [/10.1.1.150] 失败:连接被拒绝(连接被拒绝)
Based on this error, it seems like the hostname has resolved to the IP address 10.1.1.150
.基于此错误,主机名似乎已解析为 IP 地址10.1.1.150
。 This IP address is reserved for local use and is not routable over the internet so it seems like something is wrong with the DNS resolution for this hostname.此 IP 地址保留供本地使用,无法通过 Internet 路由,因此此主机名的 DNS 解析似乎有问题。 You should investigate why this is ocurring (possible a local hosts file, or a local DNS server?).您应该调查发生这种情况的原因(可能是本地主机文件,还是本地 DNS 服务器?)。 If you can get it to resolve to the correct IP (the IP I currently get is 172.217.169.46
) then it should solve your issue (or at least get you further).如果您可以将其解析为正确的 IP(我目前获得的 IP 是172.217.169.46
),那么它应该可以解决您的问题(或至少让您更进一步)。
Edit: Based on the port number in the error (which is not 443, as the URL would indicate), maybe it's trying to connect to a proxy on that IP rather than resolving the hostname to it?编辑:根据错误中的端口号(不是 443,如 URL 所示),也许它正在尝试连接到该 IP 上的代理,而不是将主机名解析为它? Do you have a proxy set up (that may no longer be working)?您是否设置了代理(可能不再有效)?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.