使用 react-native-firebase 编译 react-native
Compile react-native with react-native-firebase
在我继续之前,请注意,我已经求助于 Whosebug 作为我最后的希望,并且我花了数小时搜索 GitHub 和过去的 "related" 问题。
在一个简单的上下文中,我试图在我的 react-native 应用程序中使用 react-native-firebase,目标是 android 平台。
下面的代码完全按照 react-native-firebase
给出的步骤进行
app\build.gradle
...
dependencies {
compile(project(':react-native-firebase')) {
transitive = false
}
compile project(':react-native-config')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile "com.google.android.gms:play-services-base:11.6.0"
compile "com.google.firebase:firebase-core:11.6.0"
}
...
apply plugin: 'com.google.gms.google-services'
android\build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
url 'https://maven.google.com'
}
}
}
android\app\src\main\java\com\HF\MainApplication.java
...
import io.invertase.firebase.RNFirebasePackage;
import io.invertase.firebase.database.RNFirebaseDatabasePackage;
...
@Override
protected List < ReactPackage > getPackages() {
return Arrays. < ReactPackage > asList(
new MainReactPackage(),
new RNFirebasePackage(),
new ReactNativeConfigPackage(),
new RNFirebaseDatabasePackage()
);
}
...
然而,最后,它并没有 运行,给我一个奇怪的错误。我已尽我所能,但无济于事。任何帮助将不胜感激。
谢谢
如果您对错误感到好奇
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:incrementalDebugJavaCompilationSafeguard
:app:compileDebugJavaWithJavac
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:transformClassesWithDexForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.io.IOException: Unable to create parent directories of C:\King's_College_London\Final_Year_Project\HeartFailure\android\app\build\interm
ediates\pre-dexed\debug\com.android.support-support-core-ui-25.2.0_ed7d36204e2346bc863c0a6433807d11a8ea28a3.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1 mins 38.333 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
这与 firebase 无关。
尝试删除您的 .gradle 文件夹(进行备份)并确保您 运行 从命令行 运行 以管理员身份删除。
正如 @sfratini
所说,这与 firebase 无关,但错误实际上源于导入 react-native-firebase
。
现在对于那些将来可能会遇到这个问题的人,我已经找到了解决方案,所以请清楚准确地按照每个步骤进行操作。
总而言之,如果您导入 react-native-firebase
并遇到任何类型的错误,那么这纯粹是版本问题。然后按照这个:
1.) app\build.gradle
...
// change your dependency object to add the following lines
dependencies {
compile(project(':react-native-firebase')) {
transitive = false
}
compile project(':react-native-config')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile "com.google.android.gms:play-services-base:11.6.0"
compile "com.google.firebase:firebase-core:11.6.0"
compile "com.google.firebase:firebase-database:11.6.0"
}
// this line is very important.
apply plugin: 'com.google.gms.google-services'
2.) anddroid\build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
// compy the following exactly like this
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
/// notice the same objecct maven, but with different url
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
url 'https://maven.google.com'
}
}
}
3.) android\app\src\main\java\com\[yourAppName]\MainApplication.java
// import these two
import io.invertase.firebase.RNFirebasePackage;
import io.invertase.firebase.database.RNFirebaseDatabasePackage;
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new ReactNativeConfigPackage(),
new RNFirebasePackage(),
new RNFirebaseDatabasePackage()
);
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
....
// you'll have other code below, leave that as it is
然后执行以下操作:
npm cache verify
react-native run-android
在我继续之前,请注意,我已经求助于 Whosebug 作为我最后的希望,并且我花了数小时搜索 GitHub 和过去的 "related" 问题。
在一个简单的上下文中,我试图在我的 react-native 应用程序中使用 react-native-firebase,目标是 android 平台。
下面的代码完全按照 react-native-firebase
app\build.gradle
...
dependencies {
compile(project(':react-native-firebase')) {
transitive = false
}
compile project(':react-native-config')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile "com.google.android.gms:play-services-base:11.6.0"
compile "com.google.firebase:firebase-core:11.6.0"
}
...
apply plugin: 'com.google.gms.google-services'
android\build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
url 'https://maven.google.com'
}
}
}
android\app\src\main\java\com\HF\MainApplication.java
...
import io.invertase.firebase.RNFirebasePackage;
import io.invertase.firebase.database.RNFirebaseDatabasePackage;
...
@Override
protected List < ReactPackage > getPackages() {
return Arrays. < ReactPackage > asList(
new MainReactPackage(),
new RNFirebasePackage(),
new ReactNativeConfigPackage(),
new RNFirebaseDatabasePackage()
);
}
...
然而,最后,它并没有 运行,给我一个奇怪的错误。我已尽我所能,但无济于事。任何帮助将不胜感激。
谢谢
如果您对错误感到好奇
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:incrementalDebugJavaCompilationSafeguard
:app:compileDebugJavaWithJavac
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:transformClassesWithDexForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.io.IOException: Unable to create parent directories of C:\King's_College_London\Final_Year_Project\HeartFailure\android\app\build\interm
ediates\pre-dexed\debug\com.android.support-support-core-ui-25.2.0_ed7d36204e2346bc863c0a6433807d11a8ea28a3.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1 mins 38.333 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
这与 firebase 无关。
尝试删除您的 .gradle 文件夹(进行备份)并确保您 运行 从命令行 运行 以管理员身份删除。
正如 @sfratini
所说,这与 firebase 无关,但错误实际上源于导入 react-native-firebase
。
现在对于那些将来可能会遇到这个问题的人,我已经找到了解决方案,所以请清楚准确地按照每个步骤进行操作。
总而言之,如果您导入 react-native-firebase
并遇到任何类型的错误,那么这纯粹是版本问题。然后按照这个:
1.) app\build.gradle
...
// change your dependency object to add the following lines
dependencies {
compile(project(':react-native-firebase')) {
transitive = false
}
compile project(':react-native-config')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile "com.google.android.gms:play-services-base:11.6.0"
compile "com.google.firebase:firebase-core:11.6.0"
compile "com.google.firebase:firebase-database:11.6.0"
}
// this line is very important.
apply plugin: 'com.google.gms.google-services'
2.) anddroid\build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
// compy the following exactly like this
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
/// notice the same objecct maven, but with different url
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
url 'https://maven.google.com'
}
}
}
3.) android\app\src\main\java\com\[yourAppName]\MainApplication.java
// import these two
import io.invertase.firebase.RNFirebasePackage;
import io.invertase.firebase.database.RNFirebaseDatabasePackage;
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new ReactNativeConfigPackage(),
new RNFirebasePackage(),
new RNFirebaseDatabasePackage()
);
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
....
// you'll have other code below, leave that as it is
然后执行以下操作:
npm cache verify
react-native run-android