ใช้ Github Repository ติดตั้ง Dependency ส่วนตัว

Darthnot
Mintelligence
Published in
1 min readMay 30, 2024

ในแต่ละโปรเจคจะมีการใช้ Dependency มากมายเพื่ออำนวยความสะดวกในการพัฒนาแอพพิเคชั่น ซึ่งบาง Dependency อาจจะไม่ได้ใช้ผลลัพธ์ที่เราต้องการ จะให้เขียนใหม่ตั้งแต่คนก็เสียเวลาหรือบางครั้งอาจจะมีการชนกันของเวอร์ชั่น Dependency

In Flutter Example

dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.6
path_provider: ^2.1.0
flick_video_player: ^0.6.0
package_info_plus: ^4.1.0
file_picker: ^5.2.10

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^3.0.0

จาก Dependency ข้างบนจะติดตั้งไม่ผ่านเพราะ

Resolving dependencies...
Because wakelock_windows >=0.2.1 depends on win32 ^3.0.0 and wakelock_windows <0.2.1 depends on win32 ^2.0.0, every version of wakelock_windows requires win32 ^2.0.0 or ^3.0.0.
And because package_info_plus >=4.0.1 depends on win32 >=4.0.0 <6.0.0, package_info_plus >=4.0.1 is incompatible with wakelock_windows.
And because flick_video_player >=0.6.0 <0.8.0 depends on wakelock ^0.6.2 which depends on wakelock_windows ^0.2.0, package_info_plus >=4.0.1 is incompatible with flick_video_player >=0.6.0 <0.8.0.
So, because flutter_test_decendency depends on both flick_video_player ^0.6.0 and package_info_plus ^4.1.0, version solving failed.

มีการชนกันของเวอร์ชัน wakelock, win32 ทำให้ไม่สามารถติดตั้งได้

จริงๆ มีวิธีแก้ควรจะแก้ไขคือรายงานไปที่เจ้าของ Repo ให้มีการอัพเดทเวอร์ชันแต่หลายๆครั้งเจ้าของ Repo ไม่ว่างแก้ให้หรือแก้ก็ใช้เวลานาน

วิธีที่แนะนำคือ Fork Repository ออกมาแก้ไขหรือถ้าโชคดีอาจจะมีคนที่เจอปัญหาเดียวกันแก้ให้ ซึ้งเรามาสามารถนำ Repository นั้นมาทำการติดตั้งได้โดยตรง

dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.6
path_provider: ^2.1.0
flick_video_player:
git: https://github.com/h1amza/flick-video-player.git
package_info_plus: ^4.1.0
file_picker: ^5.2.10

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^3.0.0

จะเห็นว่าเราสามารถใช้ Repository link ในการติดตั้งได้โดยตรง

Got dependencies!
12 packages have newer versions incompatible with dependency constraints.
Try `flutter pub outdated` for more information.

สามารถใช้วิธีนี้ใน Node ได้เช่นกัน : Link

--

--