用Android Studio中导入第三方库工程的时候出现的问题:
Error:(28, 0) Cannot get property 'junitVersion' on extra properties extension as it does not exist
出现这种问题原因是第三方库工程 引用了 自定义的 junitVersion 这个名字的ext;
因此在该项目的根目录那个build.gradle里的ext加上junitVersion这个即可,如下
ext {
junitVersion = '4.12'
}
4.12这个是自定义的,
其他名称的同理。
************************************************ rootProject 方法介绍 *************************************************************
引用这些自定义ext的值方法如下:$rootProject.ext.{value}
该方法的好处就是:
用rootProject中的一个值来代替本来的版本号,目前理解成多个module时的用处,即抽取出来统一管理:例:
defaultConfig { compileSdkVersion rootProject.ext.compileSdkVersion buildToolsVersion rootProject.ext.buildToolsVersion minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion}dependencies {
compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
compile "com.android.support.test.espresso:espresso-idling-resource:$rootProject.espressoVersion"
compile "com.google.guava:guava:$rootProject.guavaVersion"
testCompile "junit:junit:$rootProject.ext.junitVersion"
testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion"
testCompile "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion"
}
而project的Gradle(项目的根目录那个build.gradle
)中是这么写的:
// Define versions in a single place
ext {
// Sdk and tools
minSdkVersion = 10
targetSdkVersion = 24
compileSdkVersion = 24
buildToolsVersion = '24.0.2'
// App dependencies
supportLibraryVersion = '24.2.0'
guavaVersion = '18.0'
junitVersion = '4.12'
mockitoVersion = '1.10.19'
powerMockito = '1.6.2'
hamcrestVersion = '1.3'
runnerVersion = '0.5'
rulesVersion = '0.5'
espressoVersion = '2.2.2'
}