3

Ever since I upgraded to gradle 3.0 our main Application's onCreate is not firing from a production-flavour app. When building for our staging flavour however, the Application's onCreate is called just fine.

Since the Application's onCreate is never called, our Realm is never initialized, and the app crashes when trying to access Realm later.

AndroidManifest.xml:

 <application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
....

App.kt:

class App : Application() {

    override fun onCreate() {
        super.onCreate()
        Realm.init(this)
        println("This is never called")
    }
}

build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'realm-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.github.triplet.play'

....

android {

    flavorDimensions "testing"

    productFlavors {
        production {
            dimension "testing"
            applicationId "com.imerso.app"
        }
        staging {
            dimension "testing"
            applicationId "com.imerso.app.staging"
            externalNativeBuild {
              cmake {
                targets 'cpp_scan_app', 'unittests'
              }
            }
        }
    }

    compileSdkVersion 25
    buildToolsVersion '26.0.2'

    dexOptions {
      // Sets the maximum number of DEX processes
      // that can be started concurrently.
      maxProcessCount 8
      // Sets the maximum memory allocation pool size
      // for the dex operation.
      javaMaxHeapSize "2g"

....

not sure if our change to gradle 3.0 is the culprit here, but everything worked fine until I did the upgrade.

simen-andresen
  • 2,217
  • 4
  • 25
  • 39

2 Answers2

2

The reason Application onCreate is not being called, is due to the undocumented behavior, during backup process. You may find more information Why backup related process might cause Application's onCreate is not executed?

I have created an issue https://issuetracker.google.com/issues/138423608 . Please kindly star the issue if you would like this issue to be resolved with higher priority.

Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
1

I had to restart my computer to overcome this issue. I tried to disable instant run, clean, rebuild. Restarted Android Studio. used the full path in the Application name. Ended up working after a full restart of my Macbook.

J. Roth
  • 41
  • 4