android - 包 android.support.v4.content 不存在 flutter

标签 android android-studio flutter build.gradle flutter-dependencies

我在这里遇到了多个错误。请让我知道我做错了什么。 生成以下错误:

  C:\Users\Lenovo\flutter_windows_v1.2.1-stable\flutter\.pub-cache\hosted\pub.dartlang.org\fluttertoast-2.2.11\android\src\main\java\io\github\ponnamkarthik\toast\fluttertoast\FluttertoastPlugin.java:14: error: package android.support.v4.content does not exist
    import android.support.v4.content.ContextCompat;
                                     ^
    C:\Users\Lenovo\flutter_windows_v1.2.1-stable\flutter\.pub-cache\hosted\pub.dartlang.org\fluttertoast-2.2.11\android\src\main\java\io\github\ponnamkarthik\toast\fluttertoast\FluttertoastPlugin.java:107: error: cannot find symbol
              Drawable shapeDrawable = ContextCompat.getDrawable(ctx, R.drawable.toast_bg);
                                       ^
      symbol:   variable ContextCompat
      location: class FluttertoastPlugin
    2 errors

FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':fluttertoast:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.
* Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 6s

    The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility.
    [!] Flutter tried to create the file `android\settings_aar.gradle`, but failed.
    To manually update `settings.gradle`, follow these steps:
        1. Copy `settings.gradle` as `settings_aar.gradle`
        2. Remove the following code from `settings_aar.gradle`:
                def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
                def plugins = new Properties()
                def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
                if (pluginsFile.exists()) {
                    pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
                }
                plugins.each { name, path ->
                    def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
                    include ":$name"
                    project(":$name").projectDir = pluginDirectory
                }
    Please create the file and run this command again.

这是我的应用级 build.gradle

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 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.santosenoque.chatapp"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    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'
    implementation "com.android.support:support-v4:27.1.1"
    implementation 'com.google.firebase:firebase-core:17.2.2'
    implementation 'com.google.firebase:firebase-analytics:17.2.0'

}

apply plugin: 'com.google.gms.google-services'

这里是项目级的build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.2.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"


}
subprojects {
    project.evaluationDependsOn(':app')


}

task clean(type: Delete) {
    delete rootProject.buildDir
}

非常感谢任何帮助。

最佳答案

问题似乎与项目或插件未使用 Android X 有关。要检查 Flutter 项目是否使用 Android X,请按照此 guide 进行操作。从文档。如果 Flutter 项目还没有使用 Android X,请关注这个 migration guide .另一方面,如果插件导致问题,请尝试使用其最新版本并查看最新版本现在是否使用 Android X。

关于android - 包 android.support.v4.content 不存在 flutter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60175870/

相关文章:

android - Paytabs android 集成-程序类型已存在 : okhttp3. 身份验证器

firebase - 如何在 FutureBuilder Widget 的构建器函数中等待 - Flutter

flutter - 有没有办法自动将小部件包装在一行中

android - Ionic SQLite 数据库 - Android 上的默认位置

Android、Layout clicklistener和subview点击通过问题

java - startForegroundService() 没有调用 startForeground(),但它调用了

flutter - 验证成功时 TextField 显示错误

Android Studio 不渲染布局预览

android - 错误 : Execution failed for task app:mergeDebugResources

Android Studio : Unable to Start AVD