当前位置: 首页 > 知识库问答 >
问题:

找不到 Gradle DSL 方法:使用 tesseract 库时出现“compile()”

端木夕
2023-03-14

我试图在Android Studio导入 tesseract ocr 项目。在构建 gradle 时,它显示错误如下

错误:(8, 0) 找不到 Gradle DSL 方法:“编译()” 可能的原因:

My app/build.gradle file

    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:2.4.1@aar'
    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:2.4.0@aar') {
        transitive = true;
    }


}

我的项目根构建.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')
}

我的设置.gradle 文件

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

My gradle-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

我也添加了依赖项。请告诉我问题出在哪里。谢谢

共有1个答案

杨超
2023-03-14

你必须改变你的顶级build.gradle,删除编译行,并添加gradle和fabric插件。

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

    }

}

Als 如果你想在你的项目中使用 libraries:tess-two,你必须在 app/build.gradle 文件的依赖块中添加这一行

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

最后移动应用插件:在app/build.gradle文件的开头的'osgi'

要解决 ndk 问题,您必须:

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

这是我的 gradle.properties :

android.useDeprecatedNdk=true
 类似资料:
  • 我知道这被问了好几次,但看起来我尝试的一切都不奏效。 我也是新手,如果我犯了任何错误,我很抱歉。 我尝试使用Gradle和eclipse构建java jar。 Gradle构建如下所示: 但我总是以: 在DefaultDependencyHandler类型的对象上找不到参数[org.springframework.boot: spring-boot-starter-data-jpa]org.gra

  • 我正在尝试使用Java JNA包装器来实现Tesseract OCR API,但我一直得到Java.lang.UnsatisfiedLinkError异常 我从http://sourceforge.net/projects/tess4j/下载了最新版本 我确保使用了32位JVM。下面是异常跟踪。 我使用了http://tess4j.sourceforge.net/codesample.html中的

  • 我用的是Mac OS优胜美地。我已经在eclipse中准备好了项目设置,构建路径中有libtesseract302.dll。但是当我运行主类时,它会抛出一个错误 仅供参考- 我已经按照这里指定的步骤执行了一些测试来修复这个问题,但它仍然会给我带来一个错误。 null

  • 问题内容: 我在一个空目录中有一个超简单的文件: 和预期的以下作品 我在Mac OS X上,使用emma-2.0.5312和java 1.7.0_40 emma.jar已安装到/ Library / Java / Extensions,因此可以正常工作 (它显示了使用emmarun的帮助) 接下来我跑 我得到错误: 是什么原因造成的?显然,它确实有一个公共的,可访问的主方法,那么为什么艾玛找不到它

  • 我奔跑 我得到了一组输出,看起来像: 最后它说: 运行easy_install或从源代码处安装都会在最后给我带来相同的错误(关于-lssl找不到库的部分)。 运行brew安装(或升级)openssl会产生以下结果 有人能帮我吗?

  • 我在为ios编译应用程序时遇到了这个问题 这是整个堆栈跟踪: 在调试模式下在iPhone Xs Max上启动lib / main.dart...正在运行的吊舱安装...运行 Xcode 构建...Xcode 构建完成。 2,4 秒 无法构建 iOS 应用程序 Xcode 构建的错误输出: ↳ ** 构建失败 ** Xcode的输出: ↳ === BUILD TARGET Firebase Auth

  • 我正在尝试运行一个JSX代码,但是得到了这个错误。我确实安装了npm安装-g babel-cli npm安装--save babel-preset-env babel-preset-react,但我仍然得到错误。 这是我的代码index.html src/app.js->JSX代码 babel命令->将JSX转换为ES5的babel命令 错误

  • 问题内容: 我正在尝试在此Debian lenny系统上使用g ++链接应用程序。ld抱怨找不到指定的库。这里的特定示例是ImageMagick,但是其他一些库也遇到类似的问题。 我通过以下方式调用链接器: ld抱怨: 但是,libmagic存在: 如何进一步诊断此问题,可能出什么问题了?我在做些完全愚蠢的事情吗? 问题答案: 问题是链接器正在寻找,但是您只有 一个快速的技巧是符号链接到