【问题标题】:How To Fix "Could not find core-1.1.0.jar (androidx.core:core:1.1.0)" Error. Flutter如何修复“找不到 core-1.1.0.jar (androidx.core:core:1.1.0)”错误。扑
【发布时间】:2021-07-05 01:54:33
【问题描述】:

每个开发人员都遇到过这种错误,尤其是使用这个特定的文件 core-1.1.0.jar。

问题是谷歌出于某种原因从它的服务器中删除了文件,因为整个错误是说它没有在网上的任何地方找到该文件。

网上有很多解决方案很遗憾不起作用,这些解决方案包括:

  • 将您的项目迁移到 AndroidX。
  • 降级 gradle 插件版本。
  • 在 AndroidManifest.xml 文件中使用一些权限。
  • 降级 Flutter 版本。
  • 使用 JCenter() 和 google() 存储库。

等等……你懂的。

下面我将分享我如何修复此错误的经验。

【问题讨论】:

    标签: flutter gradle android-gradle-plugin flutter-dependencies gradle-plugin


    【解决方案1】:

    您必须了解问题不在于您的代码或项目问题仅在于您的项目正在使用的插件,这正是为什么当我尝试将我的项目迁移到 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'
        }
    

    你就完成了。

    请注意:

    • 我首先尝试了上面提到的所有解决方案,最后一次尝试是编辑插件的文件。

    • 我所做的编辑对插件没有任何影响。

    • 我上一步使用的core.jar文件版本必须和第一步指定的core.jar版本一致。

    谢谢,我希望你们都没有错误的编码。

    【讨论】:

    • 很高兴能够帮助@MajdAlbaho
    猜你喜欢
    • 2022-06-14
    • 1970-01-01
    • 1970-01-01
    • 2017-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 2019-04-04
    相关资源
    最近更新 更多