You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Chaquopy Flutter插件运行flutter run时遇插件应用失败错误求助

Chaquopy Flutter插件配置后构建失败求助

执行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

Gradle版本信息(./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

已按官方文档完成所有初始配置,但仍无法解决上述构建错误,寻求解决方案。


内容的提问来源于stack exchange,提问作者Alessio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 08:32:02