0

I want to add itext lib to my project.(http://itextpdf.com/itextg-android)

I added to jar file into libs folder. After that i wrote to build.gradle that : compile files('libs/itextg-5.5.4.jar') .

But after the sync , i am getting that error :

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

  • The project 'Pdf' may be using a version of Gradle that does not contain the method. Gradle settings
  • The build file may be missing a Gradle plugin. Apply Gradle plugin
  • Also here(http://www.codeproject.com/Articles/986574/Android-iText-Pdf-Example) is a solution about this but when i do that i am getting another error

    Error:Failed to resolve: org.apache.commons:commons-imaging:1.0-SNAPSHOT Open File
    Show in Project Structure dialog

    lovekrand
    • 47
    • 1
    • 8
    • go though this link. It might help you http://stackoverflow.com/questions/16608135/android-studio-add-jar-as-library – Vivek Mishra Jan 28 '16 at 17:22

    2 Answers2

    2

    Please check if you added all needed packages and after this your buil.gradle looks like:

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

    From: https://github.com/alonsoat/ProyectoMonedero/blob/master/app/build.gradle

    Hope it help

    Community
    • 1
    • 1
    piotrek1543
    • 19,130
    • 7
    • 81
    • 94
    • I am taking error again : Error:Execution failed for task ':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'' finished with non-zero exit value 2 – lovekrand Feb 04 '16 at 13:00
    • try to change to jdk8 – piotrek1543 Feb 05 '16 at 11:01
    • i updated my java but it did not work. Also here is a solution but when i do that i am getting error . – lovekrand Feb 13 '16 at 13:27
    1

    You can also add a .jar or a library via right clicking on "app" > New > Module

    Then select the Import .JAR/.AAR Package option.

    You can click the "browse" [...] on the far right and locate your jar. Sync the project right click app > Sync app

    You should be golden after that. Alt-Shift over RED methods/code relevant to your added library and you should now be able to quick import.

    Just another option.

    NSTuttle
    • 3,237
    • 2
    • 17
    • 26
    • After doing that i am taking this error : Error:Execution failed for task ':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'' finished with non-zero exit value 2 – lovekrand Feb 04 '16 at 12:59
    • @lovekrand One or more of the .jar files you added may not be compiling, hence they might not be written well. Is the library from a trusted source or is it like a Google API? You might try to remove the added libraries, and add them in one at a time. – NSTuttle Feb 04 '16 at 16:04
    • Also, try to see if there may be duplicate Class files in your project tree, or maybe even written into the library you added. Sometimes Gradle builds are a little wonky after adding libraries for some reason. – NSTuttle Feb 04 '16 at 16:08
    • One more thing, in your project tree, under Gradle Scripts > build.gradle(Module: yourApp). Open it and look under dependencies, do you see the libraries you added? If not try to re sync the project. – NSTuttle Feb 04 '16 at 16:10
    • I made this there is no error but i can not import the itext methods, also i tried add library from project structure. But then i am getting error !!! – lovekrand Feb 13 '16 at 13:26