Nativescript 6.1.1 应用程序在 --release 模式下崩溃,在调试中工作

Nativescript 6.1.1 Application crashes in --release mode, works in debug

我有一个 Nativescript Vue 应用程序,它将不再 运行 处于发布模式。

我最近将应用程序从 5.3.0 迁移到 6.1.1,一切似乎都很好。我做了几次更新,包括添加 nativescript-admobnativescript-purchase 以及相应的功能。同样,在 ios 和 android.

中调试应用程序时一切正常

我还能够在 android 的 --release 模式下成功构建并使用 iOS 存档。但是,当我转到 运行 在 android 上生成的应用程序时,它会在启动时立即崩溃。

这是包含我的 package.json 的要点,应用 ID 等已更改:https://gist.github.com/wpatter6/3575e029572eaedb03e723d5fba19e10

这是一个要点,其中包含每次应用程序尝试启动时都会抛出的 logcat 堆栈跟踪: https://gist.github.com/wpatter6/3ec8def984e5e0ef532653c149020804

这是我正在 运行 构建的脚本:

rm -rf platforms/android
rm -rf node_modules

npm i

tns build android --env.snapshot --env.sourceMap --bundle --clean --release --key-store-*

我不知道如何继续解决此问题或此堆栈跟踪可能指向的内容。

如果有人对如何从日志中获取更多信息或可能出现的问题有任何建议,我将不胜感激。提前致谢!

编辑:

我尝试使用 --env.snapshot 标志构建它,现在抛出一个错误 The file ./app.css couldn't be loaded! You may need to register it inside ./app/vendor.ts。这个项目使用了scss,也许那里有什么问题?奇怪的是,这只是发布模式下的问题,样式在调试中效果很好...

所以我在这里缩小了问题范围。我在 minification/obfuscation 中详细说明了 Android here

这是我 app.gradle 中的片段的当前版本 明显导致问题的 buildTypes 属性 被注释掉了:

android {
  defaultConfig {
    minSdkVersion 21
    generatedDensities = []
    applicationId = "com.willweb.clicker"
  }
  aaptOptions {  
    additionalParameters "--no-version-vectors"  
  }  
  /* buildTypes { // THIS CAUSES RELEASE MODE ERROR ON APP LAUNCH
    release {
      // Enables code shrinking, obfuscation, and optimization for only
      // your project's release build type.
      minifyEnabled true

      // Enables resource shrinking, which is performed by the
      // Android Gradle plugin.
      shrinkResources true

      // Includes the default ProGuard rules files that are packaged with
      // the Android Gradle plugin. To learn more, go to the section about
      // R8 configuration files.
      proguardFiles getDefaultProguardFile(
        'proguard-android-optimize.txt'),
        'proguard-rules.pro'
    }
  } */
}

幸运的是,删除它确实允许我在发布模式下构建和 运行 应用程序,但不幸的是文件大小要大得多。

存在 this question 几年前关于 proguard 的内容,但没有更新。

根据他们在 github 中的团队的说法,NativeScript 提供了优化应用程序大小和代码的工具,例如 Uglifing、AOT(针对 Angular)、快照(仅针对发布 Android 构建MAC) 和 Webpack(默认启用)。此构建的一个示例是:

tns run android --env.uglify --env.aot --env.snapshot --releae <release-params-follows-here>