【问题标题】:iTextPdf - Android Studio Adding Library ErroriTextPdf - Android Studio 添加库错误
【发布时间】:2016-01-28 17:10:15
【问题描述】:

我想将 itext 库添加到我的项目中。(http://itextpdf.com/itextg-android)

我将 jar 文件添加到 libs 文件夹中。之后,我写信给 build.gradle:编译文件('libs/itextg-5.5.4.jar')。

但是在同步之后,我得到了那个错误:

错误:(12, 0) Gradle DSL 方法未找到: 'compile()' 可能的原因:

  • 项目“Pdf”可能正在使用不包含该方法的 Gradle 版本。 Gradle 设置
  • 构建文件可能缺少 Gradle 插件。 应用 Gradle 插件
  • 这里(http://www.codeproject.com/Articles/986574/Android-iText-Pdf-Example)也是一个解决方案,但是当我这样做时,我又遇到了另一个错误

    错误:无法解决:org.apache.commons:commons-imaging:1.0-SNAPSHOT 打开文件
    在项目结构对话框中显示

    【问题讨论】:

    标签: android android-studio compiler-errors shared-libraries add


    【解决方案1】:

    请检查您是否添加了所有需要的软件包,然后您的 buil.gradle 看起来像:

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 22
        buildToolsVersion "22.0.1"
    
        defaultConfig {
            applicationId "com.proyecto.alberto.monedero"
            minSdkVersion 16
            targetSdkVersion 22
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:22.0.0'
        compile files('libs/itextg-5.5.4.jar')
        compile files('libs/itextg-5.5.4-sources.jar')
        compile files('libs/itextg-5.5.4-javadoc.jar')
        compile 'com.google.android.gms:play-services:7.0.0'
    }
    

    发件人:https://github.com/alonsoat/ProyectoMonedero/blob/master/app/build.gradle

    希望对你有帮助

    【讨论】:

    • 我再次出错:错误:任务':app:dexDebug'的执行失败。 > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' 没有完成-零退出值2
    • 尝试换成jdk8
    • 我更新了我的 java 但它没有用。这也是一个解决方案,但是当我这样做时,我得到了错误。
    【解决方案2】:

    您还可以通过右键单击添加 .jar 或库 "app" > New > Module

    然后选择 Import .JAR/.AAR Package option.

    您可以单击最右侧的“浏览”[...] 并找到您的 jar。 同步项目右键应用>同步应用

    在那之后你应该是金色的。 Alt-Shift 在与您添加的库相关的 RED 方法/代码上,您现在应该能够快速导入。

    只是另一种选择。

    【讨论】:

    • 在这样做之后,我遇到了这个错误:错误:任务':app:dexDebug'的执行失败。 > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' 没有完成-零退出值2
    • @lovekrand 您添加的一个或多个 .jar 文件可能无法编译,因此它们可能写得不好。该库是来自受信任的来源还是类似于 Google API?您可以尝试删除添加的库,然后一次添加一个。
    • 另外,试着看看你的项目树中是否有重复的Class文件,或者甚至可能写入你添加的库中。有时由于某种原因添加库后,Gradle 构建有点不稳定。
    • 还有一件事,在你的项目树中,在 Gradle Scripts > build.gradle(Module: yourApp) 下。打开它并在依赖项下查看,你看到你添加的库吗?如果没有尝试重新同步项目。
    • 我这样做没有错误,但我无法导入 itext 方法,我也尝试从项目结构中添加库。但后来我收到错误!!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多