Maven 中的 FirebaseApp
FirebaseApp in maven
我想从 maven 获取 FirebaseApp
为了做:
com.google.firebase.FirestoreOptions firestoreOptions =
FirestoreOptions.Builder()
.setDatabaseUrl("xxx")
.setCredentials(ServiceAccountCredentials.fromStream(serviceAccount))
.build();
com.google.firebase.FirebaseApp.initializeApp(firestoreOptions);
但是不知道下载哪个神器
我试过:
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.13.0</version>
</dependency>
但是建造者有 .setDatabaseId()
而不是 setDatabaseUrl()
进口是
import com.google.cloud.firestore.Firestore;
import com.google.cloud.firestore.FirestoreOptions;
而不是
import com.google.firebase.Firestore;
import com.google.firebase.FirestoreOptions;
中有很好的文档
首先你需要在pom.xml
中导入这个依赖:
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.13.0</version>
</dependency>
或者如果您使用的是 gradle:
dependencies {
implementation 'com.google.firebase:firebase-admin:6.13.0'
}
然后您的代码应该如下所示:
// Impots
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
// And code
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.getApplicationDefault())
.setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);
我想从 maven 获取 FirebaseApp
为了做:
com.google.firebase.FirestoreOptions firestoreOptions =
FirestoreOptions.Builder()
.setDatabaseUrl("xxx")
.setCredentials(ServiceAccountCredentials.fromStream(serviceAccount))
.build();
com.google.firebase.FirebaseApp.initializeApp(firestoreOptions);
但是不知道下载哪个神器
我试过:
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.13.0</version>
</dependency>
但是建造者有 .setDatabaseId()
而不是 setDatabaseUrl()
进口是
import com.google.cloud.firestore.Firestore;
import com.google.cloud.firestore.FirestoreOptions;
而不是
import com.google.firebase.Firestore;
import com.google.firebase.FirestoreOptions;
首先你需要在pom.xml
中导入这个依赖:
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.13.0</version>
</dependency>
或者如果您使用的是 gradle:
dependencies {
implementation 'com.google.firebase:firebase-admin:6.13.0'
}
然后您的代码应该如下所示:
// Impots
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
// And code
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.getApplicationDefault())
.setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);