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