[問題] Android gradle build
請教gradle高手,有三個module app和lib(sync-lib及
ttt-lib),lib裡面又有用到第三方一些library,像Timber之
類的,但app裡面寫Unit test用到Timber,有客製寫
了一個task叫unitMocktest來執行unit test,但在執
行gradle unitMocktest的時候會找不到timber,錯誤訊息如下:
app:compileUnitMockTestJava
/home/project/app/src/unitMockTest/java/com/aaa/sync/ClassTestC.java:41: error:
OkHttpClient okHttpClient = new OkHttpClient();
^
symbol: class OkHttpClient
location: class ClassTestC
/home/project/app/src/unitMockTest/java/com/aaa/sync/ClassTestC.java:41: error:
OkHttpClient okHttpClient = new OkHttpClient();
^
symbol: class OkHttpClient
location: class ClassTestC
/home/project/app/src/unitMockTest/java/com/aaa/sync/ClassTestC.java:49: error
Timber.e("a");
^
symbol: variable Timber
location: class ClassTestC
Note: /project/app/src/unitMockTest/java/com/aaa/sync/ClassTestA.java uses
Note: Recompile with -Xlint:deprecation for details.
3 errors
:app:compileUnitMockTestJava FAILED
===============================
以下是app/build.gradle的設定
// Constants
def extra = rootProject.ext
def deps = extra.deps
buildscript {
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath "io.realm:realm-gradle-plugin:3.4.0"
classpath 'me.tatarka:gradle-retrolambda:3.5.0'
classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2'
classpath 'com.jakewharton.timber:timber:4.5.1'
}
// Exclude the version that the android plugin depends on.
configurations.classpath.exclude group: 'com.android.tools.external.lombok'
}
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'realm-android'
android {
compileSdkVersion extra.compileSdkVersion
buildToolsVersion extra.buildToolsVersion
defaultConfig {
applicationId "com.abc.sync.test"
versionCode 1
versionName "1.0"
minSdkVersion extra.minSdkVersion
targetSdkVersion extra.targetSdkVersion
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:23.1.1'
}
}
configurations {
compile.exclude group: "org.apache.httpcomponents", module: "httpclient"
}
sourceSets {
String sharedTestDir = 'src/test/java'
test {
java.srcDir sharedTestDir
}
androidTest {
java.srcDir sharedTestDir
}
}
lintOptions {
abortOnError false
}
buildToolsVersion '25.0.0'
}
sourceSets {
main {
java {
srcDir 'src/test/java'
}
}
test {
java {
srcDir 'src/test/java'
}
compileClasspath += sourceSets.main.runtimeClasspath
}
unitMockTest {
java.srcDir file('src/unitMockTest/java')
java.srcDir file('../ttt-lib/src/main/java')
java.srcDir file('../sync-lib/src/main/java')
}
}
configurations {
unitMockTestCompile.extendsFrom testCompile
unitMockTestRuntime.extendsFrom testRuntime
}
task unitMockTest(type: Test) {
println 'Start unit test'
testClassesDir = sourceSets.unitMockTest.output.classesDir
classpath = sourceSets.unitMockTest.runtimeClasspath
useJUnit {
includeCategories 'com.wdc.sync.UnitTests'
excludeCategories 'com.wdc.sync.IntegrationTests'
}
}
dependencies {
compile project(path:':sync-lib' ,configuration: "compile")
compile project(path:':ttt-lib',configuration: "compile")
testCompile project(path: ':sync-lib' ,configuration: "compile")
testCompile project(path: ':ttt-lib',configuration: "compile")
testRuntime project(path: ':ttt-lib',configuration: "compile")
testCompile deps.timber
testCompile deps.okhttp
// Logging
// compile deps.timber
testCompile deps.slf4jApi
testCompile deps.slf4jSimple
// Dagger
compile deps.dagger
apt deps.daggerCompiler
testApt deps.daggerCompiler
provided deps.jsr250Api
androidTestApt deps.daggerCompiler
androidTestCompile(deps.espressoCore, {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.code.findbugs'
})
compile deps.androidPriorityJobqueue
compile deps.playServicesGcm
compile deps.supportAnnotations
// main APK
// RxJava 2
testCompile deps.rxjava2
testCompile deps.rxjava1
// Java tests
testCompile deps.junit
testCompile deps.mockitoCore
// Android tests
androidTestCompile deps.mockitoCore
androidTestCompile deps.dexmakerMockito
androidTestCompile deps.supportAnnotations
// test APK
androidTestCompile deps.supportTestRunner
androidTestCompile deps.supportTestRules
unitMockTestRuntime project(path: ':ttt-lib')
unitMockTestCompile project(':sync-lib')
unitMockTestCompile project(':ttt-lib')
unitMockTestCompile deps.rxjava2
unitMockTestCompile deps.rxjava1
unitMockTestCompile deps.mockitoCore
unitMockTestCompile deps.dexmakerMockito
}
有人知道為何build會找不到第三方package嗎?感謝指教
-----
Sent from JPTT on my Samsung SM-N9208.
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 199.255.47.6
※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1502368407.A.96D.html
※ 編輯: finalshinji (199.255.47.6), 08/10/2017 20:36:11
AndroidDev 近期熱門文章
PTT數位生活區 即時熱門文章