【问题标题】:Android: Cannot include https://github.com/wealdtech/hawk as a moduleAndroid:不能包含 https://github.com/wealdtech/hawk 作为模块
【发布时间】:2017-03-11 07:46:48
【问题描述】:

我正在尝试通过 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'
            }
        }
    }
}

还有我的目录结构:

【问题讨论】:

    标签: android android-gradle-plugin


    【解决方案1】:

    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复制了剩余的配置

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-14
      • 2013-04-10
      • 1970-01-01
      • 2018-12-18
      • 1970-01-01
      • 2020-04-02
      相关资源
      最近更新 更多