1
resposta

error

Olá! Não consigo rodar o programa, aparece sempre esse erro:

"Build file 'C:\Users\Ley\Desktop\revisoes e testes\Alura\Navigation1\android-navigation-projeto-inicial\app\build.gradle' line: 2

A problem occurred evaluating project ':app'.

Failed to apply plugin [id 'kotlin-android'] The current Gradle version 5.1.1 is not compatible with the Kotlin Gradle plugin. Please use Gradle 6.1.1 or newer, or the previous version of the Kotlin plugin. "

meu gradle do app está assim:

apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
apply plugin: "androidx.navigation.safeargs.kotlin"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.android.application"

android {
    compileSdk 32

    defaultConfig {
        applicationId "br.com.alura.aluraesporte"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    def room_version = "2.0.0"

    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"

    def koin_version = "2.0.1"

    implementation "org.koin:koin-android:$koin_version"
    implementation "org.koin:koin-android-viewmodel:$koin_version"

    def coroutines_version = "1.1.1"

    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'


    def nav_version = "2.4.2"
    // Kotlin
    implementation("androidx.navigation:navigation-fragment-ktx:$nav_version")
    implementation("androidx.navigation:navigation-ui-ktx:$nav_version")
}

e o grade do projeto está assim:

buildscript {
    ext.kotlin_version = '1.3.40'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        def nav_version = "2.4.2"
        classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Se alguém souber como resolver eu agradeço muito!

1 resposta

Oi Ley, de boas?

Testei aqui e a princípio deu alguns problemas durante o build. Então, eu fiz o clean no projeto e pedi para fazer o build novamente e deu certo. Para isso, você pode ir em File > Invalidates Caches... > Invalidate and Restart. Esse procedimento é um pouco demorado, mas ele faz todo o processo de limpeza e build e costuma resolver diversos problemas de ambiente.

Antes de fazer isso no seu projeto, recomendo baixar novamente o projeto oferecido na atividade e realizar esses passos. Dado que é um projeto com configuração de build mais antiga, é extremamente recomendado evitar atualizações nos arquivos de builds, pois existe uma chance muito grande de incompatibilidade.

Vou compartilhar como ficaram os meus arquivos de build:

  • build.gradle do projeto
// Top-level build file where you can add configuration options common to all sub-projects/modules.

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"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
  • build.gradle do app
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "br.com.alura.aluraesporte"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    def room_version = "2.0.0"

    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"

    def koin_version = "2.0.1"

    implementation "org.koin:koin-android:$koin_version"
    implementation "org.koin:koin-android-viewmodel:$koin_version"

    def coroutines_version = "1.1.1"

    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
}

Resultado final no AS:Insira aqui a descrição dessa imagem para ajudar na acessibilidade