S
S
Stepan2021-03-12 14:38:48
gradle
Stepan, 2021-03-12 14:38:48

How to correctly add the plugins section in the build.gradle file?

Following the Realm documentation for Android, stumbled on this step:

Apply the realm-android plugin near the top of your application level build.gradle file:
apply plugin: 'realm-android'


I have Android Studio (4.1.2). In a new empty project, the build.gradle file has the following structure:
plugins {
    id 'com.android.application'
}
...

When adding the desired line (and sync):
apply plugin: 'realm-android'

plugins {
    id 'com.android.application'
}
...
An error is thrown:
Build file 'C:\Users\Admin\AndroidStudioProjects\RealmNotes\app\build.gradle' line: 3
Could not compile build file 'C:\Users\Admin\AndroidStudioProjects\RealmNotes\app\build.gradle'.
> startup failed:
build file 'C:\Users\Admin\AndroidStudioProjects\RealmNotes\app\build.gradle': 3: only buildscript {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed


This is also wrong:
plugins {
    id 'com.android.application', 'realm-android'
}
...
An error is thrown:
Build file 'C:\Users\Admin\AndroidStudioProjects\RealmNotes\app\build.gradle' line: 2

Could not compile build file 'C:\Users\Admin\AndroidStudioProjects\RealmNotes\app\build.gradle'.
> startup failed:
build file 'C:\Users\Admin\AndroidStudioProjects\RealmNotes\app\build.gradle': 2: argument list must be exactly 1 literal String or String with property replacement


I solved the problem by writing everything in a different format:
/*
plugins {
    id 'com.android.application'
}
*/
apply plugin: 'com.android.application'
apply plugin: 'realm-android'

...


Question: how to register several plugins in the format offered by the Studio (in the plugins {...} section)?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question