android - Android 上的 Flutter 编译错误:找不到 com.android.support:support-v4:27.0.3
问题描述
我在 Flutter 中编写了一个应用程序,并且在模拟器和设备上的 iOS 上运行它都没有问题。但是,我在使用 Android 时遇到问题。我来自 iOS 和网络背景,所以可能是我缺乏 Android 知识给我带来了问题。
我按照 Flutter Docs 中的说明安装了 Android Studio 并将 ANDROID_HOME 添加到我的 PATH 和 bash 配置文件中。
我运行 Android Studio 并选择将 Android SDK 安装到连接的 USB 驱动器(格式化为 HFS+ Mac OS 扩展(日志式)卷)。我不认为这应该给我带来问题。
怎么了:
我使用成功启动了 Android 模拟器
颤振模拟器——启动 Nexus_5X_API_28_x86
我键入
扑跑
然后看到以下输出:
Using hardware rendering with device Android SDK built for x86. If you get graphics artifacts, consider enabling software rendering with "--enable-software-rendering".
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle... 1.0s
Resolving dependencies... 19.0s
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':app:debugCompileClasspath'.
> Could not find com.android.support:support-v4:27.0.3.
这是整个错误的屏幕截图:
这是我在 android/app 中的 build.grade:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 27
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "HIDDEN"
minSdkVersion 26
targetSdkVersion 27
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
这是 android 文件夹中的 build.gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "27.0.3"
}
}
}
}
这是 android/app/src/main 中的 AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="HIDDEN">
<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="HIDDEN"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
这是 Android Studio 中的 SDK 管理器正确显示 SDK 路径和已安装的 SDK。
项目中的所有插件都是最新的。
我觉得我可能在这里遗漏了一些明显的东西,因为这只是在谈论无法通过外观找到文件。
非常感谢任何帮助。
解决方案
推荐阅读
- android - 将动画翻译到Android屏幕的中心
- kubernetes - 使用 Rancher 管道将 docker 镜像推送到私有存储库
- apache-poi - 阿帕奇 POI 4.1。XSSF 合并单元格边框
- c# - 在 Windows 上运行但不在 Linux 上运行的 Dot Net Core 便携式应用程序
- firebase - 如何在 Flutter 中为 Firebase 连接设置监听器?
- sql-server - 使用标量函数的 SQL Server 查询在 FireDAC 上非常慢,并且仅在 FireDAC 上
- mysql - 将不同表中的值相乘
- python - python django在后端获取html标签ID
- swift - 如何使视图与其内容一样高
- android - 超过 1 +1/2 个月我的应用没有投放广告,出现错误 I/Ads: Ad failed to load : 3