DEV Community

Cover image for Flutter Fix Warning Mapping new ns to old ns
codebangkok
codebangkok

Posted on

3 2

Flutter Fix Warning Mapping new ns to old ns

Image description
Image description

ปัญหา: รัน Flutter โปรเจ็ค Android แล้วขึ้น warning

Flutter 2.10.3 | Dart 2.16.1 | DevTools 2.9.2

Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Enter fullscreen mode Exit fullscreen mode

สาเหตุ: โปรเจ็ค android ใช้ com.android.tools.build:gradle version 4.1.0

Image description

วิธีแก้ปัญหา: อัพเกรดไปใช้ com.android.tools.build:gradle verion 7.0.0 ขึ้นไป

1) ตรวจสอบเวอร์ชั่น com.android.tools.build:gradle ได้ที่ https://mvnrepository.com/artifact/com.android.tools.build/gradle?repo=google

Image description

2) แก้ไขได้ที่ไฟล์ android/build.gradle ผมเลือกใช้เป็น 7.1.2

Image description

3) เมื่อสั่ง flutter run ปัญหาต่อมา คือ ไฟล์ gradle ต้องใช้เวอร์ชั่น 7.2 ขึ้นไป (ปัจจุบันเป็น 6.7)

Image description

Image description

4) ตรวจสอบเวอร์ชั่นไฟล์ gradle ได้ที่ (ไม่ต้องดาวน์โหลดนะ) https://services.gradle.org/distributions

Image description

5) แก้ไขได้ที่ไฟล์ android/gradle/wrapper/gradle-wrapper.properties ผมเลือกเวอร์ชั่น 7.4.1

Image description

6) เมื่อสั่ง flutter run ปัญหาต่อมาก็คือ Environment Variable ที่ผมเคยใช้คือ ANDROID_SDK_HOME มัน deprecated ไม่สามารถใช้ได้แล้ว

Image description

7) ต้องไปเปลี่ยนให้ใช้ ANDROID_HOME แทนแค่ตัวเดียว (ตัวอย่างนี้ผมใช้ macOS) แก้ไขไฟล์ ~/.zshrc และต้องยกเลิกตัวอื่นที่ใช้ให้หมดด้วยนะ

export ANDROID_HOME=$HOME/Library/Android/sdk
# export ANDROID_SDK_HOME=$HOME/Library/Android/sdk
Enter fullscreen mode Exit fullscreen mode

8) ปิดแล้วเปิด vscode แล้วลองรัน flutter run อีกครั้งก็จะไม่มี warning แล้ว

Image description

ติดตามผลงานได้ที่

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay