Android Studio仅支持一个settings.gradle?

时间:2015-06-09 21:01:56

标签: java android android-studio gradle

我有以下项目结构:

- my-base
- my-main
- my-Android

my-main使用my-basemy-Android使用我的my-main

以下是build.gradle个文件。

my-base build.gradle

apply plugin: 'java'
apply plugin: 'eclipse'

sourceCompatibility = 1.7
version = '1.0'

repositories {
  mavenCentral()
}

dependencies {
}

jar {
  from sourceSets.main.allSource
}

task sourcesJar(type: Jar, dependsOn: classes) {
  description "Create source jar."
  classifier = 'sources'
  from(sourceSets.main.allSource) {
    exclude '**/*processor*'
  }
}

task javadocJar(type: Jar, dependsOn: javadoc) {
  description "Create javadocs."
  classifier = 'javadoc'
  from javadoc.destinationDir
}

artifacts {
  archives sourcesJar
} 

my-main build.gradle

apply plugin: 'java'
apply plugin: 'apt'
apply plugin: 'eclipse'

sourceCompatibility = 1.7
version = '1.0'

eclipse {
  classpath {
     downloadSources=true
     downloadJavadoc=true
  }
}

buildscript {
  repositories {
    mavenCentral()
    jcenter()
    maven {
      url "https://oss.sonatype.org/content/repositories/snapshots/"
    }
  }
  dependencies {
     classpath 'com.jimdo.gradle:gradle-apt-plugin:0.5-SNAPSHOT'
  }
}


repositories {
  mavenCentral()
  maven {
    name = "sonatype"
    url = "https://oss.sonatype.org/content/repositories/snapshots/"
  }
  maven {
    name = "sonatypeGoogle"
    url = "https://oss.sonatype.org/content/repositories/google-snapshots/"
  }
  flatDir {
    dirs 'lib'
  }
}

sourceSets {
  apt{
    java{
      srcDir 'build/source/apt'
      srcDir 'build/source/base'
    }
  }
}


dependencies {
  apt (project(':my-base'))
  apt 'com.google.auto.factory:auto-factory:1.0-beta2'
  apt 'com.google.dagger:dagger:2.0.1'
  apt 'com.google.dagger:dagger-producers:2.0-beta'
  apt 'com.google.dagger:dagger-compiler:2.0.1'

  compile (project(':my-base'))   

  compile 'com.google.auto.factory:auto-factory:1.0-beta2'
  compile 'com.google.auto.service:auto-service:1.0-rc2' 
  compile 'com.google.dagger:dagger:2.0.1'
}

jar {
  from "build/source/apt"
  exclude '**/*.zip'
}

my-main settings.gradle

include ':my-base'
project(':my-base').projectDir = new File('/absoltePathTo/my-base')

my-Android build.gradle

apply plugin: 'com.android.application'

buildscript {
    repositories {
        mavenCentral()
        jcenter()
        maven {
            url "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
}

repositories {
    mavenCentral()
    maven {
        name = "sonatype"
        url = "https://oss.sonatype.org/content/repositories/snapshots/"
    }
    maven {
        name = "sonatypeGoogle"
        url = "https://oss.sonatype.org/content/repositories/google-snapshots/"
    }
    flatDir {
        dirs 'libs'
    }
}

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0 rc2"

    defaultConfig {
        applicationId "de.mytest.mytest_android"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
    lintOptions {
        abortOnError false
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'

    compile (project(':my-main'))
}

my-Android settings.gradle

include ':app'
include ":my-base"
project(':my-base').projectDir = new File('/absoltePathTo/my-base')
include ":my-main"
project(':my-main').projectDir = new File('/absoltePathTo/my-main')

在我的主要活动中,我包含了my-basemy-main中定义的类:

enter image description here

当我从Android Studio以外的命令行执行gradle build时,我没有错误。当我在Android Studio中gradle build时,我得到:

Failed to set up dependencies
Error:Unable to find module with Gradle path ':my-main'.

注意:问题似乎来自于我有两个settings.gradle。一个在my.Android中,另一个在my-main中。

如何在Android Studio导入中正确解析依赖项目my-main中的类?如何删除上述错误?

1 个答案:

答案 0 :(得分:0)

在" my-Android build.gradle"在依赖关系下,你有 编译(项目(':my-main'))

我从您的错误消息中推断出,它无法了解“我的地雷”的位置。是。尝试将绝对目录用于项目,看看是否有效。如果确实如此,那么你知道':my-main'不是正确的文件路径。