混合后运行报错

来源:4-5 Flutter工程创建及项目运行

慕工程2421507

2022-08-17

老师我把flutter引入后运行native程序报如下错误
Execution failed for task ‘:flutter:compileDebugLibraryResources’.

A failure occurred while executing com.android.build.gradle.tasks.CompileLibraryResourcesTaskCompileLibraryResourcesActionCouldnotisolatevaluecom.android.build.gradle.tasks.CompileLibraryResourcesTaskCompileLibraryResourcesAction Could not isolate value com.android.build.gradle.tasks.CompileLibraryResourcesTaskCompileLibraryResourcesActionCouldnotisolatevaluecom.android.build.gradle.tasks.CompileLibraryResourcesTaskCompileLibraryResourcesParams_Decorated@350ec077 of type CompileLibraryResourcesTask.CompileLibraryResourcesParams
Could not resolve all dependencies for configuration ‘:flutter:detachedConfiguration1’.
The project declares repositories, effectively ignoring the repositories you have declared in the settings.
You can figure out how project repositories are declared by configuring your build to fail on project repositories.
See https://docs.gradle.org/7.3.3/userguide/declaring_repositories.html#sub:fail_build_on_project_repositories for details.
Could not find com.android.tools.build:aapt2:7.2.1-7984345.
Searched in the following locations:
- https://storage.flutter-io.cn/download.flutter.io/com/android/tools/build/aapt2/7.2.1-7984345/aapt2-7.2.1-7984345.pom
If the artifact you are trying to retrieve can be found in the repository but without metadata in ‘Maven POM’ format, you need to adjust the ‘metadataSources { … }’ of the repository declaration.
Required by:
project :flutter


2: Task failed with an exception.

  • What went wrong:
    Execution failed for task ‘:flutter:compileDebugJavaWithJavac’.

Could not resolve all files for configuration ‘:flutter:debugCompileClasspath’.
Could not find androidx.lifecycle:lifecycle-common:2.2.0.
Required by:
Caused by: org.gradle.internal.snapshot.impl.IsolationException: Could not isolate value com.android.build.gradle.tasks.CompileLibraryResourcesTask$CompileLibraryResourcesParams_Decorated@350ec077 of type CompileLibraryResourcesTask.CompileLibraryResourcesParams

     project :flutter > io.flutter:flutter_embedding_debug:1.0.0-e85ea0e79c6d894c120cda4ee8ee10fe6745e187

Could not find androidx.lifecycle:lifecycle-common-java8:2.2.0.
Required by:
project :flutter > io.flutter:flutter_embedding_debug:1.0.0-e85ea0e79c6d894c120cda4ee8ee10fe6745e187
Could not find androidx.lifecycle:lifecycle-runtime:2.2.0.
Required by:
Caused by: org.gradle.api.internal.artifacts.configurations.ResolveExceptionWithHints: Could not resolve all dependencies for configuration ‘:flutter:detachedConfiguration1’.

     project :flutter > io.flutter:flutter_embedding_debug:1.0.0-e85ea0e79c6d894c120cda4ee8ee10fe6745e187

Could not find androidx.fragment:fragment:1.1.0.
Required by:
project :flutter > io.flutter:flutter_embedding_debug:1.0.0-e85ea0e79c6d894c120cda4ee8ee10fe6745e187
Could not find androidx.annotation:annotation:1.1.0.
Required by:
project :flutter > io.flutter:flutter_embedding_debug:1.0.0-e85ea0e79c6d894c120cda4ee8ee10fe6745e187
Could not find androidx.tracing:tracing:1.0.0.
Required by:
project :flutter > io.flutter:flutter_embedding_debug:1.0.0-e85ea0e79c6d894c120cda4ee8ee10fe6745e187
Could not find androidx.core:core:1.6.0.
Required by:
project :flutter > io.flutter:flutter_embedding_debug:1.0.0-e85ea0e79c6d894c120cda4ee8ee10fe6745e187
Could not find androidx.window:window-java:1.0.0-beta04.
Required by:
project :flutter > io.flutter:flutter_embedding_debug:1.0.0-e85ea0e79c6d894c120cda4ee8ee10fe6745e187
setti.gradle和app下的build。gradle如下

import org.gradle.api.initialization.resolve.RepositoriesMode

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()

    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
    repositories {
        google()
        mavenCentral()



    }
}
rootProject.name = "MyNative"
include ':app'
include ':flutter_module'
setBinding(new Binding([gradle: this]))
evaluate(new File(
        settingsDir.parentFile,
        'flutter_module/.android/include_flutter.groovy'// new
))
project(':flutter_module').projectDir = new File('../flutter_module')

plugins {
id 'com.android.application’
id ‘org.jetbrains.kotlin.android’
}
apply plugin: ‘kotlin-android’

android {
compileSdk 32

defaultConfig {
    applicationId "com.paladin.mynative"
    minSdk 23
    targetSdk 32
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
    repositories {maven {url("https://maven.aliyun.com/repository/google")}}
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = '1.8'
}
compileOptions{

    sourceCompatibility JavaVersion.VERSION_1_8

    targetCompatibility JavaVersion.VERSION_1_8

}

}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation project(':flutter')

}
repositories {
mavenCentral()
}


写回答

2回答

宝慕林9277168

2023-05-05

能问下 修改了flutter的sdk 中的哪个gradle 吗?

0
2
慕工程2421507
flutter/packages/flutter_tools/gradle/flutter.gradle 修改的这里面的
2023-07-04
共2条回复

学术袁

2022-08-19

可能是jdk、gradle版本问题导致的。
https://developer.android.google.cn/studio/releases/gradle-plugin?hl=zh-cn

0
3
慕工程2421507
回复
慕婉清3015855
抱歉才看到 我是修改的flutter/packages/flutter_tools/gradle/flutter.gradle把maven库指定里代理仓库就好了,看到你上面回复了 解决了就好 抱歉哈
2023-07-04
共3条回复

基于Flutter 3.x 实战跨平台仿抖音App混合开发

以短视频APP为例,快速上手原生/Flutter 混合开发

481 学习 · 120 问题

查看课程