android - 安装 firebase 插件后使用 cordova 运行应用程序时出现编译错误

标签 android reactjs cordova

我按照本指南安装 Cordova 和 ReactJS:https://medium.com/@pshubham/using-react-with-cordova-f235de698cc3

这有效!

但是,当我想将 firebase 与 Cordova 一起使用时,如本文档中所述:https://firebase.google.com/docs/auth/web/cordova ,在安装第 6 步中解释的插件后,我收到这些错误。

当我运行“cordova run android”时,这是我得到的输出:

Successfully built!
<universal-links> tag is not set in the config.xml. Universal Links plugin is not going 
to work.
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=C:\users\bosschertj\AppData\Local\Android\Sdk (recommended setting)
ANDROID_HOME=C:\Users\bosschertj\AppData\Local\Android\Sdk (DEPRECATED)
Subproject Path: CordovaLib
Subproject Path: app
> Task :app:preBuild UP-TO-DATE
> Task :CordovaLib:preBuild UP-TO-DATE
> Task :CordovaLib:preDebugBuild UP-TO-DATE
> Task :CordovaLib:checkDebugManifest UP-TO-DATE
> Task :CordovaLib:processDebugManifest UP-TO-DATE
> Task :app:preDebugBuild
> Task :CordovaLib:compileDebugAidl NO-SOURCE
> Task :app:compileDebugAidl NO-SOURCE
> Task :CordovaLib:packageDebugRenderscript NO-SOURCE
> Task :app:compileDebugRenderscript
> Task :app:checkDebugManifest UP-TO-DATE
> Task :app:generateDebugBuildConfig
> Task :app:prepareLintJar UP-TO-DATE
> Task :app:generateDebugSources
> Task :CordovaLib:compileDebugRenderscript UP-TO-DATE
> Task :CordovaLib:generateDebugBuildConfig UP-TO-DATE
> Task :CordovaLib:generateDebugResValues UP-TO-DATE
> Task :CordovaLib:generateDebugResources UP-TO-DATE
> Task :CordovaLib:packageDebugResources UP-TO-DATE
> Task :CordovaLib:generateDebugRFile UP-TO-DATE
> Task :CordovaLib:prepareLintJar UP-TO-DATE
> Task :CordovaLib:generateDebugSources UP-TO-DATE
> Task :CordovaLib:javaPreCompileDebug UP-TO-DATE
> Task :CordovaLib:compileDebugJavaWithJavac UP-TO-DATE
> Task :CordovaLib:processDebugJavaRes NO-SOURCE
> Task :CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug UP-TO-DATE
> Task :app:javaPreCompileDebug
> Task :app:mainApkListPersistenceDebug UP-TO-DATE
> Task :app:generateDebugResValues UP-TO-DATE
> Task :app:generateDebugResources
> Task :app:mergeDebugResources
> Task :app:createDebugCompatibleScreenManifests
> Task :app:processDebugManifest UP-TO-DATE
> Task :app:processDebugResources

> Task :app:compileDebugJavaWithJavac FAILED
C:\Users\bosschertj\Documents\projects\lazymind\cordovaReactProject\platforms\android\app\src\main\java\com\google\cordova\plugin\BrowserTab.java:21: error: package android.support.customtabs does not exist
import android.support.customtabs.CustomTabsIntent;
                                 ^
C:\Users\bosschertj\Documents\projects\lazymind\cordovaReactProject\platforms\android\app\src\main\java\com\google\cordova\plugin\BrowserTab.java:104: error: package CustomTabsIntent does not exist
    Intent customTabsIntent = new CustomTabsIntent.Builder().build().intent;24 actionable tasks: 8 executed, 16 up-to-date

                                                  ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 7s
C:\Users\bosschertj\Documents\projects\lazymind\cordovaReactProject\platforms\android\gradlew: Command failed with exit code 1 Error output:
C:\Users\bosschertj\Documents\projects\lazymind\cordovaReactProject\platforms\android\app\src\main\java\com\google\cordova\plugin\BrowserTab.java:21: error: package android.support.customtabs does not exist
import android.support.customtabs.CustomTabsIntent;
                                 ^
C:\Users\bosschertj\Documents\projects\lazymind\cordovaReactProject\platforms\android\app\src\main\java\com\google\cordova\plugin\BrowserTab.java:104: error: package CustomTabsIntent does not exist
    Intent customTabsIntent = new CustomTabsIntent.Builder().build().intent;
                                                  ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 7s

在安装插件之前,一切正常。出了什么问题,我该如何解决这个问题?

编辑:如果您有关于如何使用 Firebase 身份验证与 ReactJS 和 Cordova 配合使用的(更好)教程,请分享。

最佳答案

您可以通过将 cordova 项目转换为 Android X 来解决此问题。 因此,在 android 下的 config.xml 中添加这些行。

 <preference name="AndroidXEnabled" value="true" />
 <preference name="GradlePluginKotlinEnabled" value="true" />
 <preference name="GradlePluginKotlinCodeStyle" value="official" />
 <preference name="GradlePluginKotlinVersion" value="1.3.50" />

删除并再次添加 android 平台。

并更改 BrowserTab.java 文件的导入语句。

import android.support.customtabs.CustomTabsIntent;

import androidx.browser.customtabs.CustomTabsIntent;

该文件的路径是..

/platforms/android/app/src/main/java/com/google/cordova/plugin/BrowserTab.java

关于android - 安装 firebase 插件后使用 cordova 运行应用程序时出现编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61326843/

相关文章:

java - 如何确定应用程序的方法计数?

android - 使用 AspectRatio android Canvas 缩小大图像

android - com.parse.ParseRequest$ParseRequestException : invalid session token

javascript - JS/ReactJS - 分配新变量会更改原始变量

javascript - 测试 react 组件 : Jest encountered an unexpected token

java - 尝试在空对象引用上调用接口(interface)方法 'boolean java.util.List.add(java.lang.Object)'

javascript - Styled-Components 的 .attrs() 函数的用例是什么?

ios - 无法在本地存储中设置和获取值

javascript - phonegap 离线/在线事件不工作

android - Cordova 使用插件发送短信,文本上的 URL 不起作用