3

自从我升级到 gradle 3.0 后,我们 mainApplication的 onCreate 就没有从生产风格的应用程序中触发。然而,在为我们的 staging 风格构建时,应用程序的 onCreate 调用得很好。

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

AndroidManifest.xml:

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

应用程序.kt:

class App : Application() {

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

构建.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 的更改是否是这里的罪魁祸首,但在我进行升级之前一切正常。

4

2 回答 2

1

我不得不重新启动我的电脑来解决这个问题。我试图禁用即时运行、清理、重建。重新启动 Android Studio。在应用程序名称中使用了完整路径。在完全重新启动我的 Macbook 后结束工作。

于 2018-01-11T20:22:28.000 回答
1

未调用 Application onCreate 的原因是由于备份过程中未记录的行为。您可能会发现更多信息为什么备份相关过程可能导致应用程序的 onCreate 未执行?

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

于 2019-07-26T07:09:30.663 回答