Tag Archives: webview

[Solved] Manifest merger failed with multiple errors, see logs

After upgrading Android Sdk to 33 recently, packing Android generates the following problems:

AndroidManifest.xml Error:
 Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.


Execution failed for task ':launcher:processDebugMainManifest'.
> Manifest merger failed with multiple errors, see logs

1. Tried to add android:exported as instructed, but the problem remains. So I used the 2nd solution, drop the sdk version.

2. Drop Android sdk version

1. Set the SDK version of Android project as shown in the following figure:

2. After setting, modify the relevant SDK in all build.gradle configuration files in the project to be consistent with the version number configured in the above figure.

compileSdkVersion 30
buildToolsVersion '30.0.2'
targetSdkVersion 30

[Solved] Resource compilation failed. Check logs for details.

Record the problems encountered that cannot be clearly answered by the search.

Error log:

Execution failed for task ‘:app:mergeDebugResources’.
> A failure occurred while executing com. android. build. gradle. internal. res.ResourceCompilerRunnable
> Resource compilation failed. Check logs for details.

* Try:
Run with –info or –debug option to get more log output. Run with –scan to get full insights.

Error: I added a string-array resource file, and “I’m here” used the abbreviation, which is what caused the above error.

Solution: no abbreviation, directly use “I am here”

 

Android studio configurate intent-filter and compile error [Solved]

The error contents are as follows:

Manifest merger failed : android:exported needs to be explicitly specified for <activity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined.

 

When targeting is greater than or equal to Android 12, if some activities are configured with intent-filter, the exported property must be configured at the same time.

According to the error report, there are two solutions:

1. Modify the targetSdk of build.gradle less than 30.

2. Or add the export attribute to the <Intent-filter> tag in AndroidManifest.xml and assign it to true

Last hammer

No problem!

Websocket Front-end Call Example

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
Welcome<br/><input id="text" type="text"/>
<button onclick="send()">Send message</button>
<hr/>
<button onclick="closeWebSocket()">Close WebSocket connection</button>
<hr/>
<div id="message"></div>
</body>
<script>
var websocket = null;
// determine if the current browser supports WebSocket
if ('WebSocket' in window) {
	websocket = new WebSocket("ws://localhost:8080/wsServer");
}
else {
	alert('The current browser does not support websocket')
}

// Callback method for connection error
websocket.onerror = function () {
	setMessageInnerHTML("An error occurred with the WebSocket connection");
};

// Callback method for successful connection establishment
websocket.onopen = function () {
	setMessageInnerHTML("WebSocket connection successful");
}

// Callback method for received message
websocket.onmessage = function (event) {
	setMessageInnerHTML(event.data);
}

// Callback method for closing the connection
websocket.onclose = function () {
	setMessageInnerHTML("WebSocket connection closed");
}

// Listen to the window close event and actively close the websocket connection when the window is closed to prevent the window from being closed before the connection is broken, which will throw an exception on the server side.
window.onbeforeunload = function () {
	closeWebSocket();
}
 
// Display the message on the web page
function setMessageInnerHTML(innerHTML) {
	document.getElementById('message').innerHTML += innerHTML + '<br/>';
}
 
//Close the WebSocket connection
function closeWebSocket() {
	websocket.close();
}
 
//Send a message

function send() {
var message = document.getElementById('text').value;
	websocket.send(message);
}
</script>

</html>

Could not identify launch activity: Default Activity not foundError while Launching activity

Add in activity

<intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>

When the app has multiple activities, the activity to be started is the main interface and is set to MAIN.

LAUNCHER indicates whether it is displayed in the mobile app list.

[Solved] Stream Error: stream has already been operated upon or closed

public class StreamTest {
    public static void main(String[] args) {
        //Generate a Stream of type String
        Stream<String> stringStream = Stream.of("1", "2", "3", "4", "5");
        // Convert string type in stream to int type using map method
        stringStream.map(
                (String s) ->{
                    return Integer.parseInt(s);
                });
        stringStream.forEach(i -> System.out.println(i));
    }
}

As shown in the figure, the code runs with an error:

The stream has been used or closed

This is a feature of streams: a stream can only be used once!

Error inflating class in WebView in Android 5. X android.webkit.WebView Solutions

using WebView in Android version 5.x May report the following error

android.view.InflateException: Binary XML file line #24: Error inflating class android.webkit.WebView

solution 1:

use createConfigurationContext () method to get the Context

public class LollipopFixedWebView extends WebView {

    public LollipopFixedWebView(Context context) {
        super(getFixedContext(context));
    }

    public LollipopFixedWebView(Context context, AttributeSet attrs) {
        super(getFixedContext(context), attrs);
    }

    public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(getFixedContext(context), attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(getFixedContext(context), attrs, defStyleAttr, defStyleRes);
    }

    public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) {
        super(getFixedContext(context), attrs, defStyleAttr, privateBrowsing);
    }

    public static Context getFixedContext(Context context) {
        // Android Lollipop 5.0 & 5.1
        if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT <= 22) 
            return context.createConfigurationContext(new Configuration());
        return context;
    }
}

solution 2:

in the build.gradle of the project, appcompat version 1.1.0 May be buggy, use the following version to solve the problem

implementation 'androidx.appcompat:appcompat:1.2.0'