我想讓我現有的Android項目與gradle和IntelliJ 12一起工作。 以前我曾經使用過maven,但似乎沒有gradle那麼靈活,並且從我的想法我知道是我需要更少的子文件夾。我的Android項目分爲乾淨的java庫(:core)和實際的應用程序(:android)。這兩個項目都在我的主項目文件夾中。IntelliJ,Android和Gradle
~-+MainProject
|--+core
| L--build.gradle
|--+android
| L--build.gradle
|--build.gradle
L--settings.gradle
我認爲理想的解決方案,使gradle這個工作,這是治療(:核心)和(:機器人)項目爲嵌套的項目,這意味着我可以簡單地與我在MainProject源文件夾CMD啓動gradle任務。
不過,我想出了不同的問題:
- 搖籃依賴只包含在覈心項目
- 這意味着既不在instrumentatetionTest也不在主項目文件的任何 目錄正確設置爲源/測試目錄
- IntelliJ不解決我添加爲gradle中的依賴關係的任何類(AndroidSDK,junit,mockito,來自:core項目的那些)
- 試圖使用該插件「想法」,但無論是我用錯了或者它並沒有解決問題
- 我得到重複的相關性錯誤爲建設APK
- 必須有東西做使用JUnit:4.11和的Mockito核心:1.9.5我添加
- 我的嘗試:
- 刪除dependencys - >構建失敗造成當然could'nt的一些類來解決
- 改變JUnit的:4.5 +作爲suggesed在一些其他線程 - 在所有
>沒有改變這裏是* .gradle configuartions
MainProject: - 設置。 gradle這個
include ':core', ':android'
- 的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" }
}
}
:core - build。gradle這個
apply plugin: 'java'
dependencies {
testCompile 'junit:junit:4.11'
testCompile 'org.mockito:mockito-core:1.9.5'
}
:安卓
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
我希望有人能幫助我與
MFG Dornathal
超級不錯的回答馬呂斯。我認爲他在第一點的問題是關於如何從android build.gradle文件中指定測試源目錄。但對我來說也不完全清楚。我使用的是AndroidStudio,因此我不確定我的答案在這裏會有幫助。感謝JUnit提示;) – khose
由於Android Studio是IntelliJ與ADT已經捆綁在一起,我認爲應該沒有任何區別。 – Dornathal
當然,對於jUnit 4.11,如果SDK只包含JUnit 3,他確實需要依賴項 – RichieHH