【问题标题】:Firebase realtime database not works on real android deviceFirebase 实时数据库不适用于真正的 android 设备
【发布时间】:2017-09-25 11:18:47
【问题描述】:

我正在使用 Firebase 实时数据库构建应用。当我在模拟器上运行该应用程序时,它运行良好。但是当我在手机上运行该应用程序时,它不起作用。我在手机上更新了 google play 服务。但是没有任何效果...


构建应用程序:模块

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.orient"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support:design:26.+'
    compile 'com.google.firebase:firebase-database:10.0.1'
    testCompile 'junit:junit:4.12'
}


apply plugin: 'com.google.gms.google-services'

构建应用程序:项目

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'

        classpath 'com.google.gms:google-services:3.1.0'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com" // Google's Maven repository
        }
    }
}

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

AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.orient">

    <uses-permission android:name="android.permission.INTERNET"/>

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".ScrollingActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

主活动

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        FirebaseDatabase database = FirebaseDatabase.getInstance();
        DatabaseReference myRef = database.getReference();
        myRef.setValue("Hello, Galaxy!");

    }

我从 android studio 获取了 SHA1 密钥、包名并粘贴到 firebase 控制台。 同时更改 firabase 数据库规则

{
  "rules": {
    ".read": true,
    ".write": true
  }
}

【问题讨论】:

  • 不起作用是什么意思?你有错误吗?
  • 数据库未更新。应用不会崩溃
  • 尝试通过回调调用 setValue。有错误参数,看看吧。
  • 无法通过快速路由加载模块com.google.android.gms.dynamite.DynamiteModule$zza: V2 版本检查失败考虑本地模块 com.google.android.gms.firebase_database:4 和远程模块 com .google.android.gms.firebase_database:6 com.google.android.gms.firebase_database 的选定远程版本,版本 >= 6 类加载器引用的未知路径:/system/priv-app/PrebuiltGmsCore/lib/arm 未指定网络安全配置, 使用平台默认值

标签: android database firebase firebase-realtime-database


【解决方案1】:

这是专门针对您遇到的相同问题的线程 - Android Firebase DynamiteModule: Failed to load module descriptor

【讨论】:

    猜你喜欢
    • 2021-06-24
    • 2018-06-02
    • 2016-10-16
    • 1970-01-01
    • 2021-03-05
    • 1970-01-01
    • 1970-01-01
    • 2023-01-15
    • 1970-01-01
    相关资源
    最近更新 更多