apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.59k stars 1.52k forks source link

cordova-android@12 app crashing and not install issu #1619

Closed hansarajgyaneswar closed 11 months ago

hansarajgyaneswar commented 11 months ago

IMG-20230528-WA0010 IMG-20230528-WA0009

Bug Report

Problem

What is expected to happen?

What does actually happen?

Information

Command or Code

Environment, Platform, Device

Version information

Checklist

hansarajgyaneswar commented 11 months ago

Many devices opening splash screen and close

breautek commented 11 months ago

Please fill out the form, and include the output of cordova plugin ls

hansarajgyaneswar commented 11 months ago

cordova-plugin-admobpro 8.13.1 "AdMob Plugin Pro" cordova-plugin-contacts-phonenumbers 0.0.12 "Contacts Phone Numbers" cordova-plugin-device 2.1.0 "Device" cordova-plugin-extension 1.6.0 "Cordova Plugin Extension" cordova-plugin-geolocation 4.1.0 "Geolocation" cordova-plugin-upi 1.0.4 "UPI"

breautek commented 11 months ago

Can you explain the steps that was taken to update to cordova-android@12?

hansarajgyaneswar commented 11 months ago

First unstall Cordova and fresh install

hansarajgyaneswar commented 11 months ago

App working fine my emulator and my mobile. But some device app crash and not opening and installing issue

breautek commented 11 months ago

That's not very descriptive. Cordova has several packages with their own version numbers.

For example there is cordova, the command line package, and then there are the platforms (e.g. cordova-android).

To use cordova-android@12, it would be recommended to use the latest CLI version, which is also 12.0.0.

npm install -g cordova@12

The cordova -v command should then print:

cordova -v
12.0.0 (cordova-lib@12.0.1)

Then to upgrade an existing project, you'll need to remove the platform and add the new version:

cordova platform remove android
cordova platform add android@12

If you're upgrading from cordova-android@9 then you should the following plugins if they are installed:

If you're still having problems, then I'd try removing the plugins folder to forcefully let cordova reinstall everything from scratch:

  1. Delete the <cordova-project>/plugins directory
  2. Delete the <cordova-project>/platforms directory
  3. cordova platform add android@12
hansarajgyaneswar commented 11 months ago

IMG-20230529-WA0007 My friend device not working

I already did above guide

hansarajgyaneswar commented 11 months ago

/ Screenshot_2023-05-29-22-26-31-640_com example hello My device working fine

hansarajgyaneswar commented 11 months ago

I set also minimum sdk 21

breautek commented 11 months ago

I set also minimum sdk 21

cordova-android@12 is only tested with API 24+.

IMG-20230529-WA0007 My friend device not working

I already did above guide

This looks like a native UI being produced by a plugin given that it has an action bar, which the cordova activity has disabled. The problem here appears to be in one of your installed plugins.

hansarajgyaneswar commented 11 months ago

I did without any plugin I make simple hello world app but same problem above screenshot attached

/ Screenshot_2023-05-29-22-26-31-640_com example hello IMG-20230529-WA0007

hansarajgyaneswar commented 11 months ago

FATAL EXCEPTION: main Process: com.example.hello, PID: 4800 java.lang.NoClassDefFoundError: org.apache.cordova.PluginManager$$ExternalSyntheticLambda0 at org.apache.cordova.PluginManager.postMessage(PluginManager.java:355) at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:161) at org.apache.cordova.CordovaActivity.loadUrl(CordovaActivity.java:234) at com.example.hello.MainActivity.onCreate(MainActivity.java:40) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

hansarajgyaneswar commented 11 months ago

app not ruuning adroid 5 6 on e'4_WVGA_Nexus_S_Edited_API_23 [emulator-5554]'.

breautek commented 11 months ago

I did without any plugin I make simple hello world app but same problem above screenshot attached

/ Screenshot_2023-05-29-22-26-31-640_com example hello IMG-20230529-WA0007

The first screenshot does like the cordova hello world template. The second screenshot that says "App not installed." is not something cordova produces.

app not ruuning adroid 5 6 on e'4_WVGA_Nexus_S_Edited_API_23 [emulator-5554]'.

API 23 is not supported by the cordova framework so your mileage may vary if you try to force it (by overriding the android-minSdkVersion for example). On cordova-android@12, the minimum SDK is 24. For the purposes of figuring out the issue, we should be testing no earlier than API 24 to rule out the possibility that the problem is not a problem due to using an unsupported API.

FATAL EXCEPTION: main Process: com.example.hello, PID: 4800 java.lang.NoClassDefFoundError: org.apache.cordova.PluginManager$$ExternalSyntheticLambda0 at org.apache.cordova.PluginManager.postMessage(PluginManager.java:355) at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:161) at org.apache.cordova.CordovaActivity.loadUrl(CordovaActivity.java:234) at com.example.hello.MainActivity.onCreate(MainActivity.java:40) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

I've tested the hello world app with your plugins installed. API 24 works (as in it launches without issues) API 23 produces the above stacktrace. This is because API 23 doesn't have support for lambda functions on a collection.forEach API which the framework uses. As I mentioned before, the Cordova Framework supports API 24+. (See the PR and Mail Thread for the rationale behind bumping to API 24).

If you truly need API 23 support, you'll have to fork the cordova framework and refactor out anything that requires API 24+.

Note that I also did some testing on API 33 devices and some of your plugins doesn't appear to support API 31+ either (they require changes in their usage of PendingIntent). This includes

  1. cordova-plugin-admobpro which triggers a crash on startup because it needs to explicitly set a FLAG_MUTABLE or FLAG_IMMUTABLE on the PendingIntent it creates.
  2. cordova-plugin-upi also has the same issue on the version released to NPM, but it does appear to be fixed in their main branch.

None of the issues discovered are bugs with Cordova, so I'll be closing this issue.

hansarajgyaneswar commented 11 months ago

Simple hello world app not installing

hansarajgyaneswar commented 11 months ago

On Android 9

kosbar commented 9 months ago

But PluginManager has this code to prevent problems with Lambda (@breautek):

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                this.pluginMap.forEach((s, plugin) -> {
                    if (plugin != null) {
                        plugin.onMessage(id, data);
                    }
                });
            } else {
                for (CordovaPlugin plugin : this.pluginMap.values()) {
                    if (plugin != null) {
                        Object obj = plugin.onMessage(id, data);
                        if (obj != null) {
                            return obj;
                        }
                    }
                }
            }

We use cordova-android 11 with <preference name="android-minSdkVersion" value="21" /> Some time it works on 21 API (debug version from AS) sometimes crashes (cordova build debug with signature)...

breautek commented 9 months ago

But PluginManager has this code to prevent problems with Lambda (@breautek):

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                this.pluginMap.forEach((s, plugin) -> {
                    if (plugin != null) {
                        plugin.onMessage(id, data);
                    }
                });
            } else {
                for (CordovaPlugin plugin : this.pluginMap.values()) {
                    if (plugin != null) {
                        Object obj = plugin.onMessage(id, data);
                        if (obj != null) {
                            return obj;
                        }
                    }
                }
            }

We use cordova-android 11 with <preference name="android-minSdkVersion" value="21" /> Some time it works on 21 API (debug version from AS) sometimes crashes (cordova build debug with signature)...

cordova-android@12 has the check removed to simplify the codebase so it only has the lambda usage. Cordova-android@11 has the SDK version check to support both.

This is getting off-topic now so I'm locking the thread.

TL;DR; is don't use a minimum SDK less than 24 on cordova-android@12.