2016-10-28 53 views
0

我试用Hawk认证https://github.com/wealdtech/hawk。我想通过源代码将这个图书馆包含在一个空白的项目中,以便我可以试验apis。我不想使用jar或gradle依赖。Android:不能包含https://github.com/wealdtech/hawk作为模块

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

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' 
} 

鹰模块的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

回答

0

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

对于整个过程,:

git clone [email protected]: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 
    } 

} 

你不能添加Java插件(apply plugin: 'java')为您的Android项目。如果你这样做,你会有这个错误: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

中复制了其余的配置