iOS:
由於工程中需要用到 OC 與 C/C++ 混編,代碼中不能使用 @import 引入,即便在 build setting 中打開 enable modules 仍然不能支持,本想編寫一個純 OC 文件(.m結尾)用來放 Firebase 相關代碼,但測試後還是沒有成功,無奈對 iOS 開發太不熟悉。
改用手動集成:
1、從下方參考鏈接網頁中下載 Firebase iOS SDK;
1、到 Firebase console 創建應用,注意 Bundle ID 要與項目中一致,下載 GoogleService-Info.plist 文件並添加進工程根目錄;
4、將 Firebase.h 頭文件引入到項目中,添加代碼:
#import "Firebase.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//……
[FIRApp configure];
//……
}
參考:
Add Firebase to your iOS Project
Android:
使用 Android Studio 會比較方便。
1、使用 Tools -> Android -> SDK Manager -> SDK Tools,將 Android SDK Build-Tools, Google Play Service, Google Respository 更新到最新;
2、到 Firebase Console 創建應用,注意 Package Name 要與項目中一致,下載 google-services.json 文件,拷貝到 {PROJECT_DIR}/app/ 目錄下;
3、修改 build.gradle(root level)
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.0.0'
}
}
4、修改 build.gradle(module)
apply plugin: 'com.android.application'
android {
// ...
}
dependencies {
// ...
compile 'com.google.firebase:firebase-core:10.2.0'
// Getting a "Could not find" error? Make sure you have
// the latest Google Repository in the Android SDK manager
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
5、修改後 Sync 完成;
參考: