【问题标题】:Use maven module in Android Studio在 Android Studio 中使用 maven 模块
【发布时间】:2016-01-28 15:21:04
【问题描述】:

我在我的 android studio 中有一个 android 项目 (gradl),我有一个 maven 模块,我想在我的 android 项目中使用。结构如下:

  • Android 项目 (gradle)
    • 子项目(gradle)
    • --build.gradle
    • MyFancyStuff (gradle)
    • -- ...
    • build.gradle
    • settings.gradl
  • 共享模型(Maven 项目)
    • pom.xml
    • ...

现在我将我的settings.gradle 调整如下:

include ':MyFancyStuff',':shared-models'
project(':shared-models').projectDir = new File('../shared-models')

我从其他几个 stackoverflow 主题中得到了这个。

现在是子项目的build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'MyFancyStuff:MyFancyStuff-debug@aar'
    compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.0'
    compile 'com.sun.jersey:jersey-client:1.9.1'
    compile 'com.google.code.gson:gson:1.7.2'
    compile project(':shared-models')
}

repositories{
    flatDir{
        dirs 'libs'
    }
    ivy {
        url "../shared-models"
    }
}

现在我收到以下错误:

错误:找不到名为“默认”的配置。

基于stackoverflow上的其他线程,不知道是什么问题...

【问题讨论】:

    标签: android maven gradle android-gradle-plugin


    【解决方案1】:

    错误:找不到名称为“默认”的配置。

    这意味着 Gradle 正在寻找模块(或 build.gradle)文件,但没有找到。

    在您的情况下,问题应该是共享模型,它是一个 Maven 项目 pom.xml 而不是 build.gradle 文件。

    Gradle 不提供解析 POM 文件的原生支持,但 Groovy 的 XmlSlurper 使 XML 解析变得简单方便。
    还要检查这个link

    【讨论】:

    【解决方案2】:

    只是为了回答我自己的问题,以防万一有人也需要这个。 maven项目可以用mvn install本地安装。

    之后可以加载项目,但需要包含本地存储库

    repositories {
        mavenLocal()
    }
    

    然后,可以在依赖项部分中加载依赖项,例如

    dependencies {
       ....
        compile 'groupId:artifactId:version'
       ....
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-24
      • 1970-01-01
      • 2019-11-05
      • 2015-10-06
      相关资源
      最近更新 更多