"API Not Initialized" error in --release build only
Opened this issue · 14 comments
Platform: Android
Cordova: 10.0.0
While compiling --debug version, everything works fine.
Only when compiled as --release I get this error at app startup, when initializing Chromecast plugin, of course anything related to Chromacast is not working after the error.
Anyone else experienced this issue?
{
"code":"unknown",
"description":"api_not_initialized null",
"details":{}
}
That is interesting. o.o
Can you give more details? (stack trace?)
Any output in ADB?
It is hard to get debug output because it's a release version, so the usual way I have to get some output does not work (chrome devices).
Any hint on how I could get some additional info on a release build?
This happens for Android release only, on iOS I have the release up and running on App Store with no issues whatsoever.
So I assume you are not having the same issue in release builds on Android, correct?
I will try a minimal app to check whether the problem comes from my build setup or other plugins/elements in my current project.
That is a good point. I will try that for sure, this weekend I will be able to test.
I will try with 4.4.6 (October 2020) and see if that helps.
Still no luck. I've been trying for quite a while today experimenting with different versions of SDK too (reverted up to 17.0). Also tried adding some dependencies that were removed back.
Tried both on a Xiaomi device (Android 10) and an AOSP device (Android 9), same results. Debug build works perfectly fine, release will fail to initialize.
AFAIK the main difference between debug and release build is on debug logs and connection blocking (release version will follow more strictly connection blocking rules). I have guessed it might have to do with a connection issue to Google servers, at init stage, as the plugin is looking to access my custom receiver, but I even tried to add for test purposes, the error still persists.
Are you able to have a test to check whether the issue can be replicated or not?
AFAIK the main difference between debug and release build is on debug logs and connection blocking (release version will follow more strictly connection blocking rules). I have guessed it might have to do with a connection issue to Google servers, at init stage, as the plugin is looking to access my custom receiver, but I even tried to add for test purposes, the error still persists.
This is interesting, definitely sounds like a promising route.
I think this issue is actually happening for me too. (I just have too much on my plate and didn't notice >.<)
Our Sentry has a bunch of errors related to chromecast init, and it's only happening on android devices.
Unfortunatley, the error logging isn't set up completely correctly and I'm just getting "failed to init [Object object]"
I will investigate more. I've updated the log, hopefully I will get better info back. I will see if I can find out when this error started and correlate it with changes.
Will post back in a couple hours!
So got my logs to work properly, I am getting the same error as you:
Error during chrome.cast.initialize:{"code":"unknown","description":"api_not_initialized null","details":{}}
Code:
chrome.cast.initialize(apiConfig, function () {
_apiReady = true;
}, function (err) {
console.error(err);
err = err.message || err;
utils.logToSentry('Error during chrome.cast.initialize:' + utils.getString(err));
});
The first instance of this error (in the [Object object] format), only started 11 days ago. (Feb 25, 2021)
This is strange because I haven't done anything to anything for months. (as you can see with the outstanding issues and PR's o.o;;)
So Google must've done something remotely. :/
It seems to affect a very wide range of android devices:
The release build works on my test device though of course. Samsung tablet, SM-T350, Android 7.1.1. :/
Since it looks like the native code for initialize
can only return success, that means we have to look to the javascript....
- This is where the error should be coming from.
- Fixed this minor error on the branch
android-init-issue
(this just fixes the format of the error we're receiving).
But I did also add a stack trace to the error details. (I don't think it will be much help though). - The reason this error is happening is because
chrome.cast.isAvailable === false
(this is the interesting part).
This is where isAvailabe
get's set to true. So this is never happening. :/
The events
correspond to events fired from the native side. So for some reason Android isn't firing the SETUP
event for these devices.
Full flow:
chrome.cast.js
- on load always doesexecute('setup', ...
, which should always make it to the native sideChromecast.java
>boolean execute(
should forward the call (without fail) toChromecast.java
>boolean setup(
I suspect this is where it actually barfs
The only thing that looks like it could actually barf is that maybe connection
doesn't exist.
The only way connection
doesn't exist is if the native side barfed on plugin initialization.
There are a number of things that could go wrong here....
Unfortunately that's all the time I have for digging today...
If we had access to the native logs when running in release mode and the error happens that would be interesting.
The only other thing I can think to try right now is to:
- Empty out the
pluginInitialize
function - Put that content in another function, maybe in
boolean setup
, and then see if we can back error from the try/catch to be returned the javascript side
I successfully applied your changes on the error reporting and now I correctly get the whole details from the error.
Then following the stack trace, I get to the same result as you explained super clearly in your previous post, but I am not so skilled to work on the Java portion of the code.
What I can tell you is that I tried to remove the check on chrome.cast.isAvailable, and of course it returns another error, so there is actually an issue to be solved at init/setup phase. If you could try to trace the error back in the code, I can still try to analyze what's happening in the code to find out which section could be involved in differences between debug and release builds.
Thank you very much for your commitment!
Hi Lindsay,
I was thinking of all the extra stuff happening when switching from debug to release, and I finally found the issue reading the official Google Docs, assuming you have Proguard plugin installed.
Reference: https://developers.google.com/cast/docs/android_sender#other-ide
First test I did: uninstall Proguard plugin, and Chromecast starts working in release.
Second test: add proguard-project.txt in the project root folder, with the content showed in the documentation linked above, still having some issues to solve the issue in a final way, but working on it.
Unless you are not using Proguard, I would say the issue should be close to be solved!
It might be worth to update the documentation for the plugin to warn about this compatibility issue, and how to solve it, once we find the final solution.
https://www.npmjs.com/package/cordova-plugin-proguard
this might help to enable proguard and setup the customization file more easily?