Dart / flutter:启动时应用程序崩溃

时间:2018-05-11 17:42:17

标签: dart flutter

我有这个非常有趣的问题,我可以在模拟器上运行我的应用程序,flutter build apk成功,我可以在Google Play上发布新版本或只安装apk我的手机(Pixel 2 XL,目前是四月安全补丁)。

但是当我在手机上启动时,它会立即崩溃。我还没有尝试安装debug apk,首先我要应用May补丁。

我已经尝试过几次升级颤振,但似乎也没有任何问题:

C:\Android\osszefogasaszanhuzokert>flutter upgrade
Upgrading Flutter from c:\Android\flutter...
From https://github.com/flutter/flutter
   3d3673a34..23098dde5  master     -> origin/master
Already up to date.

Upgrading engine...
Already up-to-date.

Flutter 0.3.6-pre.81 • channel beta • https://github.com/flutter/flutter.git
Framework • revision 2849bc04ff (10 days ago) • 2018-05-01 20:07:45 -0700
Engine • revision d5c1117170
Tools • Dart 2.0.0-dev.52.0.flutter-011676641a

Running "flutter packages upgrade" in osszefogasaszanhuzokert... 14.4s

Running flutter doctor...
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.3.6-pre.81, on Microsoft Windows [Version 10.0.15063], locale en-GB)
[√] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[√] Android Studio (version 3.1)
[√] Connected devices (1 available)

• No issues found!

我最近换了笔记本电脑并检查了我的代码的git存储库。有一些问题,但我最终解决了这些问题。唯一的区别是项目名称现在只是osszefogasaszanhuzokert,而包名称是osszefogasaszanhuzokert2 - 但我不认为这会导致任何问题。

我的猜测是问题会出现在AndroidManifest.xml

的某个地方
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.zgyorkei.osszefogasaszanhuzokert2">

    <!-- The INTERNET permission is required for development. Specifically,
         flutter needs it to communicate with the running application
         to allow setting breakpoints, to provide hot reload, etc.
    -->
    <uses-permission android:name="android.permission.INTERNET"/>

    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="Összefogás A Szánhúzókért"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name="com.zgyorkei.osszefogasaszanhuzokert2.MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

Android工作室标记了几个不允许的属性,但正如您所看到的那样,我几乎将所有内容都保留为默认值 - 除了因为显而易见的原因我更改了android:label

编辑:我安装了调试apk,运行完美。但是,我能够获得发布apk崩溃的adb logcat,问题似乎如下:

05-12 07:38:23.341 29595 29595 I crash_dump32: performing dump of process 29560 (target tid = 29560)
05-12 07:38:23.341 29595 29595 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
05-12 07:38:23.341 29595 29595 F DEBUG   : Build fingerprint: 'google/taimen/taimen:8.1.0/OPM2.171019.029.B1/4720900:user/release-keys'
05-12 07:38:23.341 29595 29595 F DEBUG   : Revision: 'rev_10'
05-12 07:38:23.341 29595 29595 F DEBUG   : ABI: 'arm'
05-12 07:38:23.341 29595 29595 F DEBUG   : pid: 29560, tid: 29560, name: saszanhuzokert2  >>> com.zgyorkei.osszefogasaszanhuzokert2 <<<
05-12 07:38:23.342 29595 29595 F DEBUG   : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
05-12 07:38:23.343 29595 29595 F DEBUG   : Abort message: '[FATAL:flutter/runtime/dart_vm.cc(409)] Error while initializing the Dart VM: Snapshot not compatible with the current VM configuration: the snapshot requires 'product no-type_checks no-asserts no-error_on_bad_type no-error_on_bad_override arm-eabi hardfp' but the VM has 'product no-type_checks no-asserts no-error_on_bad_type no-error_on_bad_override arm-eabi softfp'

如何更改Dart VM以使用hardfp代替softfp

21 个答案:

答案 0 :(得分:9)

我有同样的问题。对我来说,这是在我重命名应用程序并更改了程序包名称之后发生的。我没有针对Android正确执行此操作。

关注this guide of how to change the package name之后,对于Android来说一切正常。

确保AndroidManifest.xmlandroid/app/build.gradleandroid/app/src/.../MainActivity.java中的程序包名称相同。

答案 1 :(得分:8)

这不是此问题的直接答案,但我遇到了类似的问题,并在此处结束。其他人也可以来。

