无法确定任务':app:compileDebugJavaWithJavac'的依赖关系

时间:2020-10-02 15:54:17

标签: android-studio flutter dart flutter-layout

Flutter在以前的设备上运行良好。我已经更换了笔记本电脑,在完成所有设置后,出现此错误,我无法理解此错误。

  1. 请解释此错误的原因。

  2. 此错误的解决方案

我只是在运行非常基本的应用程序。

app 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"
> 
> android {
>     compileSdkVersion 29
> 
>     sourceSets {
>         main.java.srcDirs += 'src/main/kotlin'
>     }
> 
>     lintOptions {
>         disable 'InvalidPackage'
>     }
> 
>     defaultConfig {
>         // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
>         applicationId "com.example.flutter_app"
>         minSdkVersion 16
>         targetSdkVersion 29
>         versionCode flutterVersionCode.toInteger()
>         versionName flutterVersionName
>     }
> 
>     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" }

android gradle

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

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

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
}

Logcat: 请配置Android SDK

终端报告

 C:\Users\HP\StudioProjects\flutter_app>flutter run
    Using hardware rendering with device sdk gphone x86. If you notice graphics artifacts, consider enabling software rendering with "--enable-software-rendering".
    Launching lib\main.dart on sdk gphone x86 in debug mode...
    Checking the license for package Android SDK Build-Tools 28.0.3 in C:\Users\HP\AppData\Local\Android\sdk\licenses
    Warning: License for package Android SDK Build-Tools 28.0.3 not accepted.
    Checking the license for package Android SDK Platform 29 in C:\Users\HP\AppData\Local\Android\sdk\licenses
    Warning: License for package Android SDK Platform 29 not accepted.
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
    > Failed to install the following Android SDK packages as some licences have not been accepted.
         build-tools;28.0.3 Android SDK Build-Tools 28.0.3
         platforms;android-29 Android SDK Platform 29
      To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
      Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html
    
      Using Android SDK: C:\Users\HP\AppData\Local\Android\sdk
    
    * 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'...
    Running Gradle task 'assembleDebug'... Done                         2.5s
    Exception: Gradle task assembleDebug failed with exit code 1

扑打医生-V

[√] Flutter (Channel stable, 1.22.0, on Microsoft Windows [Version 10.0.18362.1082], locale en-US)
    • Flutter version 1.22.0 at C:\src\flutter
    • Framework revision d408d302e2 (4 days ago), 2020-09-29 11:49:17 -0700
    • Engine revision 5babba6c4d
    • Dart version 2.10.0


[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at C:\Users\HP\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

[√] Android Studio (version 4.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 50.0.1
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.49.2)
    • VS Code at C:\Users\HP\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.14.1

[√] Connected device (1 available)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)

! Doctor found issues in 1 category.

3 个答案:

答案 0 :(得分:2)

运行此命令以接受来自Android的所有许可证。 flutter doctor --android-licenses并从Android Studio下载sdk管理器和构建工具

答案 1 :(得分:0)

这里是主要问题

无法安装以下 Android SDK 包,因为某些许可未被接受。 构建工具;28.0.3 Android SDK 构建工具 28.0.3 平台;android-29 Android SDK 平台 29

如错误提示,首先通过运行以下命令接受所有许可

flutter doctor --android-licenses

接下来转到 https://androidsdkmanager.azurewebsites.net/Buildtools 并下载与您在本例中缺少的构建工具 28.0.3 相对应的构建工具 下载后将 zip 文件解压缩到 C:\Android\Sdk\build-tools\28.0.3(如果您使用的是 Windows 和 /Library/Android/sdk/build-tools/28.0)。 3如果您使用的是 mac

最后,如果您使用的是 mac 或 ,请从 https://androidsdkmanager.azurewebsites.net/SDKPlatform 下载缺少的 Android SDK 平台 29 并将其解压缩到 /Library/Android/sdk/platforms/android-29 C:\Android\Sdk\platforms\android-29 如果你在 windows 上

运行您的项目(flutter run)并享受

答案 2 :(得分:0)

显然,您可以做的只是前往您的 Android SDK 目录 和

cd "/tools/bin"

并运行以下命令

 sdkmanager --licenses

让终端完成它的工作!