#exception #dart #flutter
#исключение #dart #flutter
Вопрос:
Итак, я использую плагин firebase и сделал все, что сказал Google, чтобы подключить его к firebase, но если я пытаюсь что-то добавить (создать), это прерывает работу приложения.
Это моя настройка firebase:
Я загрузил Google-сервисы.json из firebase добавлен в application / build.grandle:
dependencies {
classpath 'com.google.gms:google-services:4.2.0'
classpath 'com.android.tools.build:gradle:3.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
мой файл grundle в приложении / app/build.grundle
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 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: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
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.comp.appname"
minSdkVersion 21
targetSdkVersion 27
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
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
}
}
}
flutter {
source '../..'
}
dependencies {
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-firestore:18.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'
это сборка с ошибкой
Launching libmain.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Built buildappoutputsapkdebugapp-debug.apk.
Syncing files to device Android SDK built for x86...
D/ ( 7903): HostConnection::get() New Host Connection established 0xe4dd3840, tid 7928
D/EGL_emulation( 7903): eglMakeCurrent: 0xe4dc10c0: ver 3 1 (tinfo 0xe53dc010)
D/skia ( 7903): Program linking failed.
I/chatty ( 7903): uid=10087(com.comp.appname) 1.gpu identical 9 lines
D/skia ( 7903): Program linking failed.
D/skia ( 7903): Program linking failed.
D/skia ( 7903): Program linking failed.
I/chatty ( 7903): uid=10087(com.comp.appname) 1.gpu identical 2 lines
D/skia ( 7903): Program linking failed.
W/DynamiteModule( 7903): Local module descriptor class for providerinstaller not found.
I/DynamiteModule( 7903): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller( 7903): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
I/presentationap( 7903): The ClassLoaderContext is a special shared library.
I/chatty ( 7903): uid=10087(com.comp.appname) FirestoreWorker identical 2 lines
I/presentationap( 7903): The ClassLoaderContext is a special shared library.
W/presentationap( 7903): Accessing hidden field Ldalvik/system/BaseDexClassLoader;->pathList:Ldalvik/system/DexPathList; (light greylist, reflection)
W/presentationap( 7903): Accessing hidden field Ldalvik/system/DexPathList;->nativeLibraryDirectories:Ljava/util/List; (light greylist, reflection)
W/presentationap( 7903): Accessing hidden field Ldalvik/system/DexPathList;->systemNativeLibraryDirectories:Ljava/util/List; (light greylist, reflection)
W/presentationap( 7903): Accessing hidden field Ldalvik/system/DexPathList;->nativeLibraryPathElements:[Ldalvik/system/DexPathList$NativeLibraryElement; (light greylist, reflection)
W/presentationap( 7903): Accessing hidden method Ldalvik/system/DexPathList;->makePathElements(Ljava/util/List;)[Ldalvik/system/DexPathList$NativeLibraryElement; (light greylist, reflection)
V/NativeCrypto( 7903): Registering com/google/android/gms/org/conscrypt/NativeCrypto's 284 native methods...
W/presentationap( 7903): Accessing hidden method Ljava/security/spec/ECParameterSpec;->getCurveName()Ljava/lang/String; (light greylist, reflection)
D/NetworkSecurityConfig( 7903): No Network Security Config specified, using platform default
W/presentationap( 7903): Accessing hidden field Ljavax/net/ssl/SSLSocketFactory;->defaultSocketFactory:Ljavax/net/ssl/SSLSocketFactory; (light greylist, reflection)
W/presentationap( 7903): Accessing hidden field Ljavax/net/ssl/SSLServerSocketFactory;->defaultServerSocketFactory:Ljavax/net/ssl/SSLServerSocketFactory; (light greylist, reflection)
I/ProviderInstaller( 7903): Installed default security provider GmsCore_OpenSSL
E/AndroidRuntime( 7903): FATAL EXCEPTION: AsyncTask #2
E/AndroidRuntime( 7903): Process: com.comp.appname, PID: 7903
E/AndroidRuntime( 7903): java.lang.RuntimeException: An error occurred while executing doInBackground()
E/AndroidRuntime( 7903): at android.os.AsyncTask$3.done(AsyncTask.java:354)
E/AndroidRuntime( 7903): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
E/AndroidRuntime( 7903): at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
E/AndroidRuntime( 7903): at java.util.concurrent.FutureTask.run(FutureTask.java:271)
E/AndroidRuntime( 7903): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
E/AndroidRuntime( 7903): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime( 7903): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime( 7903): at java.lang.Thread.run(Thread.java:764)
E/AndroidRuntime( 7903): Caused by: java.lang.NoSuchMethodError: No virtual method set(Lcom/google/firebase/firestore/DocumentReference;Ljava/util/Map;)Lcom/google/firebase/firestore/Transaction; in class Lcom/google/firebase/firestore/Transaction; or its super classes (declaration of 'com.google.firebase.firestore.Transaction' appears in /data/app/com.comp.appname-GbnYcinQxOfE2R1J20iZcg==/base.apk!classes9.dex)
E/AndroidRuntime( 7903): at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$6.doInBackground(CloudFirestorePlugin.java:379)
E/AndroidRuntime( 7903): at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$6.doInBackground(CloudFirestorePlugin.java:374)
E/AndroidRuntime( 7903): at android.os.AsyncTask$2.call(AsyncTask.java:333)
E/AndroidRuntime( 7903): at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/AndroidRuntime( 7903): ... 4 more
I/Process ( 7903): Sending signal. PID: 7903 SIG: 9
Application finished.
Вероятно, стоит упомянуть, что я использую прокси, но он настроен правильно и работает с другим приложением
Комментарии:
1. Я также пробовал с targetSdkVersion 28
2. Изменили ли вы правила безопасности базы данных как общедоступной?
3. @TirthPatel как я могу это проверить?
4. Перейдите в консоль Firebase > База данных > Правила
5. @key, вы можете показать нам код, в котором вы выполняете вызов firebase?
Ответ №1:
Исправлено,
Мне пришлось понизить версию build gradle следующим образом: в myapp/ build.gradle
dependencies {
classpath 'com.google.gms:google-services:4.2.0'
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
и удалил все ненужное из myapp / app / build.gradle
dependencies {
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
Я также удалил все неиспользуемые зависимости, такие как image_picker и firebase_ml_vision
Комментарии:
1. Вы не можете удалить,
apply plugin: 'com.google.gms.google-services'
иначе firebase не сможет найти вашу базу данных с помощью вашегоgoogle-services.json
файла