1

Пытаюсь подключить свое приложение к базе данных, где будут храниться данные для входа (имя, фамилия, E-mail и пароль). Зарегистрировался, все заполнил, скачал файл .json и импортировал его, и теперь пришло время вставить код в build.gradle, как проекта, так и модуля. Проблемы на данном этапе возникли с файлом проекта. Там у меня до этого находился код с плагинами вот такой:

plugins {
    id 'com.android.application' version '7.4.0' apply false
    id 'com.android.library' version '7.4.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.21' apply false
}

Ну а я решил вставить код из Firebase, не удаляя плагинов, синхронизировал его, и начал получать ошибки одну за другой. Сначала вставил так:

plugins {
    id 'com.android.application' version '7.4.0' apply false
    id 'com.android.library' version '7.4.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.21' apply false
}
buildscript {
    repositories {
        // Make sure that you have the following two repositories
        google()  // Google's Maven repository

        mavenCentral()  // Maven Central repository

    }
    dependencies {
        // Add the dependency for the Google services Gradle plugin
        classpath 'com.google.gms:google-services:4.3.15'

    }
}

allprojects {
    repositories {
        // Make sure that you have the following two repositories
        google()  // Google's Maven repository

        mavenCentral()  // Maven Central repository

    }
}

и получил ошибку "startup failed: build file 'D:\SatriaAdhiPradana\build.gradle': 7: all buildscript {} blocks must appear before any plugins {} blocks in the script". Прочитал ее внимательно, понял, что блоки bildscript надо размещать до плагинов и переставил так:

buildscript {
    repositories {
        // Make sure that you have the following two repositories
        google()  // Google's Maven repository

        mavenCentral()  // Maven Central repository

    }
    dependencies {
        // Add the dependency for the Google services Gradle plugin
        classpath 'com.google.gms:google-services:4.3.15'

    }
}
plugins {
    id 'com.android.application' version '7.4.0' apply false
    id 'com.android.library' version '7.4.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.21' apply false
}
allprojects {
    repositories {
        // Make sure that you have the following two repositories
        google()  // Google's Maven repository

        mavenCentral()  // Maven Central repository

    }
}

Пошла во всю синхронизация, думал все сделал правильно, и вдруг - возникает очень длинная ошибка (решил не помещать ее здесь, чтобы вопрос уложился по количеству символов и опубликовался.

Потом внимательно прочитал, что эту штуку надо вставить, как плагин, и включил его в сам код plugins вот так:

{
    id 'com.android.application' version '7.4.0' apply false
    id 'com.android.library' version '7.4.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.21' apply false

    buildscript {
        repositories {
            // Make sure that you have the following two repositories
            google()  // Google's Maven repository

            mavenCentral()  // Maven Central repository

        }
        dependencies {
            // Add the dependency for the Google services Gradle plugin
            classpath 'com.google.gms:google-services:4.3.15'

        }
    }
    allprojects {
        repositories {
            // Make sure that you have the following two repositories
            google()  // Google's Maven repository

            mavenCentral()  // Maven Central repository

        }
    }
}

Получил вот такую ошибку:

  build file 'D:\SatriaAdhiPradana\build.gradle': 8: only id(String), alias(Provider), or alias(ProviderConvertible) method calls allowed in plugins {} script block

В связи с этим возникает вопрос, что я делаю не так? Куда деть эти плагины? Надо ли сначала в Android SDK подключать возможность связываться с базой данных?

1 ответ 1

1

Вы пытаетесь включить плагин google-services старым способом. нужно в build.gradle уровня проекта добавить последней строчкой в plugins

id 'com.google.gms.google-services' version '4.3.15' apply false

также в build.gradle(:app) нужно добавить в plugins

id 'com.google.gms.google-services'

Все остальные добавленные блоки нужно удалить

1
  • А maven() и связанный с ним url тоже зашит в этот плагин? 16 мар в 22:18

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.