的IntelliJ,Android和摇篮 [英] IntelliJ, Android and Gradle

查看:138
本文介绍了的IntelliJ,Android和摇篮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我现有的Andr​​oid项目的gradle与和IntelliJ 12个工作。
previously我拥有了与Maven的工作,但似乎并没有那么灵活,gradle这个,从我想我知道的是,我需要较少的子文件夹。

I am trying to get my existing Android Project working with gradle and IntelliJ 12. Previously I had it working with maven but that didn't seem to be so flexible as gradle, and from what I think I got to know is that I need less subfolders.

我的Andr​​oid项目分为一个干净的Java库(:核心)和实际应用(:机器人)。这两个项目都在我的主要项目文件夹。

My Android project is divided into a clean java library (:core) and the actual Application (:android). These two projects are both in my main project folder.

~-+MainProject
  |--+core
  |  L--build.gradle
  |--+android
  |  L--build.gradle
  |--build.gradle
  L--settings.gradle 

我认为理想的解决方案,使gradle这个工作,这是治疗(:核心)和(:机器人)项目为嵌套项目,这意味着我可以简单地与我的MainProject源文件夹CMD启动gradle这个任务。

I think the ideal solution to get gradle work with this is to treat the (:core) and (:android) project as nested projects, meaning I can simply be with my cmd in MainProject source folder to start the gradle tasks.

不过,我想出了不同的问题:

However I came up with different problems:


  1. 摇篮依赖只包含在核心项目

    • 这意味着既不在instrumentatetionTest也不在主项目文件的任何
      目录设置正确源/测试目录

    • 的IntelliJ不能解决我在gradle这个依赖性增加(AndroidSDK,JUnit中,的Mockito,那些来自:核心项目)的任何类

      • 试图使用该插件'想法',但无论是我用错了或者没有解决的问题


  • 必须有事可做使用JUnit:4.11和的Mockito核心:1.9.5我添加

  • 我的尝试:

    • 删除dependencys - >构建失败造成当然could'nt的一些类来解决

    • 更改为JUnit的:4.5 +作为suggesed在其他一些话题 - >都没有变化

    下面是* .gradle configuartions

    Here are the *.gradle configuartions

    MainProject:
       - settings.gradle

    MainProject: -- settings.gradle

    include ':core', ':android'
    

    - 的build.gradle

    -- build.gradle

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.6.+'
        }
    }
    
    subprojects {
        repositories {
            mavenLocal()
            maven { url "http://repo.maven.apache.org/maven2" }
        }
    }
    

    :核心
       - 的build.gradle

    :core -- build.gradle

    apply plugin: 'java'
    
    dependencies {
        testCompile 'junit:junit:4.11'
        testCompile 'org.mockito:mockito-core:1.9.5'
    }
    

    :Android的

    :android

    apply plugin: 'android'
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
         compile project(":core")
    
         compile 'com.google.android:android:4.1.1.4'
    
         instrumentTestCompile 'junit:junit:4.11'
         instrumentTestCompile 'org.mockito:mockito-core:1.9.5'
         instrumentTestCompile 'com.google.dexmaker:dexmaker:1.0'
         instrumentTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
    
         instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:3.6'
    } 
    
    /* ... androidSettings
    

    我希望有人能帮助我与

    I hope someone could help me with that

    MFG Dornathal

    MFG Dornathal

    推荐答案

    好了,所以你有正确的想法,但你还是需要做一些修改。

    Alright, so you've got the right idea, but there are a few changes you still need.

    您根的build.gradle 文件应该如下:

    subprojects {
        repositories {
            mavenCentral()
        }
    }
    


    • 您只需要包括 mavenLocal()如果您使用的是本地安装的回购。大多数人不这样做,并没有什么在你的项目表明你需要一个。

    • mavenCentral()可用于替换到Maven您使用的URL。

    • 我们只需要修改buildscript的Andr​​oid项目,所以我们应该是本地化的Andr​​oid项目的的build.gradle

      • You only need to include mavenLocal() if you are using a locally installed repo. Most people don't, and nothing in your project indicates that you need one.
      • mavenCentral() can be used to replace to maven URL you were using.
      • We only need to modify the buildscript for the android project, so we should localize that to the android project's build.gradle.
      • settings.gradle 和您的的build.gradle 为核心的项目都不错。

        Your settings.gradle and your build.gradle for the core project are good.

        的build.gradle 然而,对于Android项目,需要一些变化:

        Your build.gradle for the android project however, needs some changes:

        buildscript {
            repositories {
                mavenCentral()
            }
            dependencies {
                classpath 'com.android.tools.build:gradle:0.6.+'
            }
        }
        
        apply plugin: 'android'
        
        dependencies {
            compile project(":core")
        
            instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:3.6'
        }
        


        • 将包括Android插件,我们直接链接到已安装的SDK。这意味着我们不再需要包含了Android的依赖:编译com.google.android:android:4.1.1.4

        • 我们并不需要包括的JUnit 。它是由SDK提供的,因此我们就利用这一点。有一点要注意的是,只有SDK包含JU​​nit 3中。

        • 我们并不需要包括的Mockito dexmaker 除非我们真正地使用它为Android测试。如果它仅仅被用于对Java库的测试中,我们不需要在这里。

          • By including the android plugin, we link directly to the installed SDK. This means we no longer need to include the android dependency: compile 'com.google.android:android:4.1.1.4'.
          • We don't need to include junit. It's provided by the SDK, so we'll just use that. One thing to note is that the SDK only includes JUnit 3.
          • We don't need to include mockito and dexmaker unless we actually use it for the android tests. If it's only being used for the tests on the java library, we don't need it here.
          • 要回答你的问题:


            1. 我不知道你问这里。它可能会帮助,如果你要你的项目结构,包括在其中有文件和这样的。
            2. 目录
            3. 您的预感是正确的。 Hamcrest,它提供的匹配做检查,做了重大更改到1.1版本和1.3之间的API。 JUnit的4.11对1.3 Hamcrest的依赖。 1.9.5的Mockito然而,依赖于Hamcrest 1.1。所以,当两者都包括在内,覆盖1.3 1.1&放大器;的Mockito不再起作用。恢复到JUnit的4.5也是一个问题。 Junit的4.5包括1.1 Hamcrest作为JAR文件,而不是作为一个POM依赖。因此,这会导致一些问题的时候,我们有2个版本的同一文件。 JUnit的4.10是你想在这里走的路。这对Hamcrest 1.1的依赖性和其包含在聚甲醛而不是作为一个文件。双赢!我有问题,这个过了,对我来说,搞清楚是只看Maven的中央的POM文件,看看他们告诉我最好的方法。

            最后要注意的。 12的IntelliJ不能处理摇篮多生成项目。你需要切换到Android Studio或13的IntelliJ为。

            One final note. Intellij 12 cannot handle Gradle Multi-project builds. You need to switch to Android Studio or Intellij 13 for that.

            这篇关于的IntelliJ,Android和摇篮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