找不到通过 Flutter 模块构建的本地 aar

Cannot find local aar built through Flutter Module

提问人:MXC 提问时间:5/12/2020 更新时间:3/17/2023 访问量:1708

问:

我正在尝试将 flutter 模块添加为我的 Android 项目的 aar 依赖项。以下是我能够生成本地 AAR https://flutter.dev/docs/development/add-to-app/android/project-setup#add-the-flutter-module-as-a-dependency 指南,我可以看到要完成的以下步骤:

 1. Open <host>/app/build.gradle
  2. Ensure you have the repositories configured, otherwise add them:

      repositories {
        maven {
            url '/Users/asharma/Documents/Flutter/animation_module/build/host/outputs/repo'
        }
        maven {
            url 'http://download.flutter.io'
        }
      }

  3. Make the host app depend on the Flutter module:

    dependencies {
      debugImplementation 'com.example.animation_module:flutter_debug:1.0
      profileImplementation 'com.example.animation_module:flutter_profile:1.0
      releaseImplementation 'com.example.animation_module:flutter_release:1.0
    }


  4. Add the `profile` build type:

    android {
      buildTypes {
        profile {
          initWith debug
        }
      }
    }

在我的 Android 项目中,我有模块和模块。我想把它包含在我的模块中,这是我的模块applibraryaarlibrarylibrarybuild.gradle

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles 'consumer-rules.pro'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        profile {
            initWith debug
        }
    }

}

dependencies {
    debugImplementation 'com.example.animation_module:flutter_debug:1.0'
    profileImplementation 'com.example.animation_module:flutter_profile:1.0'
    releaseImplementation 'com.example.animation_module:flutter_release:1.0'
}

repositories {
    maven {
        url '/Users/asharma/Documents/Flutter/animation_module/build/host/outputs/repo'
    }
    maven {
        url 'http://download.flutter.io'
    }
}

我还在我的项目的存储库中添加了内容。(尝试过有和没有它)但依赖关系不会得到解决。 我收到错误:mavenLocal()build.gradle

Could not find com.example.animation_module:flutter_debug:1.0.
Searched in the following locations:
  - https://dl.google.com/dl/android/maven2/com/example/animation_module/flutter_debug/1.0/flutter_debug-1.0.pom
  - https://dl.google.com/dl/android/maven2/com/example/animation_module/flutter_debug/1.0/flutter_debug-1.0.jar
  - https://jcenter.bintray.com/com/example/animation_module/flutter_debug/1.0/flutter_debug-1.0.pom
  - https://jcenter.bintray.com/com/example/animation_module/flutter_debug/1.0/flutter_debug-1.0.jar
Required by:
    project :app > project :animation_flutter_sdk

我知道远程 at 上不存在依赖关系,但它存在于我的本地,gradle 应该从我的本地获取它。请帮我如何构建这个项目。https://dl.google.com

android flutter gradle flutter-dependencies

评论

0赞 memres 6/2/2020
相同的层次结构。你找到解决方案了吗?
0赞 MXC 6/2/2020
不,我还没有找到解决方案。我开了一张票 github.com/flutter/flutter/issues/57020#issuecomment-627911003
0赞 memres 6/3/2020
我解决了我的问题。看看我的答案。

答:

2赞 memres 6/3/2020 #1

我有一个包含多个库模块和一个应用程序模块的项目。我遇到了同样的问题,因为我想从我的一个库模块启动 flutter 模块。

我通过添加来解决它

repositories {
maven {
    url '../path/to_your/flutter_repo'
}
maven {
    url 'https://storage.googleapis.com/download.flutter.io'
}

在应用程序模块和库模块中build.gradle

我不需要.mavenLocal()

我还需要添加

profile {
    initWith debug
}

在每个模块中。build.gradle

现在,我的应用模块和库模块是这样的:build.gradle

应用模块:build.gradle

plugins {
    id 'com.android.application'
}

repositories {
    maven {
        url '../core/webshop/flutter_repo'
    }
    maven {
        url 'https://storage.googleapis.com/download.flutter.io'
    }
}

android {
    compileSdkVersion toolVersions.compileSdk

    defaultConfig {
       ...
    }

    signingConfigs {
        release {
            ...
        }
    }

    buildTypes {
        release {
            ...
        }
        profile {
            initWith debug
        }
    }

    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // Project modules
    implementation project('your_lib_module1')
    implementation project('your_lib_module2')
    ...

}

库模块,其中要添加 flutter 模块:build.gradle

apply plugin: 'com.android.library'

repositories {
    maven {
        url './flutter_repo'
    }
    maven {
        url 'https://storage.googleapis.com/download.flutter.io'
    }
}

android {
    compileSdkVersion toolVersions.compileSdk

    defaultConfig {
        ...
    }

    buildTypes {
        release {
            ...
        }

        profile {
            initWith debug
        }
    }

    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // Project modules
    implementation project('your_lib_module3')

    // flutter
    debugImplementation 'com.example.animation_module:flutter_debug:1.0'
    profileImplementation 'com.example.animation_module:flutter_profile:1.0'
    releaseImplementation 'com.example.animation_module:flutter_release:1.0'
...
}
-2赞 zhy 11/5/2020 #2

我有同样的问题,通过设置配置来解决

android {
    buildTypes {
        release {
            ....
        }
        profile {
            ....
        }
        debug {
            ....
        }
    }
}

configurations {
    // Initializes a placeholder for the profileImplementation dependency configuration
    profileImplementation {}
}

dependencies {
        debugImplementation xxx
        // Then it can work
        profileImplementation xxx
        releaseImplementation xxx

}

在依赖项中选取特定的生成类型

评论

1赞 Tomerikoo 11/5/2020
不要复制粘贴和链接您自己的答案。如果您认为这个问题可以从与另一个问题完全相同的答案中受益 - 这可能表明该问题是重复的,应该被标记
0赞 rcorbellini 10/1/2021 #3

我有同样的问题并解决了它,在dependencyResolutionManagement内部的存储库中添加了它settings.gradle

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
    google()
    mavenCentral()
    maven {
        url '/yourpath/your_flutter_module/build/host/outputs/repo'
    }
    maven {
        url 'https://storage.googleapis.com/download.flutter.io'
    }
  }
}
1赞 Johnson Redonyx Silva 3/17/2023 #4

将存储库添加到 settings.gradle 中,如下所示 ->

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
    google()
    mavenCentral()
    
    maven {
        url '/Users/asharma/Documents/Flutter/animation_module/build/host/outputs/repo'
    }
    maven {
        url 'http://download.flutter.io'
    }
}

}