【问题标题】:Project won't compile because of Android X由于 Android X,项目无法编译
【发布时间】:2019-03-29 12:43:50
【问题描述】:

我在 Github 上克隆了一个 project。它使用不同的插件。

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: 0.1.2
  firebase_auth: 0.7.0
  google_sign_in: 3.2.4
  cloud_firestore: 0.8.2+3
  image_picker: 0.4.12+1
  shared_preferences: 0.4.3
  firebase_storage: 1.0.4
  cached_network_image: 0.7.0
  intl: 0.15.7

有博客post 建议保持版本相同。我的问题是 image_picker 插件。环顾stackoverflow,如果您不想将应用程序迁移到Android X,它建议使用版本0.4.12+1。这是我的错误

/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java:8: error: package android.support.annotation does not exist
import android.support.annotation.VisibleForTesting;
                                 ^
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:15: error: package android.support.annotation does not exist
import android.support.annotation.VisibleForTesting;
                                 ^
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java:40: error: cannot find symbol
  @VisibleForTesting
   ^
  symbol:   class VisibleForTesting
  location: class ImagePickerPlugin
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:68: error: cannot find symbol
  @VisibleForTesting static final int REQUEST_CODE_CHOOSE_IMAGE_FROM_GALLERY = 2342;
   ^
  symbol:   class VisibleForTesting
  location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:69: error: cannot find symbol
  @VisibleForTesting static final int REQUEST_CODE_TAKE_IMAGE_WITH_CAMERA = 2343;
   ^
  symbol:   class VisibleForTesting
  location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:70: error: cannot find symbol
  @VisibleForTesting static final int REQUEST_EXTERNAL_IMAGE_STORAGE_PERMISSION = 2344;
   ^
  symbol:   class VisibleForTesting
  location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:71: error: cannot find symbol
  @VisibleForTesting static final int REQUEST_CAMERA_IMAGE_PERMISSION = 2345;
   ^
  symbol:   class VisibleForTesting
  location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:72: error: cannot find symbol
  @VisibleForTesting static final int REQUEST_CODE_CHOOSE_VIDEO_FROM_GALLERY = 2352;
   ^
  symbol:   class VisibleForTesting
  location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:73: error: cannot find symbol
  @VisibleForTesting static final int REQUEST_CODE_TAKE_VIDEO_WITH_CAMERA = 2353;
   ^
  symbol:   class VisibleForTesting
  location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:74: error: cannot find symbol
  @VisibleForTesting static final int REQUEST_EXTERNAL_VIDEO_STORAGE_PERMISSION = 2354;
   ^
  symbol:   class VisibleForTesting
  location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:75: error: cannot find symbol
  @VisibleForTesting static final int REQUEST_CAMERA_VIDEO_PERMISSION = 2355;
   ^
  symbol:   class VisibleForTesting
  location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:77: error: cannot find symbol
  @VisibleForTesting final String fileProviderName;
   ^
  symbol:   class VisibleForTesting
  location: class ImagePickerDelegate
/Users/gerardhorgan/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.4.12+1/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerDelegate.java:164: error: cannot find symbol
  @VisibleForTesting
   ^
  symbol:   class VisibleForTesting
  location: class ImagePickerDelegate
13 errors

FAILURE: Build failed with an exception.

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

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.



BUILD FAILED in 2s
*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.

*******************************************************************************************
Finished with error: Gradle task assembleDebug failed with exit code 1

我想知道是什么原因导致不兼容导致我的应用无法编译?

【问题讨论】:

    标签: flutter androidx


    【解决方案1】:

    你需要为AndroidX compatibility流文档

    【讨论】:

    • 我看过那个文件。有一个名为避免 Android X 的部分。他们在其中提供插件依赖项版本以固定在您的 pubspec.yaml 中。我已经固定了推荐的版本。即图像选择器:0.4.12+1
    【解决方案2】:

    最好的选择是为 androidX 迁移应用程序。按照android-studio中的步骤操作:

    1) 删除 pubspec 文件的所有依赖项并运行 flutter packages get

    2) 在 android-studio 中仅打开您应用的 android 模块。你可以通过右键单击你的项目根目录>flutter>在android studio中打开android模块来做到这一点

    3) 在 android-studio 菜单中仅打开 android 模块后,转到 Refactor > MigrateToAndoridX...

    4) 进行迁移!

    5) 关闭android模块android-studio实例并返回你的flutter项目

    6) 将所有依赖项插入 pubspec 文件并运行 flutter packages get

    【讨论】:

      【解决方案3】:

      使用image_picker: ^0.6.6+1并添加AndroidManifest.xml如下:

      <uses-permission android:name="android.permission.INTERNET"/>
      

      这种方法对我有用!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多