简体   繁体   English

Android项目中的Flutter子模块-未解析​​的包

[英]Flutter submodule in Android project - packages not resolved

I am trying to add a Flutter module to my Android project.我正在尝试将 Flutter 模块添加到我的 Android 项目中。 For that, I follow the relevant flutter docs , and everything seemingly works fine.为此,我遵循相关的颤振文档,一切似乎都很好。

However, when I run a Gradle sync after following all the steps in above link, the sync returns the following warnings但是,当我按照上述链接中的所有步骤运行 Gradle 同步时,同步会返回以下警告

Failed to resolve: io.flutter:flutter_embedding_debug:1.0.0-57d3bac3dd5cb5b0e464ab70e7bc8a0d8cf083ab
Failed to resolve: io.flutter:armeabi_v7a_debug:1.0.0-57d3bac3dd5cb5b0e464ab70e7bc8a0d8cf083ab
Failed to resolve: io.flutter:arm64_v8a_debug:1.0.0-57d3bac3dd5cb5b0e464ab70e7bc8a0d8cf083ab
Failed to resolve: io.flutter:x86_64_debug:1.0.0-57d3bac3dd5cb5b0e464ab70e7bc8a0d8cf083ab
Failed to resolve: io.flutter:x86_debug:1.0.0-57d3bac3dd5cb5b0e464ab70e7bc8a0d8cf083ab

It seems it cannot find some needed packages in any of the repositories I have specified.似乎在我指定的任何存储库中都找不到一些需要的包。 And indeed, I cannot use事实上,我不能使用

import io.flutter.embedding.android.FlutterFragment;

from my Android Java code.来自我的 Android Java 代码。

What repository do I have to specify to make sure the needed packages are found?我必须指定哪个存储库以确保找到所需的包?

Solution解决方案

I looked through a bunch of questions here on StackOverflow, but nothing seems to really match the problem I ran into.我在 StackOverflow 上查看了一堆问题,但似乎没有什么能真正符合我遇到的问题。 The closest would be this question , but its answer did not quite work in my case.最接近的是这个问题,但它的答案在我的情况下并不完全有效。

Instead I stumbled upon this blog post , where it is recommended to add the following repository:相反,我偶然发现了这篇博文,建议在其中添加以下存储库:

    repositories {
        ...
        maven { url "https://storage.googleapis.com/download.flutter.io" }
    }

In my case, I added the repository to settings.gradle in the host Android project (not in the one generated by Flutter).就我而言,我将存储库添加到主机 Android 项目中的settings.gradle (不是在 Flutter 生成的项目中)。 Where you add the repository may vary in your case, and I am not 100% confident that this is the best place.根据您的情况,您添加存储库的位置可能会有所不同,我不是 100% 确信这是最好的位置。

However, this indeed fixes the problem for me.但是,这确实为我解决了问题。 The packages are found, and I can use the Flutter module as expected.找到了包,我可以按预期使用 Flutter 模块。

Details细节

The repository mentioned in the SO question I mentioned above is accessed via http which may be an issue for some. 我上面提到的 SO 问题中提到的存储库是通过http访问的,这对某些人来说可能是个问题。 Accessing it with https give the following in Firefox:使用https访问它会在 Firefox 中提供以下内容:

Websites prove their identity via certificates. 
Firefox does not trust this site because it uses a certificate that is not valid for download.flutter.io. 
The certificate is only valid for the following names: 
*.storage.googleapis.com, *.googleapis.com, commondatastorage.googleapis.com, 
*.commondatastorage.googleapis.com, storage.googleapis.com, storage.mtls.googleapis.com,
 *.appspot.com.storage.googleapis.com, *.content-storage.googleapis.com, 
*.content-storage-p2.googleapis.com, *.content-storage-upload.googleapis.com, 
*.content-storage-download.googleapis.com, *.storage-upload.googleapis.com, 
*.storage-download.googleapis.com

This indicates to me that https://storage.googleapis.com/download.flutter.io is the correct URL to use for the Maven repository.这向我表明https://storage.googleapis.com/download.flutter.io是用于 Maven 存储库的正确 URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM