2015-09-26 120 views
1

我试图在android studio中导入tesseract ocr项目。同时建立gradle这个它舒错误如下未找到Gradle DSL方法:使用tesseract库时'compile()'

Error:(8, 0) Gradle DSL method not found: 'compile()' Possible causes:

  • The project 'textfairy' may be using a version of Gradle that does not contain the method. Open Gradle wrapper file
  • The build file may be missing a Gradle plugin. Apply Gradle plugin
  • 我的应用程序/文件的build.gradle

    import java.util.regex.Pattern 
    
        apply plugin: 'com.android.application' 
        apply plugin: 'io.fabric' 
    
    
    
        import org.apache.tools.ant.taskdefs.condition.Os 
    
    
        task ndkBuild(type: Exec,description: 'run ndk-build') { 
        if (Os.isFamily(Os.FAMILY_WINDOWS)) { 
         workingDir 'src/main/jni' 
         commandLine 'ndk-build.cmd', '-j',  Runtime.runtime.availableProcessors() 
    
        } else { 
         workingDir 'src/main/jni' 
         commandLine "$ndkDir/ndk-build", '-j', Runtime.runtime.availableProcessors() 
        } 
    } 
    
    tasks.withType(JavaCompile) { 
        compileTask -> compileTask.dependsOn(ndkBuild) 
    } 
    
    
        def getVersionCodeFromManifest(String prefix) { 
        def manifestFile = file("src/main/AndroidManifest.xml") 
        def pattern = Pattern.compile("versionCode=\"(\\d+)\"") 
        def manifestText = manifestFile.getText() 
        def matcher = pattern.matcher(manifestText) 
        matcher.find() 
        def version = prefix + matcher.group(1) 
        println sprintf("Returning version %s", version) 
        return Integer.parseInt("$version") 
    } 
    
    
    
    
        android { 
        compileSdkVersion 21 
        buildToolsVersion "21.1.2" 
    
        defaultConfig { 
         testInstrumentationRunner "android.test.InstrumentationTestRunner" 
         //testHandleProfiling true 
         //testFunctionalTest true 
        } 
        signingConfigs { 
         release 
        } 
        buildTypes { 
         debug { 
          debuggable true 
         } 
         release { 
          //runProguard true 
          proguardFile file('android.pro') 
          proguardFile getDefaultProguardFile('proguard-android.txt') 
          signingConfig signingConfigs.release 
         } 
        } 
    
        productFlavors { 
         x86 { 
          versionCode getVersionCodeFromManifest("6") 
          ndk { 
           abiFilter "x86" 
          } 
    
         } 
         aV7 { 
          versionCode getVersionCodeFromManifest("2") 
          ndk { 
           abiFilter "armeabi-v7a" 
          } 
         } 
         aV5 { 
          versionCode getVersionCodeFromManifest("1") 
          ndk { 
           abiFilter "armeabi" 
          } 
         } 
        } 
        sourceSets { 
         main { 
          //jniLibs.srcDirs = ['native-libs'] 
          jniLibs.srcDir 'src/main/libs' 
          jni.srcDirs = [] //disable automatic ndk-build 
         } 
        } 
    } 
    
        def Properties props = new Properties() 
        def propFile = new File('signing.properties') 
        if (propFile.canRead()) { 
        props.load(new FileInputStream(propFile)) 
    
        if (props != null && props.containsKey('STORE_FILE') && props.containsKey('STORE_PASSWORD') && 
          props.containsKey('KEY_ALIAS') && props.containsKey('KEY_PASSWORD')) { 
         android.signingConfigs.release.storeFile = file(props['STORE_FILE']) 
         android.signingConfigs.release.storePassword = props['STORE_PASSWORD'] 
         android.signingConfigs.release.keyAlias = props['KEY_ALIAS'] 
         android.signingConfigs.release.keyPassword = props['KEY_PASSWORD'] 
        } else { 
         println 'signing.properties found but some entries are missing' 
         android.buildTypes.release.signingConfig = null 
        } 
    } else { 
        println 'signing.properties not found' 
        android.buildTypes.release.signingConfig = null 
    } 
    
        dependencies { 
        debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' 
        releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' 
        compile fileTree(dir: 'src/main/libs', include: '*.jar') 
        compile 'com.viewpagerindicator:library:[email protected]' 
        compile 'com.github.chrisbanes.photoview:library:1.2.2' 
        compile 'com.google.code.findbugs:jsr305:2.0.2' 
        compile "com.google.guava:guava:18.0" 
        compile 'de.greenrobot:eventbus:2.4.0' 
        //compile 'com.android.support:design:22.2.0' 
        compile 'com.nineoldandroids:library:2.4.0' 
        compile 'com.android.support:appcompat-v7:19.0.+' 
        compile 'org.apache.commons:commons-compress:1.5' 
        compile project(":tess-two:tess-two") 
        compile 'com.android.support:cardview-v7:21.0.+' 
    
        androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0' 
        androidTestCompile 'com.google.dexmaker:dexmaker:1.0' 
        androidTestCompile 'org.mockito:mockito-core:1.10.17' 
        androidTestCompile 'junit:junit:4.12' 
    
    
        testCompile 'junit:junit:4.12' 
        testCompile "org.mockito:mockito-all:1.10.19" 
        testCompile("org.robolectric:robolectric:3.0-rc2") { 
         exclude group: 'commons-logging', module: 'commons-logging' 
        } 
        compile('com.crashlytics.sdk.android:crashlytics:[email protected]') { 
         transitive = true; 
        } 
    
    
    } 
    

    我的项目的根文件的build.gradle

    // Top-level build file where you can add configuration options common to all sub-projects/modules. 
    buildscript { 
        repositories { 
         maven { url 'https://maven.fabric.io/public' } 
         jcenter() 
        } 
        dependencies { 
         compile fileTree(dir: 'libs', include: ['*.jar']) 
        } 
    } 
    allprojects { 
        repositories { 
         maven { url 'https://maven.fabric.io/public' } 
         maven { url "http://dl.bintray.com/populov/maven" } 
         jcenter() 
         maven { 
          url "http://oss.sonatype.org/content/repositories/snapshots" 
         } 
    
        } 
    
    } 
    
    dependencies { 
        apply plugin: 'osgi' 
        compile project(':libraries:tess-two') 
    } 
    

    我settings.gradle文件

    include ':libraries:tess-two' 
    include ':app' 
    

    我的gr adle-wrapper.properties

    distributionBase=GRADLE_USER_HOME 
    distributionPath=wrapper/dists 
    zipStoreBase=GRADLE_USER_HOME 
    zipStorePath=wrapper/dists 
    distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 
    

    我加入的依赖也。请告诉我什么是问题。 谢谢

    回答

    2

    你必须改变你的顶级build.gradle,除去编译行,并添加gradle产出和织物插件。如果你想使用的库

    buildscript { 
        repositories { 
         maven { url 'https://maven.fabric.io/public' } 
         jcenter() 
        } 
        dependencies { 
         classpath 'com.android.tools.build:gradle:1.3.1' 
         classpath 'io.fabric.tools:gradle:1.+' 
        } 
    } 
    
    
    allprojects { 
        repositories { 
         maven { url 'https://maven.fabric.io/public' } 
         maven { url "http://dl.bintray.com/populov/maven" } 
         jcenter() 
         maven { 
          url "http://oss.sonatype.org/content/repositories/snapshots" 
         } 
    
        } 
    
    } 
    

    阿尔斯:苔丝,两人在你的项目中,您必须添加dependecies块内这一行你app/build.gradle文件

    compile project(':libraries:tess-two') 
    

    最后移动apply plugin: 'osgi'在该app/build.gradle文件的开头

    要解决你的问题NDK:

    1. 添加gradle.properties文件到你的项目的根文件夹
    2. 加 'android.useDeprecatedNdk = true' 可gradle.properties文件

    这里是我的gradle.properties:

    android.useDeprecatedNdk=true 
    
    +0

    喜盈盈那也是我的尝试。但同样的错误显示。 :( –

    +0

    还试图降临到你的第二个答案同样的错误:( –

    +0

    我的任何问题或有不添加gradle-wrapper.properties文件在我的问题。看到我的错误打开文件gradle-wrapper.properties这样的显示 –

    相关问题