微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Flutter 应用程序未在清单中找到应用程序 问题原因请求日志和输出

如何解决Flutter 应用程序未在清单中找到应用程序 问题原因请求日志和输出

我已尝试将 Firebase Messaging 添加到我的 Flutter 应用程序,根据 this 教程,我应该向清单文件添加自定义应用程序名称

问题

应用程序无法启动,因为 Flutter 找不到我的自定义应用程序文件

原因

我尝试将 FlutterFire / Firebase Cloud Messaging 与 Flutter 集成

请求

我只关心在 Flutter 应用程序上接收推送通知前台 + 后台),如果这不是正确的方法,请告诉我如何为 Android 设备启用此功能

日志和输出

我的清单是

    package="com.blabla.blabla">
         <!-- Default is android:name="io.Flutter.app.FlutterApplication" -->
         <!-- FOR PUSH NOIFICATION IN BACKGROUND android:name=".Application" -->
    <application
        android:name=".Application"
        android:label="BlaBla"
        android:icon="@mipmap/launcher_icon">
        <activity
            android:name=".MainActivity"
            android:launchMode="singletop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
              <!-- this is the push notification intent -->
              <intent-filter>
              <action android:name="FlutteR_NOTIFICATION_CLICK" />
              <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <Meta-data
              android:name="io.Flutter.embedding.android.normalTheme"
              android:resource="@style/normalTheme"
              />

应用程序文件与Manifest (app->src->main) 位于同一文件


import io.Flutter.app.FlutterApplication
import io.Flutter.plugin.common.PluginRegistry
import io.Flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.Flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService


class Application : FlutterApplication(),PluginRegistrantCallback {
    override fun onCreate() {
        super.onCreate()
        FlutterFirebaseMessagingService.setPluginRegistrant(this)
    }

    override fun registerWith(registry: PluginRegistry?) {
        io.Flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(
                registry?.registrarFor(
                        "io.Flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
    }
}

而我的具体(app->build.gradle)如下

def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def FlutterRoot = localProperties.getProperty('Flutter.sdk')
if (FlutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with Flutter.sdk in the local.properties file.")
}

def FlutterVersionCode = localProperties.getProperty('Flutter.versionCode')
if (FlutterVersionCode == null) {
    FlutterVersionCode = '1'
}

def FlutterVersionName = localProperties.getProperty('Flutter.versionName')
if (FlutterVersionName == null) {
    FlutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'  // Google Services plugin
apply plugin: 'kotlin-android'
apply from: "$FlutterRoot/packages/Flutter_tools/gradle/Flutter.gradle"

android {
    compileSdkVersion 30

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        applicationId "com.bla.bla"
        minSdkVersion 21
        targetSdkVersion 30
        // multiDexEnabled true
        versionCode FlutterVersionCode.toInteger()
        versionName FlutterVersionName
    }

    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
        }
    }

       splits {

    // Configures multiple APKs based on ABI.
    abi {

      // Enables building multiple APKs per ABI.
      enable true

      // By default all ABIs are included,so use reset() and include to specify that we only
      // want APKs for x86 and x86_64.

      // Resets the list of ABIs that Gradle should create APKs for to none.
      reset()

      // Specifies a list of ABIs that Gradle should create APKs for.
      include "x86","x86_64","armeabi","armeabi-v7a","arm64-v8a"

      // Specifies that we do not want to also generate a universal APK that includes all ABIs.
      universalApk true
    }
  }
}

Flutter {
    source '../..'
}

dependencies {
    // implementation "androidx.multidex:multidex:2.0.1"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    // Import the BoM for the Firebase platform
    implementation platform('com.google.firebase:firebase-bom:26.6.0')

    // Declare the dependencies for the Firebase Cloud Messaging and Analytics libraries
    // When using the BoM,you don't specify versions in Firebase library dependencies
    implementation 'com.google.firebase:firebase-messaging-ktx:21.0.1'
    // implementation 'com.google.firebase:firebase-analytics-ktx'
}

这是一般的build.gradle

    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.5'  // Google Services plugin
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是每次启动的控制台输出

E/AndroidRuntime(31070): java.lang.RuntimeException: Unable to instantiate application com.bla.bla.Application: java.lang.classNotFoundException: Didn't find class "com.bla.bla.Application" on path: DexPathList[[zip file "/data/app/com.bla.bla-bPPOfcyKzIbhjyMWE3Q9NQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.bla.bla-bPPOfcyKzIbhjyMWE3Q9NQ==/lib/arm64,/data/app/com.bla.bla-bPPOfcyKzIbhjyMWE3Q9NQ==/base.apk!/lib/arm64-v8a,/system/lib64,/system/product/lib64]]
E/AndroidRuntime(31070):        at android.app.LoadedApk.makeApplication(LoadedApk.java:1231)
E/AndroidRuntime(31070):        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6431)
E/AndroidRuntime(31070):        at android.app.ActivityThread.access$1300(ActivityThread.java:219)
E/AndroidRuntime(31070):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
E/AndroidRuntime(31070):        at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(31070):        at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime(31070):        at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime(31070):        at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(31070):        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
E/AndroidRuntime(31070):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

我不知道还能做什么!!我花了无数个小时试图解决它,如果有人知道如何解决这个问题,我将不胜感激!!

目前在 Google Pixel 2 Android 10 设备上运行。

解决方法

我的错,

我不小心把 Application.kt 文件放在 android > app 文件夹而不是 android > app > src > {{ 1}}。

一旦我将自定义 your-package-name 移到 Application.kt 旁边,一切似乎都运行良好!

,

尝试将您的 git-checkout 文件修改为如下所示。这是有效的。 这仅适用于 AndroidManifest.xml 标签。并在 <activity </activity> 中将您的 minSdkVersion 设置为 21 以克服可能的 android/app/build.gradle

multidex errors

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。