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

时间:2020-05-12 13:33:46

标签: android flutter gradle flutter-dependencies

我正在尝试将flutter模块添加为对我的Android项目的依赖。这是指南 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的远程服务器上不存在依赖关系,但是它存在于我的本地环境中,gradle应该从我的本地环境中获取它。请帮助我如何建立这个项目。

2 个答案:

答案 0 :(得分:1)

我有一个包含多个库模块和一个app模块的项目。我遇到了与想从我的一个库模块中启动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'
...
}

答案 1 :(得分:-1)

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

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

}

Picking a specific build type in a dependency