首页 > 解决方案 > Flutter:无法使用 GradleScopeCompileServices.createGeneralCompileCaches() 创建 DefaultGeneralCompileCaches 类型的服务

问题描述

我是 Flutter 的新手,正处于学习阶段。我根据创建飞镖程序的演示创建了一个 Flutter 应用程序。当我运行初始程序时,它运行良好并且演示应用程序出现,但是当我更改并继续创建一些新程序时,它失败并出现主题错误。我在下面放置了 main.dart 和 gradle 属性和依赖项的代码。

 import 'package:flutter/material.dart';

 void main() {
   runApp(MyApp());
 }

 class MyApp extends StatelessWidget {
     @override
     Widget build(BuildContext context) {
        return MaterialApp(
        theme: ThemeData(primaryColor: Colors.purpleAccent),
        home: Scaffold(
            appBar: AppBar(title: Text("Word  Generator")),
    
        ),
     );
    }

  }

 dependencies:
 flutter:
   sdk: flutter


 # The following adds the Cupertino Icons font to your application.
 # Use with the CupertinoIcons class for iOS style icons.
 cupertino_icons: ^0.1.3

 org.gradle.jvmargs=-Xmx1536M
 android.enableR8=true
 #android.useAndroidX=true
 #android.enableJetifier=true

 Log for the error:
 C:\Git\flutter\wordpairgenerator>flutter run --enable-software-rendering
 Using software rendering with device SM G615FU. You may get better performance with hardware mode by 
 configuring hardware rendering for your device.
 Launching lib\main.dart on SM G615FU in debug mode...

 FAILURE: Build failed with an exception.

 * What went wrong:
 Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not create service of type DefaultGeneralCompileCaches using 
GradleScopeCompileServices.createGeneralCompileCaches().

* 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 49s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done                        57.5s
Exception: Gradle task assembleDebug failed with exit code 1

Log for the app ran correctly:
C:\Git\flutter\myapp>flutter run --enable-software-rendering
Using software rendering with device SM G615FU. You may get better performance with hardware mode by 
configuring hardware rendering for your device.
Launching lib\main.dart on SM G615FU in debug mode...
F/AdjustPurchase(12613): PRODUCTION: AdjustPurchase is running in production mode. Use this setting 
only for the build that you want to publish. Set the environment to `sandbox` if you want to test 
your app!
Running Gradle task 'assembleDebug'...

Running Gradle task 'assembleDebug'... Done                       123.6s (!)
√ Built build\app\outputs\apk\debug\app-debug.apk.
D/Surface (13245): Surface::connect(this=0xd0815400,api=2)
D/GraphicBuffer(13245): register, handle(0xe7f34100) (w:1080 h:1920 s:1088 f:0x4 u:0x000933)
Syncing files to device SM G615FU...
3,033ms (!)

标签: androidfluttergradleflutter-dependencies

解决方案


我最近遇到了这个问题,并通过更改android/gradle/wrapper/gradle-wrapper.properties文件中的 distributionUrl 来更新 gradle 文件,从而从这个问题中恢复过来

https://services.gradle.org/distributions/gradle-5.6.2-all.zip 到 https://services.gradle.org/distributions/gradle-6.1.1-all.zip

我等了一段时间才下载 gradle 文件,它对我来说很好,希望它对你也有帮助。


推荐阅读