如何修复停止工作的gradle - 同步时出错?

Posted

技术标签:

【中文标题】如何修复停止工作的gradle - 同步时出错?【英文标题】:How to fix gradle which stopped working - error while syncing? 【发布时间】:2021-12-25 02:58:20 【问题描述】:

我在我的 android 项目中遇到了 gradle 问题。我觉得我自己无法解决这个问题很愚蠢。我昨天晚上关闭了项目,今天早上重新打开了它,所以根本没有动过gradle。今天早上我收到以下错误

    Could not compile build file 'D:\Code\Android\workouttracker\app\build.gradle'.
> startup failed:
  build file 'D:\Code\Android\workouttracker\app\build.gradle': 87: Unexpected input: '' @ line 87, column 14.
     dependencies 

所以我猜它一定是一个缺少的刹车,但我在我的构建 gradle 中找不到一个,也许我是愚蠢或盲目的。 在项目目录中运行 gradlew 时出现同样的错误

这是我的 build.gradle(在我尝试修复它之后)

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'


configurations.implementation 
        exclude group: 'org.jetbrains' , module:'annotations'
        exclude group: 'org.jetbrains.kotlin' , module:'kotlin-stdlib'
        exclude group: 'com.intellij', module:'annotations'
        exclude group: 'com.intellij', module:'annotations'
        exclude group: 'com.intellij', module:'annotations'


android 
    lintOptions 
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    

    compileSdkVersion 30
    buildToolsVersion '32.0.0-rc1'
    defaultConfig 
        applicationId 'ch.workouttracker'
        minSdkVersion 28
        targetSdkVersion 30
        versionCode 901
        versionName '0.9.0.1'
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        resConfigs "de" // And any other languages you support
    

    signingConfigs 
        release 
            storeFile file("C:\\Users\\DonBolli\\.android\\debug.keystore")
            storePassword ANDROID_STORE_PASSWORD
            keyAlias 'workouttrackerkey'
            keyPassword ANDROID_KEY_PASSWORD
        
        debug 
            storeFile file("C:\\Users\\DonBolli\\.android\\debug.keystore")
            storePassword ANDROID_STORE_PASSWORD
            keyAlias 'workouttrackerkey'
            keyPassword ANDROID_KEY_PASSWORD
        
    

    buildTypes 
        debug 
            minifyEnabled false
            signingConfig signingConfigs.debug
        
        release 
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        
    

    packagingOptions 
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.md'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.md'
        exclude 'META-INF/DEPENDENCIES'

    

    defaultConfig 
        vectorDrawables.useSupportLibrary = true
    

    compileOptions 
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    


allprojects 
    repositories 
        mavenCentral()
        maven  url = "https://maven.fabric.io/public" 
    


dependencies 

    implementation fileTree(include: ['*.jar'], dir: 'libs')
    
    //Firebase
    implementation platform('com.google.firebase:firebase-bom:29.0.0')
    implementation ("com.google.firebase:firebase-core:20.0.0") 
        exclude group: "com.android.support", module: "support-v4"
    
    implementation 'com.google.firebase:firebase-messaging:23.0.0'
    implementation 'com.google.firebase:firebase-analytics:20.0.0'
    implementation 'com.google.firebase:firebase-plugins:2.0.0'
    implementation 'com.google.firebase:firebase-ml-vision:24.0.0'
    implementation ("com.google.firebase:firebase-auth:21.0.1") 
        exclude group: "com.android.support", module: "support-v4"
    
    implementation 'com.google.firebase:firebase-database:20.0.2'
    implementation 'com.google.firebase:firebase-storage:20.0.0'


    //CrashAlyrics
    implementation 'com.google.firebase:firebase-crashlytics'
    implementation 'com.google.firebase:firebase-analytics'


    //Graphview
    implementation 'com.jjoe64:graphview:4.2.1'
    implementation 'org.apache.commons:commons-lang3:3.4'


    //Google Play
    implementation ("com.google.android.gms:play-services-base:17.6.0") 
        exclude group: "com.android.support", module: "support-v4"
    
    implementation 'com.google.android.gms:play-services-auth:19.2.0'


    //Support
    implementation "androidx.appcompat:appcompat:1.1.0"
    implementation "androidx.appcompat:appcompat-resources:1.1.0"
    implementation "androidx.navigation:navigation-fragment-ktx:2.2.1"
    implementation "androidx.drawerlayout:drawerlayout:1.0.0"
    implementation "androidx.gridlayout:gridlayout:1.0.0"
    implementation "androidx.preference:preference:1.1.0"
    implementation "androidx.recyclerview:recyclerview:1.1.0"
    implementation "androidx.cardview:cardview:1.0.0"

    implementation "io.reactivex.rxjava2:rxjava:2.2.13"
    implementation "io.reactivex.rxjava2:rxandroid:2.1.1"

    // Gradle
    implementation com.android.tools.build:gradle);

    //Glide
    implementation 'com.github.bumptech.glide:glide:4.11.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

    /**
     * dependency to request the runtime permissions.
     */
    implementation 'com.karumi:dexter:4.2.0'

    // code generator for view
    implementation "com.jakewharton:butterknife:10.2.0"
    annotationProcessor "com.jakewharton:butterknife-compiler:10.2.0"
    testImplementation 'junit:junit:4.12'


apply plugin: 'com.google.gms.google-services'

【问题讨论】:

【参考方案1】:

依赖里面有错误

// Gradle
implementation com.android.tools.build:gradle);

改成

// Gradle
implementation 'com.android.tools.build:gradle'

【讨论】:

以上是关于如何修复停止工作的gradle - 同步时出错?的主要内容,如果未能解决你的问题,请参考以下文章

如何修复项目“MyApp”不是基于 gradle 的项目

Gradle 同步失败:原因:打开 zip 文件时出错 Corrupt Dependency Cache

当我在开发模式下停止应用程序并将 build.gradle.kts 与 spring boot 一起使用时出错

CDR已停止工作,怎么破?

运行MyActivity时出错:Gradle项目同步失败。请修正您的专案,然后再试一次

如何修复“读写数据沙箱:使用 Mac Catalyst 时出错”