gpt4 book ai didi

android - VSCode中的新Flutter项目。无法解析Kotlin插件

转载 作者:行者123 更新时间:2023-12-03 04:12:00 36 4
gpt4 key购买 nike

TL; DR

在VSCode中创建新的flutter项目时,如何正确使用Kotlin插件?

我正在尝试在VSCode中创建一个新的flutter项目。

从今年年初开始,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)

我的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
}

我其他的flutter项目都使用java作为其android代码。这是我第一次使用kotlin,因为它现在似乎是默认值。我不确定我是否具有正确的kotlin插件或如何安装它,我只是假设VSCode在设置新项目时会自动执行此操作。

重现步骤
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

我在vscode底部栏中的sdk抖动显示
Flutter: 1.9.1+hotfix.6
我的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 "$@"

我尝试过的内容

控制台错误提示尝试使用以下命令运行:--stacktrace,--info,--debug和--scan。我从 this post知道了怎么做

我的堆栈跟踪很长而且很相似。信息结果相似,调试结果太长(如果您真的希望我可以包括它们),扫描结果又短又奇。似乎是在说我无法扫描,但建议您扫描…|:

看来我的主要问题是Kotlin在这一行
Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71

但是当我用谷歌搜索时并没有太多

This SO post导致我进入 this kotlin documentation,据说该文件在gradle文件中使用了新版本,例如
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61" 

但是我在新版本中遇到相同的错误
Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61

我的问题是,在VSCode中创建新的flutter项目时,如何正确使用Kotlin插件?

编辑:

最后,我放弃了kotlin,回到了Java。

很可惜,因为kotlin是flutter中的默认设置,这意味着它是首选的,而且我听说使用它比java有一些优势。这就是为什么我没有将其作为答案的原因。这是我转换回Java的步骤
  • 删除android文件夹
  • 导航到项目
  • 的父目录
    终端运行中的

  • flutter create --org com.example.newtest -a java newtest

    或更一般地
    flutter create --org [package] -a java [project]
  • 在vscode中,单击调试>开始调试

  • 编辑2 :

    自上次编辑以来,我什至无法运行hello world项目。

    编辑3 :

    我重新安装了Android Studio两次(第一次重新安装可能会遇到问题,可能是因为我将旧的Android SDK拖到了Android Studio文件夹中,因为它不包含在内)。再次重新安装后,kotlin现在可以在新项目中轻松工作。
    第二次卸载时,我使用以下命令来帮助 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'. Connect to 10.1.1.150:19000 [/10.1.1.150] failed: Connection refused (Connection refused)



    基于此错误,主机名似乎已解析为IP地址 10.1.1.150。该IP地址为 reserved for local use,无法通过Internet路由,因此该主机名的DNS解析似乎有问题。您应该调查为什么会发生这种情况(可能是本地主机文件,还是本地DNS服务器?)。如果您可以将其解析为正确的IP(我当前获得的IP是 172.217.169.46),那么它应该可以解决您的问题(或者至少可以使您更进一步)。

    编辑:基于错误中的端口号(如URL所示,它不是443),也许它正在尝试连接到该IP上的代理而不是解析主机名?您是否设置了代理(可能不再工作了)?

    关于android - VSCode中的新Flutter项目。无法解析Kotlin插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59232983/

    36 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com