Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use tools:overrideLibrary inside config.xml to override splashscreen library? #1517

Closed
bsataric opened this issue Nov 7, 2022 · 14 comments

Comments

@bsataric
Copy link

bsataric commented Nov 7, 2022

I am trying to override splashcreen library inside Manifest file by inserting following line into config.xml:

<uses-sdk tools:overrideLibrary="androidx.core.splashscreen"/>

I have also inserted this into my config xml in the beginning:

<edit-config file="AndroidManifest.xml" target="/manifest" mode="merge">
  <manifest xmlns:tools="http://schemas.android.com/tools" />
</edit-config> 

And it works as it inserts the tools namespace inside the manifest tag.

However the tools:overrideLibrary part is a mystery to me. I'm not sure how to insert it into the manifest via config.xml.

I tried putting it inside another edit-config tag, and also config-file tag but I'm not sure about proper syntax (or if it can be done at all) for it to graft the correct Manifest in the end.

@lempere
Copy link
Contributor

lempere commented Nov 8, 2022

To insert the element tag uses-sdk you could do it like inserting permissions

<config-file parent="/manifest" target="AndroidManifest.xml">
    <uses-sdk tools:overrideLibrary="androidx.core.splashscreen"/>
</config-file>

@bsataric
Copy link
Author

bsataric commented Nov 8, 2022

@lempere thanks for the answer.

However it doesn't work (and I think I tried it before). The following error occurs (btw. I'm using Cordova 11):

Execution failed for task ':app:mergeDebugResources'.

A failure occurred while executing com.android.build.gradle.internal.res.ResourceCompilerRunnable
Resource compilation failed (Failed to compile resource file: ....config.xml: . Cause: com.ctc.wstx.exc.WstxParsingException: Undeclared namespace prefix "tools" (for attribute "overrideLibrary")
at [row,col {unknown-source}]: [159,71]). Check logs for more details.

Basically the two tags I'm trying are these:

<edit-config file="AndroidManifest.xml" target="/manifest" mode="merge">
  <manifest xmlns:tools="http://schemas.android.com/tools" />
</edit-config> 

<config-file parent="/manifest" target="AndroidManifest.xml">
  <uses-sdk tools:overrideLibrary="androidx.core.splashscreen"/>
</config-file>

@dpogue
Copy link
Member

dpogue commented Nov 8, 2022

You need to add xmlns:tools="http://schemas.android.com/tools" to the widget tag in your config.xml file too.

Because the whole file is XML, it needs that namespace declared at the top level for parsing to succeed.

@bsataric
Copy link
Author

bsataric commented Nov 8, 2022

I tried that as well but it just doesn't recognize it that way via widget.

It has to be added manually with edit-config as I wrote in the post above. But even then the tools:ooverrideLibrary doesn't see it.

@bsataric
Copy link
Author

bsataric commented Nov 11, 2022

I think I found a way to do ti somehow... But it still doesn't always circumvent the navbar dissapearing issue. In Android studio buiild navbar is there but via Cordova and VSCode it's not... Anyway I added these 2 things:

<edit-config file="AndroidManifest.xml" target="/manifest" mode="merge">
  <manifest xmlns:tools="http://schemas.android.com/tools" />
</edit-config> 


<edit-config file="AndroidManifest.xml" 
               mode="add" target="/manifest" 
               xmlns:tools="http://schemas.android.com/tools">
  <uses-sdk tools:overrideLibrary="androidx.core.splashscreen" />
</edit-config>

@jcesarmobile
Copy link
Member

The last comment is confusing, what the <uses-sdk tools:overrideLibrary="androidx.core.splashscreen" /> would do is to override any uses-sdk limitation androidx.core.splashscreen library could have. In example if it required minSDK 23 but you wanted to still support SDK 22 as Cordova does.
So adding that override does not fix any issue the splash screen support library is causing.

What are you trying to achieve with that change?

@bsataric
Copy link
Author

