我正在try 使用Chaquopy Ffltter插件.在所有初始设置报告here之后,我运行flutter run并得到以下错误:

Using hardware rendering with device sdk gphone64 x86 64. If you notice graphics artifacts, consider enabling software rendering with "--enable-software-rendering".
Launching lib/main.dart on sdk gphone64 x86 64 in debug mode...

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file '/home/alessio/.pub-cache/hosted/pub.dev/chaquopy-0.0.19/android/build.gradle' line: 28

* What went wrong:
A problem occurred evaluating project ':chaquopy'.
> Failed to apply plugin 'com.chaquo.python'.
   > Could not find matching constructor for: com.android.build.gradle.internal.api.DefaultAndroidSourceDirectorySet(String, org.gradle.api.internal.project.DefaultProject_Decorated, com.android.build.gradle.internal.api.artifact.SourceArtifactType$JAVA_SOURCES)

* 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.
==============================================================================

2: Task failed with an exception.
-----------
* Where:
Script '/home/alessio/snap/flutter/common/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 395

* What went wrong:
A problem occurred configuring project ':chaquopy'.
> Failed to notify project evaluation listener.
   > Could not find matching constructor for: com.android.build.gradle.internal.api.DefaultAndroidSourceDirectorySet(String, org.gradle.api.internal.project.DefaultProject_Decorated, com.android.build.gradle.internal.api.artifact.SourceArtifactType$JAVA_SOURCES)
   > Cannot invoke method substring() on null object
   > com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle

* 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 1s
Running Gradle task 'assembleDebug'...                           2,183ms
Exception: Gradle task assembleDebug failed with exit code 1

这是./gradlew --refresh-dependencies --warning-mode all的输出:

> Configure project :chaquopy
The RepositoryHandler.jcenter() method has been deprecated. This is scheduled to be removed in Gradle 8.0. JFrog announced JCenter's sunset in February 2021. Use mavenCentral() instead. Consult the upgrading guide for further information: https://docs.gradle.org/7.5/userguide/upgrading_version_6.html#jcenter_deprecation
        at build_8i1n964jy2rxqs9w3xv7zw649$_run_closure1$_closure2.doCall(/home/alessio/.pub-cache/hosted/pub.dev/chaquopy-0.0.19/android/build.gradle:8)
        (Run with --stacktrace to get the full stack trace of this deprecation warning.)

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file '/home/alessio/.pub-cache/hosted/pub.dev/chaquopy-0.0.19/android/build.gradle' line: 28

* What went wrong:
A problem occurred evaluating project ':chaquopy'.
> Failed to apply plugin 'com.chaquo.python'.
   > Could not find matching constructor for: com.android.build.gradle.internal.api.DefaultAndroidSourceDirectorySet(String, org.gradle.api.internal.project.DefaultProject_Decorated, com.android.build.gradle.internal.api.artifact.SourceArtifactType$JAVA_SOURCES)

* 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.
==============================================================================

2: Task failed with an exception.
-----------
* Where:
Script '/home/alessio/snap/flutter/common/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 395

* What went wrong:
A problem occurred configuring project ':chaquopy'.
> Failed to notify project evaluation listener.
   > Could not find matching constructor for: com.android.build.gradle.internal.api.DefaultAndroidSourceDirectorySet(String, org.gradle.api.internal.project.DefaultProject_Decorated, com.android.build.gradle.internal.api.artifact.SourceArtifactType$JAVA_SOURCES)
   > Cannot invoke method substring() on null object
   > com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle

* 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 15s

这是./gradlew help --scan:https://scans.gradle.com/s/nddzq6gl7fpy2产生的日志(log)

这是./gradlew -v的输出:

------------------------------------------------------------
Gradle 7.5
------------------------------------------------------------

Build time:   2022-07-14 12:48:15 UTC
Revision:     c7db7b958189ad2b0c1472b6fe663e6d654a5103

Kotlin:       1.6.21
Groovy:       3.0.10
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.6 (JetBrains s.r.o. 17.0.6+0-17.0.6b802.4-9586694)
OS:           Linux 5.15.0-78-generic amd64

这是我的前build.gradle名:

buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        google()
        mavenCentral()
        maven { url "https://chaquo.com/maven" }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.chaquo.python:gradle:14.0.2"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

这是我的android/app/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 plugin: 'com.chaquo.python'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    namespace "com.example.prova"
    compileSdkVersion localProperties.getProperty('flutter.compileSdkVersion').toInteger()
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.prova"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
        targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        ndk {
            abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
        }
    }

    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 {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

这是我的local.properties分:

sdk.dir=/home/alessio/Android/Sdk
flutter.sdk=/home/alessio/snap/flutter/common/flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.minSdkVersion=21
flutter.targetSdkVersion=34
flutter.compileSdkVersion=34

我不知道怎么修,如果你能帮我,我会很高兴的.

推荐答案

该错误要么是由于使用了不兼容的Chaquopy和Android Gradle插件版本,要么是Chaquopy插件错误检测到了Android插件的版本号.

这本身就是由于您的build.gradle文件版本号不匹配造成的:

        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath "com.chaquo.python:gradle:14.0.2"

...和Chaquopy Ffltter插件的build.gradle文件,其路径显示在上面的chaquopy-0.0.19以下:

        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "com.chaquo.python:gradle:12.0.0"

我能够通过编辑chaquopy-0.0.19 build.gradle文件来解决这个问题,如下所示:

  • 更新版本号以匹配您自己的build.gradle文件中的版本号.
  • minSdkVersion增加到21,以修复错误"此版本的Chaquopy需要minSdkVersion 21或更高版本".

这使得flutter run可以构建并运行your app.

(我是Chaquopy的开发者,正在积极维护.然而,Chaquopy Flutter插件是一个非官方的第三方项目,其开发人员已经停用了将近一年,所以我不推荐使用它.)

Flutter相关问答推荐

如何在应用栏中将列置于中心

如何创建一个按钮来在Ffltter Webview中转到上一页?

无法让Riverpod Stream发出新值

从外部类动态更改IconButton的图标

在背景图像上排列定位徽标

从图标启动器打开时,VSCode未检测到Web设备

当 Dart SDK 版本范围不匹配时,为什么依赖解析器不会抛出错误?

尽管海拔设置为 0,如何删除 appBar 下的下划线

Flutter 火焰相机抖动已弃用

来自服务器的数据未分配给变量

如何在Flutter中动态绘制一条从A点到B点的线?

PreferredSizeWidget类不能用作混合,因为它既不是混合类也不是混合

如何从sibling ChildWidgetB 触发 ChildWidgetA 中的操作

在 Flutter 中使用 HardwareKeyboard 时所有键都没有响应

type '({bool growable}) => List' 不是类型转换中类型 'List' 的子类型

SfCircularChart 周围的额外间距

如何在 flutter 中创建渐变按钮

如何在 flutter 中制作这种类型的扩展瓦片

有没有办法帮助我修复类型 null 不是 Map 类型的子类型?

如何从圆角go 除背景 colored颜色