android.support.v4.content和android.support.annotations不存在

时间:2019-07-14 07:42:43

标签: android ionic3

Ionic 3 android构建失败,并在IonicWebViewEngine.java和所有照相机Java文件(CameraLauncher.java,FileProvider.java等)上出错。

我尝试添加插件cordova-android-support-gradle-release和cordova-plugin-android-support-v4,但似乎没有任何效果。

请帮助!

如果我查看Android Studio SDK管理器-> SDK工具->支持存储库,我会看到已安装Android支持存储库47.0.0。

离子CLI:5.2.2 科尔多瓦CLI:9.0.0 Android SDK工具:26.1.1

下面是我的package.json

...
  "dependencies": {
    "@angular/animations": "5.2.9",
    "@angular/common": "5.2.9",
    "@angular/compiler": "5.2.9",
    "@angular/compiler-cli": "^8.0.2",
    "@angular/core": "5.2.9",
    "@angular/fire": "^5.2.1",
    "@angular/forms": "5.2.9",
    "@angular/http": "5.2.9",
    "@angular/platform-browser": "5.2.9",
    "@angular/platform-browser-dynamic": "5.2.9",
    "@ionic-native/app-center-crashes": "^5.8.0",
    "@ionic-native/camera": "^4.20.0",
    "@ionic-native/core": "4.12.0",
    "@ionic-native/dialogs": "^4.20.0",
    "@ionic-native/file": "^4.20.0",
    "@ionic-native/file-transfer": "^5.8.0",
    "@ionic-native/firebase": "^4.20.0",
    "@ionic-native/firebase-authentication": "^5.8.0",
    "@ionic-native/geolocation": "^4.20.0",
    "@ionic-native/in-app-browser": "^4.20.0",
    "@ionic-native/launch-navigator": "^4.20.0",
    "@ionic-native/native-geocoder": "^4.20.0",
    "@ionic-native/native-storage": "^4.20.0",
    "@ionic-native/network": "^4.20.0",
    "@ionic-native/push": "4.12.0",
    "@ionic-native/splash-screen": "^4.20.0",
    "@ionic-native/status-bar": "^4.20.0",
    "@ionic/pro": "1.0.20",
    "@ionic/storage": "2.1.3",
    "@types/google-maps": "^3.2.0",
    "angularfire2": "^5.2.1",
    "cordova": "^9.0.0",
    "cordova-android": "^8.0.0",
    "cordova-android-support-gradle-release": "^3.0.1",
    "cordova-ios": "5.0.1",
    "cordova-lib": "^9.0.1",
    "cordova-plugin-actionsheet": "^2.3.3",
    "cordova-plugin-add-swift-support": "^2.0.2",
    "cordova-plugin-android-support-v4": "^21.0.1",
    "cordova-plugin-androidx": "^1.0.2",
    "cordova-plugin-appcenter-crashes": "^0.3.5",
    "cordova-plugin-appcenter-shared": "^0.3.5",
    "cordova-plugin-camera": "^4.1.0",
    "cordova-plugin-cocoapod-supportx": "^1.7.3",
    "cordova-plugin-device": "^2.0.3",
    "cordova-plugin-dialogs": "^2.0.2",
    "cordova-plugin-file": "^6.0.2",
    "cordova-plugin-firebasex": "^3.0.8",
    "cordova-plugin-geolocation": "^4.0.2",
    "cordova-plugin-inappbrowser": "^3.1.0",
    "cordova-plugin-ionic-keyboard": "^2.1.3",
    "cordova-plugin-ionic-webview": "^2.5.1",
    "cordova-plugin-nativegeocoder": "^3.2.2",
    "cordova-plugin-nativestorage": "^2.3.2",
    "cordova-plugin-network-information": "^2.0.2",
    "cordova-plugin-splashscreen": "^5.0.3",
    "cordova-plugin-statusbar": "^2.4.3",
    "firebase": "^6.2.3",
    "font-awesome": "^4.7.0",
    "ionic-angular": "3.9.2",
    "ionic2-rating": "^1.2.2",
    "ionicons": "3.0.0",
    "moment": "^2.24.0",
    "promise-polyfill": "^8.1.2",
    "rxjs": "6.0.0",
    "rxjs-compat": "6.2.2",
    "sw-toolbox": "3.6.0",
    "uk.co.workingedge.phonegap.plugin.launchnavigator": "^5.0.4",
    "zone.js": "0.8.20"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.2.4",
    "typescript": "~2.6.2"
  },
  "description": "An Ionic project",
  "config": {
    "ionic_copy": "./scripts/custom.js"
  },
  "cordova": {
    "plugins": {
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-device": {},
      "cordova-plugin-dialogs": {},
      "cordova-plugin-ionic-webview": {
        "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
      },
      "cordova-plugin-appcenter-crashes": {},
      "cordova-plugin-inappbrowser": {},
      "cordova-plugin-geolocation": {
        "GEOLOCATION_USAGE_DESCRIPTION": "To locate you"
      },
      "cordova-plugin-network-information": {},
      "cordova-plugin-nativestorage": {},
      "cordova-plugin-file": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-statusbar": {},
      "uk.co.workingedge.phonegap.plugin.launchnavigator": {
        "GOOGLE_API_KEY_FOR_ANDROID": "AIzaSyDSvQ54fe0zoNTZ1EX-J4yUblacxWdKbds",
        "LOCATION_USAGE_DESCRIPTION": "This app requires access to your location for navigation purposes",
        "OKHTTP_VERSION": "3.12.0"
      },
      "cordova-plugin-nativegeocoder": {
        "LOCATION_WHEN_IN_USE_DESCRIPTION": "Use geocoder service"
      },
      "cordova-plugin-firebasex": {
        "IOS_FIREBASE_AUTH_VERSION": "5.20.2",
        "IOS_MIN_VERSION": "9.0",
        "IOS_FIREBASE_CORE_VERSION": "5.20.2",
        "IOS_FIREBASE_MESSAGING_VERSION": "5.20.2",
        "IOS_FIREBASE_PERFORMANCE_VERSION": "5.20.2",
        "IOS_FIREBASE_REMOTECONFIG_VERSION": "5.20.2",
        "IOS_FABRIC_VERSION": "1.9.0",
        "IOS_CRASHLYTICS_VERSION": "3.12.0",
        "IOS_STRIP_DEBUG": "false",
        "ANDROID_PLAY_SERVICES_TAGMANAGER_VERSION": "17.0.0",
        "ANDROID_FIREBASE_CORE_VERSION": "17.0.0",
        "ANDROID_FIREBASE_MESSAGING_VERSION": "19.0.0",
        "ANDROID_FIREBASE_CONFIG_VERSION": "18.0.0",
        "ANDROID_FIREBASE_PERF_VERSION": "18.0.0",
        "ANDROID_FIREBASE_AUTH_VERSION": "18.0.0",
        "ANDROID_CRASHLYTICS_VERSION": "2.10.1",
        "ANDROID_CRASHLYTICS_NDK_VERSION": "2.1.0",
        "ANDROID_SHORTCUTBADGER_VERSION": "1.1.22"
      },
      "cordova-android-support-gradle-release": {
        "ANDROID_SUPPORT_VERSION": "27.0.0"
      },
      "cordova-plugin-camera": {
        "ANDROID_SUPPORT_V4_VERSION": "27.+"
      },
      "cordova-plugin-android-support-v4": {}
    },
    "platforms": [
      "android",
      "ios"
    ]
  }
}

