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 完成;
参考: