【问题标题】:How to add explicit declaration in gradle android如何在 gradle android 中添加显式声明
【发布时间】:2018-02-18 05:51:04
【问题描述】:
compile "com.google.firebase:firebase-auth:$FOO"
compile "com.google.android.gms:play-services-auth:$FOO"

compile "com.android.support:design:$BAR"
compile "com.android.support:customtabs:$BAR"
compile "com.android.support:cardview-v7:$BAR"

我需要在您的 build.gradle 中添加显式编译声明。 这个链接说https://github.com/firebase/FirebaseUI-Android#installation 放置此代码以避免冲突。但 Android 工作室说 FOO,BAR 没有找到。帮帮我

【问题讨论】:

    标签: java android gradle dependencies build.gradle


    【解决方案1】:

    FOOBAR 只是在 .gradle 文件中定义的变量。
    您可以随意调用它们。

    要使用这种语法,您可以在顶级 build.gradle 中定义类似:

    project.ext { 
        firebaseVersion = '11.2.0'
        supportLibraryVersion = '26.0.1'
    }
    

    然后在模块的另一部分 build.gradle 文件中使用这些变量,例如在依赖项中。

    例如:

    dependencies {
        compile "com.android.support:design:$supportLibraryVersion"
        compile "com.google.android.gms:play-services-auth:$firebaseVersion"
    }
    

    或者,如果您更喜欢使用 FOOBAR

    project.ext { 
            FOO = '11.2.0'
            BAR = '26.0.1'
        }
    
     dependencies {
            compile "com.android.support:design:$BAR"
            compile "com.google.android.gms:play-services-auth:$FOO"
        }
    

    【讨论】:

      【解决方案2】:

      所有这些常量都定义在constants.gradle文件中

      constants.gradle 示例

      project.ext {
          compileSdk = 26
          targetSdk = 26
          minSdk = 14
      
          buildTools = '26.0.1' 
          firebaseVersion = '11.2.0'
          supportLibraryVersion = '26.0.1'
          playServiesVersion = '11.2.0'
      }
      

      你必须在项目目录下直接添加 constants.gradle 文件和 添加

      apply from: 'constants.gradle' 
      

      在项目的build.gradle 中。

      // Top-level build file where you can add configuration options common to all sub-projects/modules.
      apply from: 'constants.gradle'
      
      buildscript {
          repositories {
              jcenter()
          }
          dependencies {
              classpath 'com.android.tools.build:gradle:2.3.3'
              classpath 'com.google.gms:google-services:3.1.0'
              // NOTE: Do not place your application dependencies here; they belong
              // in the individual module build.gradle files
          }
      }
      

      【讨论】:

      • 看不懂!请解释一下什么是 FOO,BAR?
      • @eagle foo 和 bar 是库的版本号。随着库版本的更改,我们必须更改此 foo 和 bar 值,例如,当升级 firebase-auth 库时,我们将更改这些版本号码
      猜你喜欢
      • 2017-02-11
      • 2018-10-26
      • 1970-01-01
      • 2015-12-30
      • 2013-12-21
      • 2016-11-14
      • 1970-01-01
      • 2015-01-25
      • 1970-01-01
      相关资源
      最近更新 更多