android studio编程时出现的错误:Cannot get property 'XXXX' on extra properties extension as it does not exist

用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 {
    // App's dependencies, including test
    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"

    // Dependencies for local unit tests
    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'
}



  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值