我的问题:应用在模拟器上首次启动时会崩溃

我的解决方案:通过运行flutter clean

清除缓存

答案 2 :(得分:4)

我遇到了同样的问题,这里没有任何选择可以帮助我。最终,我发现了logcat并意识到我的应用由于Crashlytics软件包而崩溃了。

简而言之,我在终端中运行以下命令以显示设备中的日志,这不仅帮助我找到了罪魁祸首,而且还帮助我解决了问题。您可以使其在后台运行。

adb logcat

您可能必须在下面的路径中添加path环境变量。或者只是cd

C:\Users\[USERNAME]\AppData\Local\Android\sdk\platform-tools

请参见下面的输出。我确信如果由于某种原因再次发生这种情况,我应该能够弄清楚原因,而不是推测是什么原因造成的。

enter image description here

答案 3 :(得分:3)

就我而言,我只需要运行flutter build apk --release --no-shrink

答案 4 :(得分:2)

对我来说是因为我使用了admob,却忘记了将APPLICATION_ID添加到AndroidManifest.xml

<meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="app-id"/>

答案 5 :(得分:2)

某些具有不同架构的手机也存在相同的问题。当我打开应用程序时,它开始崩溃。这是一个对我有用的修复程序:

defaultConfig {
    ...
    multiDexEnabled true
    ndk {
        abiFilters 'x86', 'armeabi-v7a'
    }
}

必须在ndk文件中添加android/app/build.gradle,它的工作原理像一个超级按钮。

我希望这可以帮助某人。

答案 6 :(得分:1)

在android studio上进行扑打时: 我遇到了同样的问题,但是最后我得出结论,当您对位于应用程序“根目录”的名为pu​​bspec.yaml的文件添加新的依赖项时,该依赖项的配置方式不正确,例如{{flutter_facebook_login:^ 1.2。 0}},因此,如果需要,请以正确的方式配置它,或者根本不使用它。 ^ _ ^ at android studio

答案 7 :(得分:1)

升级后我也遇到了同样的问题。

在我的应用中,multiDexEnabled true文件中已启用build.gradle,并且在升级之前运行良好。 我之前已经添加了它,以解决另一个崩溃问题。

查看相同内容:Flutter android app crashes upon startup if I include a certain package

答案 8 :(得分:1)

我的解决方案在所有其他解决方案上均无效:

android\build.gradle

classpath 'com.android.tools.build:gradle:3.5.0'

结合新发布的Gradle 6.6 今天发布的,请访问gradle\wrapper\gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip

为我完成了工作,希望对您有所帮助!祝你好运。

答案 9 :(得分:1)

这是解决方案:

在build.gradle文件中,如下所示:

buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
     //       signingConfig signingConfigs.debug
            // colocado isso para release
            signingConfig signingConfigs.release

            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

只需将minifyEnabled更改为false,然后再次运行flutter build。

答案 10 :(得分:1)

经过一天的努力,我没有尝试任何建议,因为我已经尝试了所有方法。其中:

  • 干净整洁
  • 颤振升级
  • 检查包中的包和清单是否相同
  • multiDexEnable true
  • 和其他解决方案...

对于我来说,升级抖动时的解决方案是:

  classpath 'com.android.tools.build:gradle:3.3.1'

  classpath 'com.android.tools.build:gradle:3.3.2'

是的,足以更新工具gradle。在没有错误的情况下编译已编译的项目,然后启动应用程序。但是,当应用启动时,它会自动关闭,而不会出现任何错误消息。所以要小心。我希望这样可以节省您数小时的压力。

答案 11 :(得分:1)

嗨,如果以上答案均无效,请尝试我的

我在终端机上使用过flutter pub upgrade,谢谢!如果我有帮助,请支持:)

答案 12 :(得分:1)

解决此错误的简单方法

更改软件包名称时会发生此错误

为了以适当的方式更改软件包名称,您必须遵循以下步骤

通过以下步骤,您可以解决此错误

步骤1:-

1。转到:---

  

project> [您的应用名称]> Android [您的应用名称]> app> src

在src文件夹中,您可以找到3个文件Debug,main和profile

分别转到每个文件 ,并更改其 AndroidManifest.xml文件

现在,您距离解决此错误还差一半。

步骤2:-

现在,转到位于

的build.gradle文件。
  

