Я запустил новый проект во флаттере и применял к нему Fire Store.
При выполнении шагов по добавлению моего приложения в базу Fire он начал выдавать ошибку.
ошибка, обнаруженная в журнале cat, когда запущено приложение, было
04-04 14:54:56.061 24084-24084/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.firestoreflutterchat, PID: 24084
java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.example.firestoreflutterchat-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.firestoreflutterchat-2, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:4869)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4461)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4401)
at android.app.ActivityThread.access$1500(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5097)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.example.firestoreflutterchat-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.firestoreflutterchat-2, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.ActivityThread.installProvider(ActivityThread.java:4854)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4461)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4401)
at android.app.ActivityThread.access$1500(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5097)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method
Приложение, которое я запускаю на устройстве с версией kit kat Xt1030
, чтобы удалить эту ошибку, я сделал некоторые вещи в gradle и в основном описывал другие был multidex
, так что это мои файлы gradle:
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
mavenCentral()
// maven { url 'https://github.com/yongjhih/android-gradle-plugin.m2/raw/master/' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// Add this line
// classpath 'com.google.gms:google-services:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'
//com.google.android.gms to 11.4.2.
}
}
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
}
и приложение gradle:
def localProperties = new Properties()
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 FileNotFoundException("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: 'kotlin-android'
// Add this line
apply plugin: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
// compileOptions {
// sourceCompatibility JavaVersion.VERSION
// targetCompatibility JavaVersion.VERSION 8
// }
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.firestoreflutterchat"
minSdkVersion 18
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
// testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// ndk {
// abiFilters 'armeabi-v7a'
// }
multiDexEnabled true
// productFlavors {
// dev {
// // Enable pre-dexing to produce an APK that can be tested on
// // Android 5.0+ without the time-consuming DEX build processes.
// minSdkVersion 21
// flavorDimensions "versionCode"
// }
// prod {
// // The actual minSdkVersion for the production version.
// minSdkVersion 18
// flavorDimensions "versionCode"
// }
// }
}
buildTypes {
release {
multiDexKeepFile file('multidex-config.txt')
// 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
}
}
}
flutter {
source '../..'
}
dependencies {
// add the Firebase SDK for Google Analytics
implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation 'androidx.multidex:multidex:2.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
И в файле манифеста было сказано изменить имя:
android:name="io.flutter.app.FlutterApplication"
до
android:name="androidx.multidex.MultiDexApplication"
или по другому способу сделать это
Добавить класс, расширяющий приложение флаттера
, которое при выполнении
package com.example.firestoreflutterchat
import android.content.Context
import androidx.multidex.MultiDex
import io.flutter.app.FlutterApplication
class App : FlutterApplication() {
override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
MultiDex.install(this)
}
}
, а затем изменив манифест Android с
android:name="io.flutter.app.FlutterApplication"
на
android:name=".App"
Теперь, после выполнения всех этих действий, мое приложение cra sh, но с другой ошибкой
04-05 18:22:18.266 10645-10645/com.example.firestoreflutterchat E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.firestoreflutterchat, PID: 10645
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.firestoreflutterchat/com.example.firestoreflutterchat.MainActivity}: java.lang.ClassCastException: com.example.firestoreflutterchat.MainActivity cannot be cast to android.app.Activity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2124)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5097)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: com.example.firestoreflutterchat.MainActivity cannot be cast to android.app.Activity
at android.app.Instrumentation.newActivity(Instrumentation.java:1084)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2115)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5097)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)