【问题标题】:Mapbox using flutter使用颤振的地图框
【发布时间】:2019-04-11 15:09:54
【问题描述】:

我想用flutter集成mapbox 我正在做的只是在 pubsec.yaml 中安装我的 sdk 并将访问令牌放在 Android Manifest 文件和 Info.plist 中

这是我添加 mapbox_gl 的 pubsec.yaml

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  mapbox_gl: ^0.0.3

我还没有在 dart 文件中添加任何代码,只是尝试运行应用程序,但它给了我错误

/flutter/.pub-cache/hosted/pub.dartlang.org/mapbox_gl-0.0.3/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java:16: error: cannot find symbol
import androidx.annotation.NonNull;
                          ^
  symbol:   class NonNull
  location: package androidx.annotation
/flutter/.pub-cache/hosted/pub.dartlang.org/mapbox_gl-0.0.3/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java:130: error: cannot find symbol
  private static String getAccessToken(@NonNull Context context) {
                                        ^
  symbol:   class NonNull
  location: class MapboxMapController
/flutter/.pub-cache/hosted/pub.dartlang.org/mapbox_gl-0.0.3/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java:298: error: cannot find symbol
  private void enableLocationComponent(@NonNull Style style) {
                                        ^
  symbol:   class NonNull
  location: class MapboxMapController
/flutter/.pub-cache/hosted/pub.dartlang.org/mapbox_gl-0.0.3/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java:315: error: cannot find symbol
  private void enableSymbolManager(@NonNull Style style) {
                                    ^
  symbol:   class NonNull
  location: class MapboxMapController
/flutter/.pub-cache/hosted/pub.dartlang.org/mapbox_gl-0.0.3/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java:326: error: cannot find symbol
  private void enableLineManager(@NonNull Style style) {
                                  ^
  symbol:   class NonNull
  location: class MapboxMapController
/flutter/.pub-cache/hosted/pub.dartlang.org/mapbox_gl-0.0.3/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java:333: error: cannot find symbol
  private void enableCircleManager(@NonNull Style style) {
                                    ^
  symbol:   class NonNull
  location: class MapboxMapController
/flutter/.pub-cache/hosted/pub.dartlang.org/mapbox_gl-0.0.3/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java:556: error: cannot find symbol
  public boolean onMapClick(@NonNull LatLng point) {
                             ^
  symbol:   class NonNull
  location: class MapboxMapController
/flutter/.pub-cache/hosted/pub.dartlang.org/mapbox_gl-0.0.3/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java:286: error: cannot find symbol
    public void onStyleLoaded(@NonNull Style style) {
                               ^
  symbol: class NonNull
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
8 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':mapbox_gl: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 4s
*******************************************************************************************
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

感谢任何帮助。

【问题讨论】:

  • 你能给我看看 pubsec.yaml。
  • 你是如何添加 mapbox gl

标签: flutter mapbox-gl


【解决方案1】:

这是一个 AndroidX 兼容性问题。

将此添加到您的 android/gradle.properties 并尝试再次构建:

android.enableJetifier=true
android.useAndroidX=true

(Official docs about AndroidX migration on Flutter)

【讨论】:

    猜你喜欢
    • 2021-01-26
    • 1970-01-01
    • 2018-10-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-19
    • 2021-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多