这些是我的构建错误:

BUILD FAILED in 4s
33 actionable tasks: 5 executed, 28 up-to-date
C:\projects\apps\ladder\platforms\android\gradlew: Command failed with exit code 1 Error output:
C:\projects\apps\ladder\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;
                                 ^
C:\projects\apps\ladder\platforms\android\app\src\main\java\org\apache\cordova\camera\CameraLauncher.java:40: error: package android.support.v4.content does not exist
import android.support.v4.content.FileProvider;
                                 ^
C:\projects\apps\ladder\platforms\android\app\src\main\java\org\apache\cordova\camera\CordovaUri.java:25: error: package android.support.v4.content does not exist
import android.support.v4.content.FileProvider;
                                 ^
C:\projects\apps\ladder\platforms\android\app\src\main\java\org\apache\cordova\camera\FileProvider.java:21: error: package android.support.v4.content does not exist
public class FileProvider extends android.support.v4.content.FileProvider {}
                                                            ^
C:\projects\apps\ladder\platforms\android\app\src\main\java\com\ionicframework\cordova\webview\IonicWebViewEngine.java:114: error: cannot find symbol
    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
     ^
  symbol:   class RequiresApi
  location: class IonicWebViewEngine.ServerClient
C:\projects\apps\ladder\platforms\android\app\src\main\java\org\apache\cordova\camera\CameraLauncher.java:303: error: cannot find symbol
        this.imageUri = new CordovaUri(FileProvider.getUriForFile(cordova.getActivity(),
                                                   ^
  symbol:   method getUriForFile(Activity,String,File)
  location: class FileProvider
C:\projects\apps\ladder\platforms\android\app\src\main\java\org\apache\cordova\camera\CameraLauncher.java:801: error: cannot find symbol
                        Uri tmpFile = FileProvider.getUriForFile(cordova.getActivity(),
                                                  ^
  symbol:   method getUriForFile(Activity,String,File)
  location: class FileProvider
C:\projects\apps\ladder\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePlugin.java:365: error: cannot find symbol
                    boolean areNotificationsEnabled = notificationManagerCompat.areNotificationsEnabled();
                                                                               ^
  symbol:   method areNotificationsEnabled()
  location: variable notificationManagerCompat of type NotificationManagerCompat
C:\projects\apps\ladder\platforms\android\app\src\main\java\org\apache\cordova\firebase\FirebasePluginMessagingService.java:144: error: constructor Builder in class Builder cannot be applied to given types;
            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId);
                                                             ^
  required: Context
  found: FirebasePluginMessagingService,String
  reason: actual and formal argument lists differ in length
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\projects\apps\ladder\platforms\android\app\src\main\java\org\apache\cordova\file\AssetFilesystem.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
9 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

2 个答案:

答案 0 :(得分:1)

请查看IonicWebViewEngine.java文件

main_root/plugins/cordova-plugin-ionic-webview/src/android/com/ionicframework/cordova/webview/IonicWebViewEngine.java

在第11行中,您将看到此代码

import android.support.annotation.RequiresApi;

请更改为:

import androidx.annotation.RequiresApi;

然后删除/添加Android平台,然后您就可以通过离子CLI命令行构建APK

答案 1 :(得分:0)

如果您在 config.xml 中使用 AndroidX = true 将 cordova-plugin-ionic-webview 升级到 5.0.0 也修复了它。