I have a Cordova (not Capacitor) Ionic 5 app which I have been working on for a while and built many times. To check something on another project; someone gave me a a project which required Capacitor to build. It seems Capacitor has no cli build function so I was required to upgrade Android Studio to build from there. That worked.
But now I can no longer build my original project. It does run fine in the browser however.
There are numerous pages of build errors but the most relevant samples seem to be these:
E:\www\sz.app\platforms\android\app\src\main\java\com\ionicframework\cordova\webview\IonicWebViewEngine.java:11: error: package android.support.annotation does not exist import android.support.annotation.RequiresApi;
Task :app:compileDebugJavaWithJavac FAILED E:\www\sz.app\platforms\android\app\src\main\java\com\ionicframework\cordova\webview\IonicWebViewEngine.java:137: error: cannot find symbol @RequiresApi(Build.VERSION_CODES.LOLLIPOP) ^ symbol: class RequiresApi location: class IonicWebViewEngine.ServerClient
E:\www\sz.app\platforms\android\app\src\main\java\plugin\google\maps\PluginMap.java:192: error: cannot find symbol boolean locationPermission = PermissionChecker.checkSelfPermission(cordova.getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) == PermissionChecker.PERMISSION_GRANTED; ^ symbol: variable PermissionChecker location: class PluginMap
E:\www\sz.app\platforms\android\app\src\main\java\plugin\google\maps\PluginLocationService.java:260: error: cannot find symbol public void onConnectionFailed(@NonNull ConnectionResult result) { ^ 24 actionable tasks: 1 executed, 23 up-to-date symbol: class NonNull
Execution failed for task ':app:compileDebugJavaWithJavac'.
Ionic:
Ionic CLI : 6.10.1 (C:\Users\Peter\AppData\Roaming\npm\node_modules@ionic\cli) Ionic Framework : @ionic/angular 5.1.1 @angular-devkit/build-angular : 0.901.6 @angular-devkit/schematics : 9.1.6 @angular/cli : 9.1.6 @ionic/angular-toolkit : 2.2.0
Capacitor:
Capacitor CLI : 2.1.0 @capacitor/core : 2.1.0
Cordova:
Cordova CLI : not installed Cordova Platforms : not available Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 9 other plugins)
Utility:
cordova-res : not installed native-run (update available: 1.0.0) : 0.2.8
System:
Android SDK Tools : 26.1.1 (C:\android-sdk) NodeJS : v12.18.2 (C:\Program Files\nodejs\node.exe) npm : 6.14.5 OS : Windows 7
This type of error occurs when an Android project contains references to both the AndroidX (Jetifier) library and its deprecated predecessor, the Android Support Library. In a Cordova project, this typically happens when some plugins have migrated to AndroidX and others are still using the Android Support Library.
First ensure AndroidX is enabled in your Cordova project.
Either make sure the Android platform is cordova-android@9
or install cordova-plugin-androidx into a cordova-android@8
project.
Then install cordova-plugin-androidx-adapter which will dynamically patch the source code of plugins to migrate from Android Support Library to AndroidX. Note this currently only works for Java and XML source files (not Kotlin or compiled libraries e.g. JAR or AAR).