【问题标题】:Unable to resolve class of library in splitted Gradle Build Script无法解析拆分的 Gradle 构建脚本中的库类
【发布时间】:2015-05-20 16:45:54
【问题描述】:

我正在尝试将我的 Gradle 构建文件拆分为几个部分以使其可维护

在我的 build.gradle 中,我在一项任务中使用了 Apache Commons 库,现在我将它放在一个单独的 Gradle 文件中

Gradle 项目文件:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath 'commons-codec:commons-codec:1.10'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Gradle 模块文件:

apply plugin: 'com.android.library'
apply from: 'gradle/splittedFile.gradle'

我的 splittedFile.gradle

import org.apache.commons.codec.binary.Base64

当我执行构建时,它显示“无法解析类 org.apache.commons.codec.binary.Base64

如何使库在拆分后的 Gradle 文件中可访问?

【问题讨论】:

    标签: android android-studio build gradle split


    【解决方案1】:

    buildscript 依赖块添加到您的gradle/splittedFile.gradle 文件中。

    import org.apache.commons.codec.binary.Base64
    
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath group: 'commons-codec', name: 'commons-codec', version: '1.2'
        }
    }
    
    task encode << {
        def byte[] encodedString = new Base64().encode('hello world\n'.getBytes())
        println new String(encodedString)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-14
      • 2011-02-03
      • 1970-01-01
      • 2013-12-30
      相关资源
      最近更新 更多