錯誤描述:
D:\Program Files\flutter\.pub-cache\hosted\pub.flutter-io.cn\image_picker-0.6.7+14\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerPlugin.java:15: 錯誤: 找不到符號
import androidx.lifecycle.DefaultLifecycleObserver;
^
符號: 類 DefaultLifecycleObserver
位置: 程序包 androidx.lifecycle
D:\Program Files\flutter\.pub-cache\hosted\pub.flutter-io.cn\image_picker-0.6.7+14\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerPlugin.java:33: 錯誤: 找不到符號
implements Application.ActivityLifecycleCallbacks, DefaultLifecycleObserver {
^
符號: 類 DefaultLifecycleObserver
位置: 類 ImagePickerPlugin
解決方案:
imagepicker插件目錄android\build.gradle中添加如下行
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 16
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'InvalidPackage'
}
dependencies {
implementation 'androidx.core:core:1.0.2'
implementation 'androidx.annotation:annotation:1.0.0'
implementation 'androidx.exifinterface:exifinterface:1.3.0'
implementation "androidx.lifecycle:lifecycle-common-java8:2.2.0" //新增
}
}
來源:android - androidx.lifecycle..DefaultLifecycleObserver not found - Stack Overflow