skip to Main Content

I have big struggles with the configuration of my Android Gradle Project. I tried a large number of solutions found on the internet, but still can’t build and run my project successfully. I try to add Firebase libraries to my app.

The app was generated via the latest Android Studio Navigation Template.

Here are my gradle files:

settings.gradle

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
}

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
        gradlePluginPortal()
//        jcenter()
    }
}
rootProject.name = "RowingBG Achievements"
include ':app'

build.gradle (Project)

buildscript {
    ext {
        gradle_version = "8.0.2"
        kotlin_version = '1.8.20'
        gms_version = '4.3.15'
    }
 //    repositories {
 //        google()
 //        mavenCentral()
 //        gradlePluginPortal()
 //        maven { url "https://maven.google.com" }
 //        maven { url "https://jitpack.io" }
 //    }

 //    dependencies {
 //        classpath "com.android.tools.build:gradle:$gradle_version"
 //        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
 //        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.41'
 //        classpath "com.google.gms:google-services:$gms_version"
 //    }
 }
 plugins {
    id 'com.android.application' version "$gradle_version" apply false
    id 'com.android.library' version "$gradle_version" apply false
    id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false
    id "com.google.gms.google-services" version "$gms_version" apply false
 }

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

build.gradle (Module:App)

apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'com.google.gms.google-services'
//apply plugin: 'kotlin-android'
//apply plugin: 'kotlin-kapt'

android {
    namespace 'com.bzahov.rowingbg'
    compileSdk 33

    defaultConfig {
        applicationId "com.bzahov.rowingbg"
        minSdk 28
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        viewBinding true
    }
}
dependencies { 
     // Import the BoM for the Firebase platform
    implementation platform('com.google.firebase:firebase-bom:32.1.0')
    implementation 'com.google.firebase:firebase-auth-ktx'
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.google.firebase:firebase-core'
    implementation "com.google.firebase:firebase-firestore-ktx"
    implementation "com.google.firebase:firebase-database-ktx"
    implementation "com.google.firebase:firebase-storage-ktx"
    implementation "com.google.android.gms:play-services-auth-ktx"


...}

I got so strange errors:

No variants found for ‘:app’. Check build files to ensure at least one variant exists. at:
com.android.tools.idea.gradle.project.sync.AndroidModule.prepare(GradleModules.kt:266)

After I resolved this one I got folowing one:

Could not find com.google.firebase:firebase-core:.
Required by:
project :app
Failed to resolve: com.google.android.gms:play-services-auth-ktx
Add Google Maven repository and sync project
Affected Modules: app

and

Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ‘:app:debugRuntimeClasspath’.

enter image description here

when I sync project I get these warnings like my project don’t access Google Maven repositoryenter image description here

I tried a lot of different approaches but I don’t have enough knowledge on new Settings. Gradle Approach. Can you help me resolve the issues or give me some advice and guidance?

I will be very grateful if you could help me to solve it because I already tried to do it alone, without success, for so much time

Thank you for your help in advance. 🙂

2

Answers


  1. in build.gradle (Module:App) you should remove -ktx from "com.google.android.gms:play-services-auth-ktx":

       implementation "com.google.android.gms:play-services-auth"
    
    Login or Signup to reply.
  2. The line of code that is causing you problems is:

    implementation 'com.google.firebase:firebase-core'
    

    Which is also currently deprecated. Besides that, you have removed the kotlin-android and kotlin-kapt plugins. To solve this, please add the following dependencies in your configuration files:

    settings.gradle:

    pluginManagement {
        repositories {
            gradlePluginPortal()
            google()
            mavenCentral()
        }
    }
    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            google()
            mavenCentral()
        }
    }
    rootProject.name = "RowingBG Achievements"
    include ':app'
    

    build.gradle (Project):

    buildscript {
        ext {
            gradle_version = '7.4.0'
            kotlin_version = '1.8.20'
            google_services_version = '4.3.15'
            firebase_bom_version = '32.0.0'
            play_services_auth_version = '20.5.0'
        }
        dependencies {
            classpath "com.google.gms:google-services:$google_services_version"
            classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
        }
    }
    
    plugins {
        id 'com.android.application' version "${gradle_version}" apply false
        id 'com.android.library' version "${gradle_version}" apply false
        id 'org.jetbrains.kotlin.android' version "${kotlin_version}" apply false
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    build.gradle (Module:App):

    plugins {
        id "com.android.application"
        id "kotlin-android"
        id "kotlin-kapt"
        id "com.google.gms.google-services"
    }
    
    android {
        namespace "com.bzahov.rowingbg"
        compileSdk 33
    
        defaultConfig {
            applicationId "com.bzahov.rowingbg"
            minSdk 21
            targetSdk 33
            versionCode 1
            versionName "1.0"
    
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
        kotlinOptions {
            jvmTarget = JavaVersion.VERSION_1_8
        }
        buildFeatures {
            viewBinding true
        }
    }
    
    dependencies {
        //Firebase
        implementation platform("com.google.firebase:firebase-bom:$firebase_bom_version")
        implementation "com.google.firebase:firebase-analytics-ktx"
        implementation "com.google.firebase:firebase-auth-ktx"
        implementation "com.google.firebase:firebase-firestore-ktx"
        implementation "com.google.firebase:firebase-database-ktx"
        implementation "com.google.firebase:firebase-storage-ktx"
        //Play Services Auth
        implementation "com.google.android.gms:play-services-auth:$play_services_auth_version"
    }
    

    Please note that these dependencies will work for implementing Firebase products. However, you also need to add the corresponding dependencies for Android.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search