应用程序onCreate没有被调用生产版本

时间:2017-10-31 13:00:08

标签: android kotlin android-gradle-3.0

自从我升级到gradle 3.0后,我们的主Application onCreate并未从制作风格的应用程序中解雇。然而,在构建我们的暂存风格时,应用程序的onCreate被称为正常。

由于永远不会调用应用程序的onCreate,我们的Realm永远不会被初始化,并且在以后尝试访问Realm时应用程序会崩溃。

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"

...

不确定我们对gradle 3.0的更改是否是罪魁祸首,但在升级之前一切正常。

2 个答案:

答案 0 :(得分:1)

我必须重新启动计算机才能解决此问题。我试图禁用即时运行,清理,重建。重启Android Studio。使用了应用程序名称中的完整路径。完全重启我的Macbook后结束工作。

答案 1 :(得分:1)

在备份过程中,由于未记录的行为,未调用Application onCreate的原因。您可能会找到更多信息Why backup related process might cause Application's onCreate is not executed?

我创建了一个问题https://issuetracker.google.com/issues/138423608。如果您想以更高的优先级解决此问题,请加注星标。

相关问题