title: Realm for Android with Kotlin - Cannot change Dependencies of Configuration after it has been included in dependency resolution
body: <p>I am trying to get Realm to work in my project. I have Kotlin with version 1.2.51 and Instant Run disabled. </p>
  
  <p>In my project <code>build.gradle</code> file I added the following dependency:</p>
  
  <pre><code>classpath "io.realm:realm-gradle-plugin:5.4.0"
  </code></pre>
  
  <p>In my App <code>build.gradle</code> file I applied the Realm plugin as explained in the tutorial:</p>
  
  <pre><code>apply plugin: 'com.android.application'
  apply plugin: 'kotlin-android'
  apply plugin: 'kotlin-android-extensions'
  apply plugin: 'kotlin-kapt'
  apply plugin: 'realm-android'
  </code></pre>
  
  <p>When I am trying to build the project, I get the following error:</p>
  
  <pre><code>org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':app'
  Caused by: org.gradle.api.InvalidUserDataException: Cannot change dependencies of configuration ':app:api' after it has been included in dependency resolution.
  </code></pre>
  
  <p>When I change the order of <code>apply plugin</code> so that realm is directly after <code>com.android.application</code> the project builds.
  The problem then is, that Realm tells me on my first insert of a RealmObject, that the object is not contained in the object scheme.</p>
  
  <p>RealmCustomer.kt</p>
  
  <pre><code>open class RealmCustomer(
      @PrimaryKey
      var id: String = "",
      var firstname: String = "",
      var lastname: String = "",
      var addresses: RealmList&lt;RealmAddress&gt; = RealmList()
  ) : RealmObject() {}
  </code></pre>
  
  <p>RealmAddress.kt</p>
  
  <pre><code>open class RealmAddress(
      var street: String = "",
      var streetNr: String = "",
      var city: String = "",
      var countryCode: String = ""
  ) : RealmObject() {}
  </code></pre>
  
  <p>As far as I can see, there should not be a problem with it.
  In my Applications onCreate I call the following code:</p>
  
  <pre><code>Realm.init(this)
  RealmConfiguration.Builder().name("my.realm").build().apply { Realm.setDefaultConfiguration(this) }
  </code></pre>
  
  <p>At some point later, I retrieve my Realm like this:</p>
  
  <pre><code>private val realm: Realm by lazy { Realm.getDefaultInstance() }
  
  fun save(items: List&lt;...&gt;) {
      realm.executeTransaction {
          items.map {
  
              val addressList = it.addresses?.map {
                  realm.createObject(RealmAddress::class.java).apply {
                      street = it.street
                      streetNr = it.streetNr
                      city = it.city
                      countryCode = it.countryCode
                  }
              }
  
              val cx = realm.createObject(RealmCustomer::class.java, it.id).apply {
                  firstname = it.firstname
                  lastname = it.lastname
              }
  
              addressList?.forEach { cx.addresses.add(it) }
          }
      }
  }
  </code></pre>
  
  <p>This code with <code>apply plugin: 'realm-android'</code> in the second place crashed with the Schema error: <code>RealmException: RealmAddress is not part of the schema for this Realm</code></p>
  
  <p>Thank you in advance.</p>