Cannot read property 'find' of null with cordova-android 11 in ionic 3

3.6k Views Asked by At

I have upgraded cordova-android to version 11 to support API Level 31 or above but when I'm creating build its giving error Cannot read property 'find' of null

I have done changes as suggested here Migrating to Cordova-Android 11 in Config.xml

        <preference name="AndroidWindowSplashScreenAnimatedIcon" value="resources/android/icon/drawable-xxxhdpi-icon.png" />

removed all <splash> tags and uninstalled

cordova-plugin-splashscreen

and

cordova-plugin-androidx-adapter

still getting the error , please help

6

There are 6 best solutions below

0
Riya Singh On

The problem seems to have been occurred with one of the plugins. I have faced this problem many a times, hence I always keep a backup of the entire project before any new plugin installation

performing the following tasks should help

cordova platform remove android

and then

cordova platform add android@latest

try with just android instead of @latest in case if you get the same error.

sometimes the json file stores the information and then never deletes it when you revoke the changes.

0
Cristian Zumelzu On

The are many problems when you are trying to update to cordova-android 11. I recommend you follow in detail step by step in this article for the proper upgrade https://ionic.zendesk.com/hc/en-us/articles/7891143965975-Migrating-to-Cordova-Android-11

Also I had to add "types": [] to the "compilerOptions" in tsconfig.js After this I solve my problems

0
Mister_CK On

Can you share the entire error? There are a few issues when upgrading to cordova-android-11 and also when upgrading to use targetSDK 31 (are you doing both at once? or were you already using targetSDK31?). This is a pretty standard error. Some things to check:

  • Have you upgraded to use java 11 (or higher), java 8 is deprecated.
  • Are you using Node 14 or higher? Node 12 is deprecated.
  • I believe you should run: npm i [email protected], because iOS still needs the plugin (it will not be added for android if you use this version tag).
  • I had to patch our cordova plugin qrScanner as it used the term 'compile', which changed to 'implementation'
  • I think using a png for your splashScreen icon won't scale to different devices. But I am not sure. (You can create an .XML from an .svg in android studio and use that instead).

If you can share more details, you can get some more precise advice.

0
Nicoz On

I've faced the same problem. As suggest here, it was caused by some plugins.

In my case, the plugins was : cordova-plugin-telerik-imagepicker phonegap-plugin-barcodescanner

They're not actually maintain anymore, so i had to use those forks, both for the same guy : https://github.com/geraldapeoples/phonegap-plugin-barcodescanner https://github.com/geraldapeoples/ImagePicker

It's not really a good practice to use forked plugin, but i can't found other working plugin that do the job properly, and don't have the time neither skill to dev a new one by myself.

Migrate to cordova-android 11 is not an easy path, but the doc advised above by Cristian Zumelzu cover most of the problems i met.

0
Raul On

im added this to my config.xml and it works!!

<platform name="android">
    ...
    <config-file parent="/resources" target="app/src/main/res/values/themes.xml">
         <style name="Theme.App.SplashScreen" parent="Theme.SplashScreen">
              <item name="windowSplashScreenBackground">#FFFFFF</item>
              <item name="windowSplashScreenAnimatedIcon">@drawable/notification_icon.png</item>
              <item name="windowSplashScreenBrandingImage">@drawable/notification_icon.png</item>
              <item name="windowSplashScreenIconBackgroundColor">#FFFFFF</item>
              <item name="windowSplashScreenAnimationDuration">1000</item>
              <item name="postSplashScreenTheme">@style/MyTheme</item>
         </style>
    </config-file>
    ...
</platform>
0
Cristian Zumelzu On

This problem usually is related after you update to cordova-android >=11.

Its happening because one of your plugins or in your config.xml you are defining some theme like.

<resources>
    <style name="MyTheme" parent="android:Theme.Holo.Light">
    </style>
</resources>

and now should be

        <config-file target="res/values/themes.xml" parent="/resources">
        <style name="MyTheme" parent="android:Theme.Holo.Light">
        </style>
    </config-file>

In specifically my case was the plugin cordova-plugin-telerik-imagepicker.

Is still not updated. You need to change this in the plugin.xml of the plugin (that make reference to the resource)

I created a fork with the last changes that allow to run the plugin on cordova-android 12 https://github.com/ZumelzuR/ImagePicker.git

Also there are a PR with this change.

Anyway this could happend with other plugins that you are using