Help, I can't even install the Java SDK into my new Android Studio project

How am I currently supposed to set up my new Android Studio 2021.1.1 project to use Realm? The install page is useless. Let me show you what I mean.

I am apparently supposed to do this:

But my project-level build.gradle script, as created by the new project wizard, looks like this:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.1.2' apply false
    id 'com.android.library' version '7.1.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}

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

Where am I supposed to put these things?

Also, the instructions for the application-level build-gradle file are out of date. For example, instead of apply plugin: I seem to now be supposed to add id ... to the plugins block…? And the syntax now seems to be viewBinding true instead of viewBinding = true.

It would be nice if the documentation actually told me correctly what to do… :frowning:

G’Day @polymath74,

Thank you for raising your concerns, they are absolutely correct.

The Android Studio has now changed the format for adding plugins.

  1. The classpath for Java SDK, will be added to the project-level build.gradle file
  2. The plugins in the app level build.gradle file, I tested with this format and this works
plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id  'realm-android'
}

I have tested this on Android Studio Arctic Fox 2020.3.1 Patch 4.

In the Android Bumblebee version, you can add dependencies as below in the project-level build.gradle file

buildscript {

    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "io.realm:realm-gradle-plugin:10.10.1"
    }
}

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

I hope the provided information helps. Please let us know if you have any further questions.

I look forward to your response.

Cheers, :performing_arts:

1 Like

Thanks for the reply, and sorry for the delay on my side - I’m finally getting time to come back to this.

In the meantime, the Kotlin SDK beta is supposedly ready for use, so I thought I would try that instead - but also ran into problems there.

I can add the packages to the gradle files as per the install instructions, and this actually worked! But when I paste in my object models from the Realm UI, I get errors:

image

Ok, I have finally worked out how to get the (older) Java SDK working with Kotlin on Android Studio Bumblebee 2021.1.1 Patch 3, so I’m going to post it here for anyone else playing along at home (and for my own future reference :wink: ).

In the project-level build.gradle file, I put the gradle plugin classpath line at the top, but I had to embed it in a buildscript section:

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

buildscript {
    dependencies {
        classpath "io.realm:realm-gradle-plugin:10.10.1"
    }
}

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

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

And in the app-level build.gradle file, I added the kotlin-kapt and realm-android plugins, using the new syntax:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-kapt'
    id 'realm-android'
}

android { ...

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.