I'm trying to prevent nabar on the top from dissapearing on the app launch. That somehow started happening with introduction of Cordova 11 and splaschreen 6.0.2. Somewhere I saw that overriding SS plugin this way might help about it but it seems it's not a consistent solution. Also clearing cache helps it seems but it's not a valid solution. It happens on Android 13 and Pixel 6, while on some other phones it works ok.

Also I do not understand about the minSdk version. Am I supposed to add that along overideLibrary? Which minSdk version should I put? I'm not an Android programer so for me all of this is quite confusing and help is apperiated.

@jcesarmobile
Copy link
Member

The minSDK was just an example of what that override does, it overrides whatever requirements/restrictions related to the SDK versions a library might have (max, min, target SDKs) that could conflict with your own app requirements. But the library has none, so adding that override is not doing anything.

Your problem is really a problem with the new splash screen API, that doesn’t allow programmatic changes of the app theme (status bar, navigation bar, etc.) while the splash screen is being displayed (it’s an Android OS bug starting on android 12, but more noticeable on android 13 since on android 12 would only happen when launching from the app icon)
This change might help once it’s released (would also require to set the FadeSplashScreen preference to false)
#1506

Other solutions depending on the problem is to configure the app theme in the styles.xml file with styles you want your app theme to have, can be used for the status bar background and text color, and for the bottom navigation bar (gesture bar or the bar with software navigation buttons).
Not really sure what you mean by “navbar on top”, so not sure it that can be styled.

@bsataric
Copy link
Author

Hmmm I see.

Thananks for the answer!

I guess there's nothing else but wait for a solution to this particular issue, or if nothing appears then to style/css our app so it somehow responds correctly to the navbar dissapearing. Bottom pic is with "navbar" disapearing and bottom one is how it should be without this bug:

image

@jcesarmobile
Copy link
Member

Is that a native bar or html bar?

The problem is not going to be fixed for Android 12, and probably for Android 13 neither, I don't think it has even been reported to Google and even if reported, google is closing most of the splash related issues as "working as expected".

If it's a native bar and you are using some plugin to show it, you can try to put the code to show the bar in a setTimeout with ~500ms, that worked for me on a similar issue where the app content was being put behind the status bar.

@bsataric
Copy link
Author

It is cordova-plugin-statusbar plugin.

So when I put a 500ms delay on the Statusbar.show() it shows but it's still plugged to the top of the screen (it should have the green top as you can see in the picture above):

image

I realized that the statusbar plugin here is actually used only as a green bar on top and doesn't contain HTML elements iteself.

@jcesarmobile
Copy link
Member

So the bar with the bluetooth icon, the "my sites", "Map view" and other icons is html, right?

try also calling StatusBar.overlaysWebView(false); inside the setTimeout and also change the color in there, as you are probably changing the color by using the preferences. None of the status bar plugin preferences will work on Android 12+ because of the mentioned bug as they are applied on app startup but the splash screen is preventing style changes on app startup.

@bsataric
Copy link
Author

Yes the bar contains html.

I tried calling StatusBar.overlaysWebView(false); inside handleStatusBar function but it doesn't help.

Code snippet that works with statusbar looks basically like this:

private handleStatusBar() {
	if (window.cordova && window.StatusBar) {
		window.StatusBar.show();
		window.StatusBar.backgroundColorByHexString('#009A80');
	}
}

But adding timeout inside it, or calling handleStatusBar from a timeout doens't do too much good as well, as sometimes it works, and sometimes it overlaps the html elements in html bar as it seems that all these calls are random in timing in terms of what overlaps what so there is not a predictable outcome of how the top of the app looks like.

@jcesarmobile
Copy link
Member

Going to close since the problem has nothing to do with the original question.
Once #1506 gets released it will help to mitigate this problem.

@jcesarmobile jcesarmobile closed this as not planned Won't fix, can't repro, duplicate, stale Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants