android - 找不到通过 Flutter Module 构建的本地 aar

标签 android flutter gradle flutter-dependencies

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

 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 项目中,我有 app模块和 library模块。我想包括这个aar在我的library模块,这是我的library模块 build.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

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

最佳答案

我有一个包含几个库模块和一个应用程序模块的项目。我遇到了同样的问题,因为我想从我的一个库模块启动 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')
    ...

}

图书馆模块build.gradle ,您要在其中添加 flutter 模块:
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'
...
}

关于android - 找不到通过 Flutter Module 构建的本地 aar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61753081/

相关文章:

android - 无法解析 android.arch.lifecycle :extensions:1. 1.0

testing - 如何在 Flutter 中为多个测试提供 `setUp` 和 `WidgetTester`

flutter - 如何在通知消息中显示多于一行(flutter_local_notifications程序包)

java - 是否可以从 Gradle 依赖项修改 Android Studio 中库文件的源代码

gradle - 如何使用 Gradle 复制配置文件

java - RxJava Android 压缩许多不同类型的请求

Android Multitouch - 可以在模拟器中测试吗?

dart - 完成小部件动画后,在 Flutter 中运行一个函数

java - Gradle:同一项目中的 Java 和 Android 子项目

java - 将按钮值切换为整数