[英]Android Studio project could not synchronise with Gradle files
I am completely new to apps development.我对应用程序开发完全陌生。 I am trying to build up the foundation of the knowledge by following the instructions from an online course ( https://developer.android.com/codelabs/build-your-first-android-app#8 ) given by the android developer page in using Android Studio with Java.我正在尝试按照 ZC31B323064CE19CA8ZECD1 开发人员页面提供的在线课程( https://developer.android.com/codelabs/build-your-first-android-app#8 )的说明来建立知识基础在使用 Android Studio 和 Java。
After I add the lines to the project gradle file: def nav_version = "2.3.0-alpha04" classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"在我将这些行添加到项目 gradle 文件后: def nav_version = "2.3.0-alpha04" classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
and to the app gradle file: apply plugin: 'androidx.navigation.safeargs'和应用程序 gradle 文件:应用插件:'androidx.navigation.safeargs'
My project is failed to synchronize with the Gradle files.我的项目无法与 Gradle 文件同步。 Could someone solve the error and explain the error to me?有人可以解决错误并向我解释错误吗? I have tried to rebuild the project but it didn't work out.我试图重建项目,但没有成功。 Below is the code and the error:下面是代码和错误:
Error: class org.codehaus.groovy.ast.expr.TupleExpression cannot be cast to class org.codehaus.groovy.ast.expr.ArgumentListExpression (org.codehaus.groovy.ast.expr.TupleExpression and org.codehaus.groovy.ast.expr.ArgumentListExpression are in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @42d80b78) class org.codehaus.groovy.ast.expr.TupleExpression cannot be cast to class org.codehaus.groovy.ast.expr.ArgumentListExpression (org.codehaus.groovy.ast.expr.TupleExpression and org.codehaus.groovy.ast.expr.ArgumentListExpression are in unnamed module of loader org.Z8ED1A771BC236C287AD93C699BFDD2D Error: class org.codehaus.groovy.ast.expr.TupleExpression cannot be cast to class org.codehaus.groovy.ast.expr.ArgumentListExpression (org.codehaus.groovy.ast.expr.TupleExpression and org.codehaus.groovy.ast .expr.ArgumentListExpression are in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @42d80b78) class org.codehaus.groovy.ast.expr.TupleExpression cannot be cast to class org.codehaus.groovy.ast.expr.ArgumentListExpression (org.codehaus.groovy.ast.expr.TupleExpression 和 org.codehaus.groovy.ast.expr.ArgumentListExpression 在加载程序 org.Z8ED1A77169BF22287AD3 的未命名模块中7Z.internal.classloader.VisitableURLClassLoader @42d80b78) 7Z.internal.classloader.VisitableURLClassLoader @42d80b78)
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Gradle 的依赖缓存可能已损坏(这有时会在网络连接超时后发生。)
Re-download dependencies and sync project (requires network) The state of a Gradle build process (daemon) may be corrupt.重新下载依赖项和同步项目(需要网络) Gradle 构建过程(守护程序)的 state 可能已损坏。 Stopping all Gradle daemons may solve this problem.停止所有 Gradle 守护程序可能会解决此问题。
Stop Gradle build processes (requires restart) Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.停止 Gradle 构建过程(需要重新启动) 您的项目可能正在使用与项目中其他插件或项目请求的 Gradle 版本不兼容的第三方插件。
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.在 Gradle 进程损坏的情况下,您也可以尝试关闭 IDE 然后杀死所有 Java 进程。
Code: enter image description here代码:在此处输入图像描述
Can you try below lines As It's working fine for me.您可以尝试以下几行吗?因为它对我来说很好用。
// Add to Porject level gralde file
def nav_version = "2.3.5"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
//Add to Module level gralde file.
id "androidx.navigation.safeargs.kotlin"
Difference b/w androidx.navigation.safeargs.kotlin and androidx.navigation.safeargs黑白差异 androidx.navigation.safeargs.kotlin 和 androidx.navigation.safeargs
id 'androidx.navigation.safeargs' is for Java/Kotlin mixed modules
id 'androidx.navigation.safeargs.kotlin' is for pure Kotlin modules.
Plus put the plugin at the end eg check below example加上把插件放在最后,例如检查下面的例子
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'androidx.navigation.safeargs.kotlin'
Other Info, You can try below options as well.其他信息,您也可以尝试以下选项。
-Check If the Gradle is on online mode not offline (Right side menu bar click on Gradle =//= check If that sign is not pressed.)
-Clean your project then rebuild
-Invalidate Cache and Restart
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.