项目> [您的应用名称]> Android [您的应用名称]> app> build.gradle

在这里您可以找到此代码defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.appname" minSdkVersion 16 targetSdkVersion 29 versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" }

只需将软件包名称com.example.appname更改为您合适的软件包名称

步骤3:-

现在转到

  

项目> [您的应用名称]> Android   [your_app_name]> app> src> main> java> mainactivity

***警告******,如果您在颤抖的情况下使用Kotlin,则必须转到此处:-

  

项目> [您的应用名称]> Android   [your_app_name]> app> src> main> kotlin>主要活动

您可以在 Mainactivity.kotlin mainactivity.java

之后更改应用程序的软件包名称。

它应该可以正常运行...请对此提供反馈。

  

也不要忘记更改文件夹的名称[转到    src> main> kotlin或java> com.example.app ]

答案 13 :(得分:0)

对于那些使用Kotlin进行了重构/更改包名的人,但上述方法均无效(我的情况),请检查以下内容:确保在您的 app / src / main目录中是 app / src / main / java app / src / main / kotlin 目录中的MainActivity文件。对我来说,java文件夹中没有文件,这会导致崩溃(当然,请确保您也已完成上述所有操作)。

答案 14 :(得分:0)

此问题没有一个万能的答案,因为它有多个有效答案,并且正确的答案将完全取决于您面临的问题。

我在这里补充我的经验,希望对以后的人有所帮助。我遇到的问题是由于“ firebase_crashlytics”未正确安装。

在我的情况下,[project]/android/build.gradle[project]/android/build.gradle中的条目基本上未正确更新,这只是使应用程序崩溃,而任何日志中都没有任何详细信息。

然后,我重做了插件“自述文件”部分中的所有步骤,并且工作正常。

https://pub.dev/packages/firebase_crashlytics

我在此处未添加任何特定详细信息,因为这些详细信息将来可能会随着版本升级而更改。

基本上,当您遇到应用崩溃错误且没有任何日志可帮助您时,请确保您检查了新添加的插件并正确安装了它们。

希望这会有所帮助!

答案 15 :(得分:0)

我遇到了相同的行为(该应用程序在启动时就关闭了,没有任何错误或警告等),并使用命令解决了该问题:

flutter clean

当我有一段时间(几个月)没有在模拟器上重新启动该应用程序时,这就是我的事情。我想这与Flutter的一些更新/等有关。

答案 16 :(得分:0)

如Morad所述,未正确引用AdMob将导致您的应用在启动时崩溃,甚至可能无法提供崩溃提示。对于iOS和Android都是如此。

Android -在AndroidManifest.xml中

<meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="your-app-id"/>

iOS -在Info.plist中

    <key>GADApplicationIdentifier</key>
    <string>your-app-id</string>

按照此处的说明进行操作:https://pub.dev/packages/firebase_admob

如果您不知道自己的应用ID,则可以在https://admob.google.com上找到它 并在左侧单击“应用程序”,然后单击“查看所有应用程序”(只要您已经设置了广告)。

答案 17 :(得分:0)

就我而言,问题是我使用的Android Studio版本为3.6.1,而gradle-wrapper.properties发行版本为6.0.0-all。为了解决这个问题,我将其更改为4.10.1-all。

答案 18 :(得分:0)

打开android studio,从gradle中获取SHA密钥,并在Google控制台中更新密钥,在您的项目中上传Google JSON列表,确保您的SHA密钥应该是唯一的,请使用以下命令获取文件夹:

Google SHA

@{
    await Html.RenderPartialAsync("SupportDeck", new SupportDeck
    {
        Deck = Model.FriendSupport.normalDeck,
        Type = DeckType.Normal,
        GameData = Model.GameData,
        AssetList = Model.AssetList
    });
}

答案 19 :(得分:0)

