Android:不能包含https://github.com/wealdtech/hawk作为模块

时间:2016-10-28 12:04:39

标签: android android-gradle

我正在尝试https://github.com/wealdtech/hawk进行Hawk身份验证。我想在一个空项目中按源包含这个库,以便我可以试验api。我不想使用jar或gradle依赖。

我将项目作为模块导入,我遇到了这个错误:

Error:(2, 0) Gradle DSL method not found: 'compile()'
Possible causes:<ul><li>The project 'HawkTest' may be using a version of Gradle that does not contain the method.
<a href="open.wrapper.file">Open Gradle wrapper file</a></li><li>The build file may be missing a Gradle plugin.
<a href="apply.gradle.plugin">Apply Gradle plugin</a></li>

我尝试了这些链接的解决方案,但我无法获得任何有助于解决此问题的信息: Android gradle build Error:(9, 0) Gradle DSL method not found: 'compile()'.

Android gradle build Error:(9, 0) Gradle DSL method not found: 'compile()'.

我花了很多时间来解决这个问题,但似乎没有任何解决方案。任何方向或解决方案将不胜感激。

这是我的顶级构建文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

应用级别文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.test.android.hawktest"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
}

Hawk模块的gradle文件:

dependencies {
    compile 'com.wealdtech:wealdtech-core:2.0.0'
    compile 'com.wealdtech:wealdtech-configuration:2.0.0'
    compile 'com.google.guava:guava:17.0'
}

uploadArchives {
    repositories {
        mavenDeployer {
            pom.project {
                pom.artifactId = 'hawk-core'
                name 'Hawk Core'
                description 'Java implementation of Hawk protocol - core'
            }
        }
    }
}

我的目录结构:

enter image description here

1 个答案:

答案 0 :(得分:0)

hawk顶级build.gradle包含所有子项目配置(请检查https://github.com/wealdtech/hawk/blob/develop/build.gradle

对于整个过程,从项目根目录:

git clone git@github.com:wealdtech/hawk.git

settings.gradle中,这将配置gradle模块:

include ':app',':hawk-core', ':hawk-server-jersey', ':hawk-client-jersey'
project(':hawk-core').projectDir = new File('hawk/hawk-core')
project(':hawk-server-jersey').projectDir = new File('hawk/hawk-server-jersey')
project(':hawk-client-jersey').projectDir = new File('hawk/hawk-client-jersey')

然后编辑顶级build.gradle以指定Java项目的配置。添加以下内容:

configure(subprojects.findAll {it.name.startsWith('hawk')}) {

    apply plugin: 'java'
    apply plugin: 'maven'
    apply plugin: 'idea'
    apply plugin: 'signing'

    repositories {
        mavenCentral()
        mavenLocal()
    }

    dependencies {
        testCompile 'org.testng:testng:6.8'
    }

    task copyLibs (type: Copy) {
        into "$buildDir/output/libs"
        from configurations.testRuntime
    }

    task testJar (type: Jar) {
        classifier = 'tests'
        from sourceSets.test.output
    }

    task javadocJar(type: Jar, dependsOn: javadoc) {
        classifier = 'javadoc'
        from 'build/docs/javadoc'
    }

    task sourcesJar(type: Jar) {
        classifier = 'sources'
        from sourceSets.main.allSource
    }

    artifacts {
        archives jar
        archives javadocJar
        archives sourcesJar
    }

}

您无法为Android项目添加Java插件(apply plugin: 'java')。如果您这样做,则会出现此错误:The 'java' plugin has been applied, but it is not compatible with the Android plugins.。这就是我使用configure(subprojects.findAll并对hawk模块执行过滤的原因。我已经从https://github.com/wealdtech/hawk/blob/develop/build.gradle

复制了剩余的配置