2017-09-25 28 views
0

我正在使用Firebase实时数据库构建应用程序。当我在模拟器上运行应用程序时,它工作正常。但是当我在手机上运行应用程序时,它不起作用。我更新了手机上的Google Play服务。但是,没有什么工作......Firebase实时数据库无法在真实Android设备上工作


构建应用程序:模块

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> 

MainActivity

​​

我从android studio取得SHA1密钥,包名称并粘贴到Firebase控制台。 也改变firabase数据库规则

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

你是什么意思,它不工作?你有错误吗? –

+0

数据库未更新。应用程序不会崩溃 – Gpear

+0

尝试使用回调调用setValue。有错误论据,请看一下。 –

回答

相关问题