Open iiaishwarya opened 6 years ago
@aishwaryasharma96 can you run adb logcat
while reproducing the problem so we can see the logs?
I'm getting the same error:
10-10 14:43:01.029 12099 12205 V Push_Plugin: execute: action=init
10-10 14:43:01.030 12099 12146 V Push_Plugin: execute: data=[{"android":{"senderID":"SNIP","icon":"smallicon","iconColor":"#00A8CA","forceShow":true},"ios":{"alert":"true","badge":"true","sound":"true","clearBadge":true}}]
10-10 14:43:01.031 12099 12146 V Push_Plugin: execute: jo={"senderID":"SNIP","icon":"smallicon","iconColor":"#00A8CA","forceShow":true}
10-10 14:43:01.032 12099 12146 E com.ma.android: Invalid ID 0x00000000.
10-10 14:43:01.032 12099 12146 E Push_Plugin: execute: Got Resources NotFoundException String resource ID #0x0
Looking at the code it looks like the plugin is failing when trying to get the GCM_DEFAULT_SENDER_ID
string constant
PushPlugin.java
191: Log.v(LOG_TAG, "execute: jo=" + jo.toString());
192:
193: senderID = getStringResourceByName(GCM_DEFAULT_SENDER_ID);
194:
195: Log.v(LOG_TAG, "execute: senderID=" + senderID);
While I'm here, is this code correct? The senderID seems to only be set to this string constant and not the senderID that gets passed into the plugin
I am experiencing the exact same issue, although I am not using Meteor. This happens both when compiling locally and via Phonegap Build.
Here is the output from adb logcat | grep Push
when I compile locally:
10-15 15:59:53.547 29624 29742 V Push_Plugin: execute: action=init
10-15 15:59:53.555 29624 29699 V Push_Plugin: execute: data=[{"android":{"icon":"icon","iconColor":"#444488"},"browser":{},"ios":{"alert":true,"sound":true,"vibration":true,"badge":true,"clearBadge":true}}]
10-15 15:59:53.556 29624 29699 V Push_Plugin: execute: jo={"icon":"icon","iconColor":"#444488"}
10-15 15:59:53.556 29624 29699 E Push_Plugin: execute: Got Resources NotFoundException String resource ID #0x0
Phonegap CLI v7.1.0 phonegap-plugin-push v2.1.2 cordova android v6.4.0
Relevant config.xml
details:
<preference name="phonegap-version" value="cli-7.1.0" />
<preference name="android-minSdkVersion" value="24" />
<platform name="android">
<resource-file src="google-services.json" target="google-services.json" />
</platform>
<engine name="android" spec="6.4.0" />
<plugin name="phonegap-plugin-push" spec="2.1.2">
<variable name="FCM_VERSION" value="11.0.1" />
</plugin>
I've verified that my google-services.json
file is up to date.
Okay, then this appears to be a compile time error where the Google Play Services Gradle Plugin is not being applied properly so the sender ID is not being added to the resources correctly. Can anyone check their build to see if it is reporting an error along those lines.
@macdonst thanks for the quick response.
I am not sure if this is helpful, but here is some of the output from my local build:
Updating icons at platforms/android/res
Updating splash screens at platforms/android/res
Updating resource files at platforms/android
copy google-services.json platforms/android/google-services.json (updated file)
Prepared android project successfully
Later in the build output:
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :wrapper
BUILD SUCCESSFUL in 4s
1 actionable task: 1 executed
Command finished with error code 0: /usr/local/Cellar/gradle/4.10.2/bin/gradle -p,/Users/codyrushing/Projects/phoneapp/app/platforms/android,wrapper,-b,/Users/codyrushing/Projects/phoneapp/app/platforms/android/wrapper.gradle
Subproject Path: CordovaLib
Running command: /Users/codyrushing/Projects/phoneapp/app/platforms/android/gradlew cdvBuildDebug -b /Users/codyrushing/Projects/phoneapp/app/platforms/android/build.gradle -Dorg.gradle.daemon=true -Dorg.gradle.jvmargs=-Xmx2048m -Pandroid.useDeprecatedNdk=true
Download https://jcenter.bintray.com/com/android/tools/build/gradle/maven-metadata.xml
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
at build_202efyw0s07ivrvn3fy5g3csk.run(/Users/codyrushing/Projects/phoneapp/app/platforms/android/build.gradle:143)
Configuration 'compile' in project ':' is deprecated. Use 'implementation' instead.
WARNING: The Jack toolchain is deprecated and will not run. To enable support for Java 8 language features built into the plugin, remove 'jackOptions { ... }' from your build.gradle file, and add
android.compileOptions.sourceCompatibility 1.8
android.compileOptions.targetCompatibility 1.8
Future versions of the plugin will not support usage of 'jackOptions' in build.gradle.
To learn more, go to https://d.android.com/r/tools/java-8-support-message.html
This build successfully deploys to my device, but I get the same String resource ID #0x0
error on push registration.
If you need the full log from my build, let me know.
@aishwaryasharma96 google-services.json needs to reach into .meteor/cordova-build/platforms/android.
Hi Meteor guys, I don't have all these problems (Meteor 1.7.0.5 and Meteor 1.8) . I build with Android Studio 3.1.4 (avoid 3.2+ when cordova-android 6.4). JDK - default of Android Studio and I think Java 1.6 would be preferable for cordova-android 6.4. Gradle 4.1 (probably 4.6 would also do it) and these in the Android level build.gradle file:
apply plugin: 'com.android.application'
buildscript {
repositories {
google()
jcenter()
}
// Switch the Android Gradle plugin version requirement depending on the
// installed version of Gradle. This dependency is documented at
// http://tools.android.com/tech-docs/new-build-system/version-compatibility
// and https://issues.apache.org/jira/browse/CB-8143
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.1.0'
}
}
// Allow plugins to declare Maven dependencies via build-extras.gradle.
allprojects {
repositories {
google()
jcenter()
}
project.ext {
defaultBuildToolsVersion="26.1.1" //String
defaultMinSdkVersion=21 //Integer - Minimum requirement is Android 5.0
defaultTargetSdkVersion=26 //Integer - We ALWAYS target the latest by default
defaultCompileSdkVersion=26 //Integer - We ALWAYS compile with the latest by default
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.1'
}
then ....
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
then
dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
// SUB-PROJECT DEPENDENCIES START
implementation(project(path: "CordovaLib"))
implementation "com.google.firebase:firebase-auth:16.0.4"
implementation "com.google.firebase:firebase-config:16.0.1"
// implementation "com.crashlytics.sdk.android:crashlytics:2.9.5"
implementation "com.google.firebase:firebase-perf:16.1.2"
implementation "com.google.android.gms:play-services-auth:16.0.1"
implementation "com.google.android.gms:play-services-identity:16.0.0"
// implementation "com.android.support:support-v13:27.0.2"
implementation "me.leolin:ShortcutBadger:1.1.22@aar"
implementation "com.google.firebase:firebase-messaging:17.3.3"
implementation "com.squareup.okhttp3:okhttp:3.9.1"
// implementation "com.android.support:support-v4:24.1.1+"
implementation "com.facebook.android:facebook-android-sdk:4.37.0"
// implementation "com.android.support:support-v13:27.1.1"
implementation "com.android.support:appcompat-v7:26.+"
// implementation "com.squareup.okhttp3:okhttp:3.+"
// SUB-PROJECT DEPENDENCIES END
}
and the gradle file needs to end with this line:
apply plugin: 'com.google.gms.google-services'
which works together with 'com.google.gms:google-services:4.1.0' at the top. Everything else is the generic from Meteor android build.
I am paulailincai on skype if anyone needs a peer (re)view.
@paulincai are you using the https://github.com/raix/push plugin? If so have you implemented the channels for android 8?
We encountered the same error and resolved it by reinstalling the plugin.
cordova plugin remove phonegap-plugin-push
cordova plugin add phonegap-plugin-push
Resolved in the same way above:
cordova plarform remove android cordova plugin remove phonegap-plugin-push cordova plugin add phonegap-plugin-push cordova platform add android
When I am using this plugin I am getting the following error. It will be great if any one explains me what the problem might be ?
@karthik93r check logcat, but it might be an error finding GCM_DEFAULT_SENDER_ID, probably a gradle compile error, are you using android studio?
the ide gives you alot more clarity on build errors
@da314pc Thank you for the response.Some how the plugin is not getting the GCM_DEFAULT_SENDER_ID.Is there any way we can give default sender id to the plugin in the config file. We have tried like this :
<plugin name="phonegap-plugin-push" source="npm">
<params>
<param name="SENDER_ID" value="xxxxxxxxxx7" />
</params>
</plugin>
@karthik93r I am pretty certain this a gradle build error. Are you just building from the console? Usually, I see issues like this not build the entire project because of some conflicting google library or other error in gradle.
@da314pc We are doing the build from the console only.Is this error can be because of Invalid google-services.json file?
spent 4 hours and solved it.
do:
cordova plugin add cordova-android-play-services-gradle-release
cordova platform remove android
cordova plugin remove phonegap-plugin-push
cordova plugin add phonegap-plugin-push
cordova platform add android
We also have this problem, however the senderID seems to be applied properly:
07-25 12:55:36.273 20396 20520 V Push_Plugin: execute: action=init
07-25 12:55:36.274 20396 20465 V Push_Plugin: execute: data=[{"android":{"senderID":"XXXXXX"},"ios":{"vibration":true}}]
07-25 12:55:36.276 20396 20465 V Push_Plugin: execute: jo={"senderID":"XXXXXX"}
07-25 12:55:36.277 20396 20465 E Push_Plugin: execute: Got Resources NotFoundException String resource ID #0x0
EDIT: Okay, the senderID which is passed in by the client as part of data
is applied here, GCM_DEFAULT_SENDER_ID is set to the default const value, thus it fails..
After updating cordova-android from 7.1.1 to 8.0.0, this seems to work.
EDIT: But it only works on initial builds, when building again (w/o removing platforms/plugins first) it wont create the relevant files in platforms/android/app/build/generated/res - https://developers.google.com/android/guides/google-services-plugin)
EDIT2: Okay nvmd I have no idea what's going on. It generates the files sometimes. Seems random.
EDIT3: After what felt like ages of trial and error with different plugins i figured out (with a fork of this phonegap-plugin-push) that setting the version of https://www.npmjs.com/package/cordova-support-google-services to the latest one finally works. So until a new version of phonegap-plugin-push is released, we'll use our fork with the updated dependency version...
I fixed this error by adding this snippet to config.xml:
`
`
EDIT: I am using cordova-support-google-services, which generates the values.xml that contains among others the gcm_defaultSenderId. If that xml does not exist, you cannot initialize the FirebaseApp.
This plugin uses a shared gradle variable ext.postBuildExtras
to trigger the xml generation. In my , I have another plugin that overwrites this ext.postBuildExtras
.
EDIT2: You can verify if the google-services.json is picked up, by looking for this statement in the gradle build logs.
> Task :app:processReleaseGoogleServices Parsing json file: [some path]/platforms/android/app/google-services.json
EDIT3: After what felt like ages of trial and error with different plugins i figured out (with a fork of this phonegap-plugin-push) that setting the version of https://www.npmjs.com/package/cordova-support-google-services to the latest one finally works. So until a new version of phonegap-plugin-push is released, we'll use our fork with the updated dependency version...
Just updated our Cordova-Android from 7.1 to 8.0.0 and had the "Got Resources NotFoundException String resource ID #0x0" error. After removing cordova-support-google-services @1.1.0 and adding cordova-support-google-services@1.3.2, I can confirm the error is now gone and Push Notifications work again - thank you. phonegap-plugin-push version is 2.2.3.
EDIT3: After what felt like ages of trial and error with different plugins i figured out (with a fork of this phonegap-plugin-push) that setting the version of https://www.npmjs.com/package/cordova-support-google-services to the latest one finally works. So until a new version of phonegap-plugin-push is released, we'll use our fork with the updated dependency version...
Just updated our Cordova-Android from 7.1 to 8.0.0 and had the "Got Resources NotFoundException String resource ID #0x0" error. After removing cordova-support-google-services @1.1.0 and adding cordova-support-google-services@1.3.2, I can confirm the error is now gone and Push Notifications work again - thank you. phonegap-plugin-push version is 2.2.3.
We eventually switched to Capacitor 2 months ago and are really enjoying it. We no longer have the same kind of infuriating issues like we had with cordova. Feels like we have a lot more control now. Can really recommend checking it out (https://capacitor.ionicframework.com/docs/cordova/migrating-from-cordova-to-capacitor).
I have this same problem. The problem presented itself when I added appcenter's code push plugin (cordova-plugin-code-push). I noticed that:
app/src/main/res/values/strings.xml only contains
<?xml version='1.0' encoding='utf-8'?>
<resources>
<string name="app_name">Helloworld</string>
<string name="launcher_name">@string/app_name</string>
<string name="activity_name">@string/launcher_name</string>
</resources>
I did find that there is a file in
app/build/generated/res/google-services/arm64/debug/values/values.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="default_web_client_id" translatable="false">XXXXXXX</string>
<string name="firebase_database_url" translatable="false">XXXXXXX</string>
<string name="gcm_defaultSenderId" translatable="false">XXXXXXX</string>
<string name="google_api_key" translatable="false">XXXXXXX</string>
<string name="google_app_id" translatable="false">XXXXXXX</string>
<string name="google_crash_reporting_api_key" translatable="false">XXXXXXX</string>
<string name="google_storage_bucket" translatable="false">XXXXXXX</string>
<string name="project_id" translatable="false">XXXXXXX</string>
</resources>
If I merged these keys into the app/src/main/res/values/strings.xml with what was previously there then everybody is happy.
Any thoughts on getting the console build to just work for cordova with these constraints?
@GimpMaster I think its becoming really hard not to build the project in Android Studio
The problem is the gcm libraries sometimes clash with the android cordova libraries
check these versions classpath 'com.google.gms:google-services:4.1.0' classpath 'com.google.firebase:firebase-core:11.0.1'
Thank you @da314pc .
What I did was copy off the working platform/android folder to a backup location. And then re-built with the code-push plugin. Looking through BOTH of those folders I see the following:
Working and NOT-Working classpath 'com.google.gms:google-services:4.2.0' classpath 'com.android.tools.build:gradle:3.+'
I did not find anywhere firebase:firebase-core even in the working scenario
However I do see this:
implementation "com.google.firebase:firebase-messaging:17.0.+"
in working and not-working scenarios.
@GimpMaster forgot to mention, that some of the libraries you have to add I'm pretty sure the plugin wont work without the firebase:firebase-core library. I think the com.google.gms:google-services is optional.
@da314pc Ok, I tracked this down to an issue of postBuildExtras.
Both microsoft code-push and cordova-support-google-services use the ext.postBuildExtras function. The problem is only the last gradle file included in app/build.grade gets to keep the postBuildExtras function. So one will run but not the other depending on when they were included.
I found a fork of cordova-support-google-services where they went back to cdvPostBuildExtras
https://github.com/cloudscapelabs/cordova-support-google-services/blob/csl/build.gradle
Doing this solved the problem for me.
@da314pc Ok, I tracked this down to an issue of postBuildExtras.
Both microsoft code-push and cordova-support-google-services use the ext.postBuildExtras function. The problem is only the last gradle file included in app/build.grade gets to keep the postBuildExtras function. So one will run but not the other depending on when they were included.
I found a fork of cordova-support-google-services where they went back to cdvPostBuildExtras
https://github.com/cloudscapelabs/cordova-support-google-services/blob/csl/build.gradle
Doing this solved the problem for me.
+1
In my case I debugged the problem and found that in PushPlugin.java
the method getStringResourceByName()
is called and inside it activity.getResources().getIdentifier(aString, "string", packageName);
, in which GCM_DEFAULT_SENDER_ID
is the value of GCM_DEFAULT_SENDER_ID
: gcm_defaultSenderId
, and this resource was not found (returned 0
).
I solved it according to this answer https://stackoverflow.com/a/33498712/4850646, including the value of project_number
(inside project_info
in google-services.json
) in the file platforms/android/app/src/main/res/values/strings.xml
:
<string name="gcm_defaultSenderId">PROJECT_NUMBER</string>
I don't know why this value is not being automatically defined, tough.
Update
After I added that property the app closed right after opening it and the with the log:
java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process <package_name>. Make sure to call FirebaseApp.initializeApp(Context) first
The error was actually a side effect of the com.google.gms:google-services
library not being applied.
These problems started after I updated to cordova-android@9.0.0
, and seeing the announcement of this version, there is a section Added Google Services Support
that says to use the following property to use Google APIs or Firebase Services:
<preference name="GradlePluginGoogleServicesEnabled" value="true" />
After adding it, the file platforms/android/app/build/generated/res/google-services/debug/values/values.xml
(which has the property gcm_defaultSenderId
, among others, as shown in a previous comment) was generated (there wasn't this file before), and I can now use the push plugin again.
I am trying to send notifications on Android but on startup, apparently
this.push.on("error", e => { alert(e.message); this.log("Push.Error:", e); this.emit("error", { type: getService() + ".cordova", error: e.message }); });
gives an error saying: string resource id #0x0
Platform and Version
Android 6.4.0
Plugin version
I have google-service.json in .meteor\local\cordova-build