它崩溃的原因是由于启动时使用了第三方库。 要检查是哪个库导致崩溃,请转到Android Studio上的[ { "id": 1, "name": "MICRO", "email": "maximillia94@example.net", "email_verified_at": "2019-09-29 17:49:36", "created_at": "2019-09-29 17:49:36", "updated_at": "2019-09-29 17:49:36" }, { "id": 2, "name": "SEDAN", "email": "ziemann.bill@example.com", "email_verified_at": "2019-09-29 17:49:36", "created_at": "2019-09-29 17:49:36", "updated_at": "2019-09-29 17:49:36" }, { "id": 3, "name": "CUV", "email": "don90@example.org", "email_verified_at": "2019-09-29 17:49:36", "created_at": "2019-09-29 17:49:36", "updated_at": "2019-09-29 17:49:36" }, { "id": 4, "name": "SUV", "email": "dkoepp@example.net", "email_verified_at": "2019-09-29 17:49:36", "created_at": "2019-09-29 17:49:36", "updated_at": "2019-09-29 17:49:36" }, { "id": 5, "name": "MINIVAN", "email": "laney.schaden@example.com", "email_verified_at": "2019-09-29 17:49:36", "created_at": "2019-09-29 17:49:36", "updated_at": "2019-09-29 17:49:36" }, { "id": 6, "name": "HATCHBACK", "email": "herman.addison@example.net", "email_verified_at": "2019-09-29 17:49:36", "created_at": "2019-09-29 17:49:36", "updated_at": "2019-09-29 17:49:36" }, { "id": 7, "name": "ROADSTER", "email": "thaddeus89@example.org", "email_verified_at": "2019-09-29 17:49:36", "created_at": "2019-09-29 17:49:36", "updated_at": "2019-09-29 17:49:36" }, { "id": 8, "name": "PICKUP", "email": "eusebio32@example.net", "email_verified_at": "2019-09-29 17:49:36", "created_at": "2019-09-29 17:49:36", "updated_at": "2019-09-29 17:49:36" }, { "id": 9, "name": "VAN", "email": "caleb77@example.net", "email_verified_at": "2019-09-29 17:49:36", "created_at": "2019-09-29 17:49:36", "updated_at": "2019-09-29 17:49:36" }, { "id": 10, "name": "COUP", "email": "foster.kiehn@example.com", "email_verified_at": "2019-09-29 17:49:36", "created_at": "2019-09-29 17:49:36", "updated_at": "2019-09-29 17:49:36" }, { "id": 11, "name": "TRUCK", "email": "ophelia62@example.net", "email_verified_at": "2019-09-29 17:49:36", "created_at": "2019-09-29 17:49:36", "updated_at": "2019-09-29 17:49:36" }, { "id": 12, "name": "BIG TRUCK", "email": "elsie41@example.com", "email_verified_at": "2019-09-29 17:49:36", "created_at": "2019-09-29 17:49:36", "updated_at": "2019-09-29 17:49:36" } ] ,使用Logcat查看日志。然后,重新启动应用程序并检查输出。对我而言,导致崩溃的是Firebase Auth库。我刚刚更新了该库以喜欢我的问题。我希望这可以帮助别人。如果没有,“保持冷静,继续阅读,最终会发现它的。”

答案 20 :(得分:0)

Android   如果您使用的是Firebase插件,请先尝试一下。我认为问题出在您使用的是哪种Flutter版本以及Firebase插件使用了什么版本

当您的应用程序及其引用的库超过65,536个方法时,您会遇到一个构建错误,表明您的应用程序已达到Android构建体系结构的限制:  设置您的应用程序项目以使用Multidex配置需要根据您的应用程序支持的最低Android版本对应用程序项目进行以下修改。

如果将minSdkVersion设置为21或更高,则只需在模块级build.gradle文件中将multiDexEnabled设置为true,如下所示:

android {
defaultConfig {
    ...
    minSdkVersion 21 
    targetSdkVersion 28
    multiDexEnabled true
}
...

但是,如果将minSdkVersion设置为20或更低,则必须使用multidex支持库,如下所示:

  1. 修改模块级别的build.gradle文件以启用multidex并将multidex库添加为依赖项,如下所示:

      android {
        defaultConfig {
            ...
            minSdkVersion 15 
            targetSdkVersion 28
            multiDexEnabled true
        }
        ...
    }
    

    依赖项{   实现'com.android.support:multidex:1.0.3'}

2。根据是否覆盖Application类,执行以下操作之一:

If you do not override the Application class, edit your manifest file to set android:name in the <application> tag as follows:


  <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <application
            android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>
</manifest>

如果您确实重写了Application类,请如下进行更改以扩展MultiDexApplication(如果可能):

java public class MyApplication extends MultiDexApplication { ... } 科特琳class MyApplication : MultiDexApplication() {...}

multidex documentation

相关问题