Flutter生成的Android项目集成Chaquopy后Gradle Sync失败求助
在Flutter生成的Android子项目中集成Chaquopy失败的问题
我在Flutter生成的Android项目里尝试使用Chaquopy插件,由于Chaquopy暂无Flutter直接支持,所以选择在Android子项目中集成。我已经逐行按照Chaquopy官方文档操作,但仍出现Gradle同步失败、无法下载Chaquopy插件的问题。以下是我的配置文件及错误日志,恳请帮忙排查(我是编程新手,对这类问题了解有限)。
Settings.gradle内容
include ':app' def localPropertiesFile = new File(rootProject.projectDir, "local.properties") def properties = new Properties() assert localPropertiesFile.exists() localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } def flutterSdkPath = properties.getProperty("flutter.sdk") assert flutterSdkPath != null, "flutter.sdk not set in local.properties" apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
项目级Build.gradle内容
buildscript { ext.kotlin_version = '1.6.10' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.2.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } plugins { id 'com.chaquo.python' version '12.0.1' apply false } allprojects { repositories { google() mavenCentral() } } rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { project.evaluationDependsOn(':app') } task clean(type: Delete) { delete rootProject.buildDir }
应用级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: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" plugins { id 'com.chaquo.python' } android { compileSdkVersion flutter.compileSdkVersion 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 applicationId "com.example.pyflut" minSdkVersion flutter.minSdkVersion targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName python { buildPython "C:/Users/super/AppData/Local/Programs/Python/Python310/python.exe" buildPython "C:/Users/super/AppData/Local/Programs/Python/Python310/python.exe", "-3.10" } } 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" }
错误信息
Build file 'F:\Pyflut\android\build.gradle' line: 14 Error resolving plugin [id: 'com.chaquo.python', version: '12.0.1', apply: false] > Could not resolve all dependencies for configuration 'detachedConfiguration1'. > Could not determine artifacts for com.chaquo.python:com.chaquo.python.gradle.plugin:12.0.1 > Could not get resource 'https://plugins.gradle.org/m2/com/chaquo/python/com.chaquo.python.gradle.plugin/12.0.1/com.chaquo.python.gradle.plugin-12.0.1.jar'. > Could not HEAD 'https://jcenter.bintray.com/com/chaquo/python/com.chaquo.python.gradle.plugin/12.0.1/com.chaquo.python.gradle.plugin-12.0.1.jar'. > Read timed out * Try: > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. * Exception is: org.gradle.api.GradleException: Error resolving plugin [id: 'com.chaquo.python', version: '12.0.1', apply: false] at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.resolveToFoundResult(DefaultPluginRequestApplicator.java:215)...... [因字符限制无法复制完整错误,若需要可提供]
解决步骤
修复插件仓库配置
错误显示Gradle尝试从已停止服务的JCenter下载插件,需在项目级build.gradle中明确指定插件仓库为MavenCentral:pluginManagement { repositories { gradlePluginPortal() mavenCentral() google() } } plugins { id 'com.chaquo.python' version '12.0.1' apply false }移除重复配置
应用级build.gradle的defaultConfig中重复设置了buildPython,保留一行即可:python { buildPython "C:/Users/super/AppData/Local/Programs/Python/Python310/python.exe" }检查网络连接
"Read timed out"说明网络请求超时,确保网络能正常访问Maven仓库,必要时切换网络或配置代理。清理Gradle缓存
删除项目根目录下的.gradle文件夹,重新执行Gradle同步,避免缓存干扰。
内容的提问来源于stack exchange,提问作者Noob Coder
相关产品推荐
相关产品推荐

