我不知道为什么每次尝试创建应用程序的构建时都会遇到此错误。我尝试了许多解决方案,但无法解决。我不知道是否有任何插件引起了问题或是否存在任何问题我的代码或firebase或firebase连接出现问题。我已删除节点模块并运行npm install并删除并重新添加了android平台,但仍然出现此错误。
import com.google.firebase.iid.FirebaseInstanceIdService;
^
symbol: class FirebaseInstanceIdService
location: package com.google.firebase.iid
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePluginInstanceIDService.java:9: error: cannot find symbol
public class FirebasePluginInstanceIDService extends FirebaseInstanceIdService {
^
symbol: class FirebaseInstanceIdService
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:508: error: method getByteArray in class FirebaseRemoteConfig cannot be applied to given types;
: FirebaseRemoteConfig.getInstance().getByteArray(key, namespace);
^
required: String
found: String,String
reason: actual and formal argument lists differ in length
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:525: error: method getValue in class
FirebaseRemoteConfig cannot be applied to given types;
: FirebaseRemoteConfig.getInstance().getValue(key, namespace);
^
required: String
found: String,String
reason: actual and formal argument lists differ in length
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:579: error: no suitable method found
for setDefaults(Map<String,Object>,String)
FirebaseRemoteConfig.getInstance().setDefaults(defaultsToMap(defaults), namespace);
^
method FirebaseRemoteConfig.setDefaults(Map<String,Object>) is not applicable
(actual and formal argument lists differ in length)
method FirebaseRemoteConfig.setDefaults(int) is not applicable
(actual and formal argument lists differ in length)
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePluginInstanceIDService.java:18: error: method does not override or implement a method from a supertype
@Override
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\io\card\cordova\sdk\CardIOCordovaPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
6 errors
:app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
27 actionable tasks: 1 executed, 26 up-to-date
> 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.
* Get more help at https://help.gradle.org
BUILD FAILED in 54s
cmd: Command failed with exit code 1 Error output:
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePluginInstanceIDService.java:6: error: cannot find symbol
import com.google.firebase.iid.FirebaseInstanceIdService;
^
symbol: class FirebaseInstanceIdService
location: package com.google.firebase.iid
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePluginInstanceIDService.java:9: error: cannot find symbol
public class FirebasePluginInstanceIDService extends FirebaseInstanceIdService {
^
symbol: class FirebaseInstanceIdService
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:508: error: method getByteArray in class FirebaseRemoteConfig cannot be applied to given types;
: FirebaseRemoteConfig.getInstance().getByteArray(key, namespace);
^
required: String
found: String,String
reason: actual and formal argument lists differ in length
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:525: error: method getValue in class
FirebaseRemoteConfig cannot be applied to given types;
: FirebaseRemoteConfig.getInstance().getValue(key, namespace);
^
required: String
found: String,String
reason: actual and formal argument lists differ in length
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:579: error: no suitable method found
for setDefaults(Map<String,Object>,String)
FirebaseRemoteConfig.getInstance().setDefaults(defaultsToMap(defaults), namespace);
^
method FirebaseRemoteConfig.setDefaults(Map<String,Object>) is not applicable
(actual and formal argument lists differ in length)
method FirebaseRemoteConfig.setDefaults(int) is not applicable
(actual and formal argument lists differ in length)
C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePluginInstanceIDService.java:18: error: method does not override or implement a method from a supertype
@Override
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\user\Downloads\mosque\platforms\android\app\src\main\java\io\card\cordova\sdk\CardIOCordovaPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
6 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.
* Get more help at https://help.gradle.org
BUILD FAILED in 54s
[ERROR] An error occurred while running subprocess cordova.
cordova build android exited with exit code 1.
答案 0 :(得分:2)
是的,它已贬值。修复非常简单,只需移动代码...
来自您的onTokenRefresh()
子类中的FirebaseInstanceIdService
到达您的onNewToken()
子类中的FirebaseMessagingService
折旧信息:https://firebase.google.com/support/release-notes/android#update_-_april_02_2019
我建议您使用旧版本的Firebase进行此小的代码更改。在您使用的同时,也可以迁移到AndroidX [https://developer.android.com/jetpack/androidx/migrate]。
答案 1 :(得分:2)
由于主要的Firebase版本支持AndroidX而发生此问题
解决方案:
删除android平台(我遵循了此步骤。但是应该有我可能不知道的解决方法)-cordova platform rm android
删除旧的firebase插件-
cordova plugin rm cordova-plugin-firebase
添加新的firebase插件-
cordova plugin add cordova-plugin-firebasex
再次添加平台-
cordova platform add android
现在您的构建将成功。
答案 2 :(得分:1)
好的。这是gradle错误。这是由于Firebase在4月进行了更新,FirebaseInstanceIdService
已过时,许多人都面临这个问题。
Check the reference documentation for FirebaseInstanceIdService
不推荐使用此类。
赞成在FirebaseMessagingService中重写onNewToken。一旦 已经实施,则可以安全删除此服务。
答案 3 :(得分:1)
这是由于Firebase于4月5日更新。在https://firebase.google.com/support/release-notes/android#update_-_april_02_2019 96,我找到了上一个工作版本,并相应地调整了project.properties
,如下所示:
cordova.system.library.4=com.google.firebase:firebase-core:16.0.8
cordova.system.library.5=com.google.firebase:firebase-messaging:17.5.0
cordova.system.library.6=com.google.firebase:firebase-config:16.4.1
cordova.system.library.7=com.google.firebase:firebase-perf:16.2.4
此处所有依赖项均锁定为特定版本(更新-2019年4月2日),而不是 + ,这将为您提供最新版本,从而破坏了构建过程。
现在我可以成功构建了!希望对您有帮助!
可以在 platforms / android / project.properties 上找到 project.properties
答案 4 :(得分:1)
经过服务器测试后,我的解决方案是通过cordova-plugin-firebasex更改cordova-plugin-firebase。 https://github.com/dpa99c/cordova-plugin-firebase#migrating-from-cordova-plugin-firebase
rm -Rf platforms/android
cordova plugin rm cordova-plugin-firebase
rm -Rf plugins/ node_modules/
npm install
cordova plugin add cordova-plugin-firebasex
cordova platform add android
我希望这会有所帮助。
https://github.com/dpa99c/cordova-plugin-firebase#androidx
此插件已迁移为使用AndroidX(Jetpack),后者是Android支持库的后继产品。通过添加对cordova-plugin-androidx的依赖关系来实现,该依赖关系可在Cordova项目的Android平台中启用AndroidX。
这是因为Firebase和Play Services库的主要版本于2019年6月17日已迁移到AndroidX。
因此,如果您的项目包含依赖于旧版Android支持库的任何插件,则应将cordova-plugin-androidx-adapter添加到您的项目中。该插件会将所有插件代码从Android支持库动态迁移到AndroidX等效版本。
答案 5 :(得分:0)
如果此问题发生在 React Native 框架中。有两种解决方案:
在以下文件中更改Firebase版本:
android\app\build.gradle
...
//implementation 'com.google.firebase:firebase-core'
//implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-messaging:17.6.0'
...
然后在文件底部的android\gradle.properties
中添加
firebaseCoreVersion=16.0.8
firebaseMessagingVersion=17.6.0
将\node_modules\react-native-fcm\android\src\main\java\com\evollu\react\fcm\InstanceIdService.java
文件更改如下。
package com.evollu.react.fcm;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.ReactContext;
import com.google.firebase.iid.FirebaseInstanceId;
//import com.google.firebase.iid.FirebaseInstanceIdService; //Commented FirebaseInstanceIdService
import com.google.firebase.messaging.FirebaseMessagingService; //ADD FirebaseMessagingService
public class InstanceIdService extends FirebaseMessagingService {
private static final String TAG = "InstanceIdService";
/**
* Called if InstanceID token is updated. This may occur if the security of
* the previous token had been compromised. This call is initiated by the
* InstanceID provider.
*/
// [START refresh_token]
@Override
public void onNewToken(String token) { //Added onNewToken method
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
// Broadcast refreshed token
Intent i = new Intent("com.evollu.react.fcm.FCMRefreshToken");
Bundle bundle = new Bundle();
bundle.putString("token", refreshedToken);
i.putExtras(bundle);
final Intent message = i;
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
public void run() {
// Construct and load our normal React JS code bundle
ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
ReactContext context = mReactInstanceManager.getCurrentReactContext();
// If it's constructed, send a notification
if (context != null) {
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
} else {
// Otherwise wait for construction, then send the notification
mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
public void onReactContextInitialized(ReactContext context) {
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
}
});
if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
// Construct it in the background
mReactInstanceManager.createReactContextInBackground();
}
}
}
});
}
}
答案 6 :(得分:0)
使用
cordova plugin add cordova-plugin-androidx
cordova plugin add cordova-plugin-androidx-adapter
然后使用
cordova plugin add cordova-plugin-firebasex