您必须了解问题不在于您的代码或项目,问题仅在于您的项目正在使用的插件,这正是为什么当我尝试将我的项目迁移到 AndroidX 我收到一条消息:
未找到 AndroidX 用法。
下面是解决此错误的步骤。
首先:您需要将此代码添加到您应用的gradle.build 文件中,在此路径android/app/gradle.build 中找到:
dependencies {
def core_version = "1.3.2"
// Java language implementation
implementation "androidx.core:core:$core_version"
// Kotlin
implementation "androidx.core:core-ktx:$core_version"
// To use RoleManagerCompat
implementation "androidx.core:core-role:1.0.0"
// To use the Animator APIs
implementation "androidx.core:core-animation:1.0.0-alpha02"
// To test the Animator APIs
androidTestImplementation "androidx.core:core-animation-testing:1.0.0-alpha02"
}
上面的代码只是改变了你要使用的 core.jar 版本。
第二:你需要到导致这个错误的插件文件夹,你可以通过阅读错误很容易知道是哪个插件导致了错误,下面是一个例子:
任务“:image_picker:compileDebugJavaWithJavac”执行失败。 >
无法解析所有文件以进行配置
':file_picker:debugCompileClasspath'。 > 找不到 core-1.1.0.jar
(androidx.core:core:1.1.0)。
现在您可以看到,image_picker 插件导致了错误。所以我们需要去这个插件的文件夹。
所有插件的文件夹都可以在这个路径中找到:%FLUTTER_SDK_PATH%\flutter\.pub-cache\hosted\pub.dartlang.org
只需将 %FLUTTER_SDK_PATH% 替换为您的 Flutter SDK 实际路径即可。
现在我们在这个文件夹中找到image_picker 文件夹。
第三:进入插件文件夹后,需要更改插件使用的core.jar文件的版本,方法如下:
您导航到插件文件夹中的 android 文件夹并打开 gradle.build 文件,在我的例子中是路径:%FLUTTER_SDK_PATH%\.pub-cache\hosted\pub.dartlang.org\image_picker-0.7.4\android
现在一直向下滚动,您会找到以下代码:
dependencies {
implementation 'androidx.core:core:1.1.0'
implementation 'androidx.annotation:annotation:1.0.0'
implementation 'androidx.exifinterface:exifinterface:1.3.0'
}
把implementation 'androidx.core:core:1.1.0'改成implementation 'androidx.core:core:1.3.2':
dependencies {
implementation 'androidx.core:core:1.3.2'
implementation 'androidx.annotation:annotation:1.0.0'
implementation 'androidx.exifinterface:exifinterface:1.3.0'
}
你就完成了。
请注意:
谢谢,我希望你们都没有错误的编码。