0

Working in IntelliJ and uploaded source code for an app via Github to create the project.

I'm having the hardest time compiling a java class due to dependencies (as far as I can tell). The .jar files I need as dependencies for my java class appear in the .idea/libraries folder as .xml files. They also appear when I go to View/Tool Windows/Gradle and double-click on Tasks/android/androidDependencies as LOCAL dependencies. However, in my java class file there are variables from the imported .jar file dependencies that yet cannot be resolved. Whenever I try and add the .jar files to my Project Library, Gradle asks to sync the project and as a result, the directories for the .jar files in the Project Library change to my project/app file and are underlined in red and corrupted. When I don't sync the project, there are compilation errors that read that the instances in my java class that derive from those .jar dependencies cannot be found (they don't reference the dependency).

Here is what my app/build.gradle file looks like (the dependencies that aren't working right are those last four at the end: selenium-server-standalone-2.53.0.jar, jacoco-maven-plugin-0.7.7.201606060606.jar, jbrofuzz-core-2.5.jar, and java-client-4.0.0.jar)

Can anyone help me figure this out? I can provide more information as needed.

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    //noinspection GroovyAssignabilityCheck
    defaultConfig {
        applicationId "eu.wikijourney.wikijourney"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 21
        versionName '1.2.0'
    }
    //noinspection GroovyAssignabilityCheck
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    //noinspection GroovyAssignabilityCheck
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/DEPENDENCIES'
    }
    //noinspection GroovyAssignabilityCheck
    productFlavors {
    }
//noinspection GroovyAssignabilityCheck
    lintOptions{ // https://stackoverflow.com/a/32676398/3641865
        disable 'MissingTranslation' // So gradle stops complaining about the generated app_version string
                                     // not present in all translations. This is a (not so) ugly hack.
    }
    // https://stackoverflow.com/a/29525111/3641865
    applicationVariants.all { variant ->
        variant.resValue "string", "app_version", variant.versionName
    }
}

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}
//noinspection GroovyAssignabilityCheck
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:design:22.2.1'
    compile 'com.android.support:recyclerview-v7:22.2.1'
    compile 'com.android.support:cardview-v7:22.2.1'
    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.loopj.android:android-async-http:1.4.9'
    compile 'org.apache.commons:commons-lang3:3.3.2'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'org.osmdroid:osmdroid-android:5.0.1@aar'
    compile 'com.github.MKergall.osmbonuspack:OSMBonusPack:v5.6'
    compile 'com.github.k3b:k3b-geoHelper:v1.1.1'
    compile files('selenium-server-standalone-2.53.0.jar')
    compile files('jbrofuzz-core-2.5.jar')
    compile files('jacoco-maven-plugin-0.7.7.201606060606.jar')
    compile files('java-client-4.0.0.jar')
    // compile 'com.github.k3b:APhotoManager:k3b-geoHelper:test-libgeo-0.4.7.160321'
}
Cora Coleman
  • 237
  • 1
  • 5
  • 14

1 Answers1

0

This line

compile fileTree(include: ['*.jar'], dir: 'libs')

Says it will compile all JAR files that you place in the libs directory of your project. Which means, you can remove these lines.

compile files('selenium-server-standalone-2.53.0.jar')
compile files('jbrofuzz-core-2.5.jar')
compile files('jacoco-maven-plugin-0.7.7.201606060606.jar')
compile files('java-client-4.0.0.jar')

And move all JARs into that libs folder (make it if it doesn't exist). If you still get errors, then you are missing some more dependencies.

Additionally, you should always try to find your needed libraries from Maven when possible. (Use the Gradle tab to see the needed dependency to include)

And, at least for one of those dependencies, you can use the JitPack instructions.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Okay, thanks for explaining that! Should I make a libs folder in the same folder where my java class is? – Cora Coleman Jul 12 '16 at 01:34
  • See here. https://stackoverflow.com/questions/16608135/android-studio-add-jar-as-library – OneCricketeer Jul 12 '16 at 01:40
  • Okay, I added a folder "libs" with the .jar files within the app folder but my code still couldn't couldn't resolve the variables and such. Then I tried adding the "libs" folder with my .jar files on the same level as the app folder but that didn't work either. – Cora Coleman Jul 12 '16 at 01:41
  • Not resolving variables or classes&imports? There is a difference. – OneCricketeer Jul 12 '16 at 01:57
  • I followed that to the T and though everything resolved in my java class, when I ran the java class I got all of the same errors that came before: that the packages and variables etc. do not exist. – Cora Coleman Jul 12 '16 at 02:00
  • Everything in my java class is resolved (all of the symbols/packages used from those .jar files has been correctly instantiated without error). But when I run my test, I get errors that Gradle "cannot find symbol..." or package etc. even though my packages have now been imported in the java class without a problem. – Cora Coleman Jul 12 '16 at 02:10
  • That's a Java error. http://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean – OneCricketeer Jul 12 '16 at 05:31
  • 1
    That turned out to be it! Thank you so much for pointing me to that answer. I had named my java class the same as a class from one of the .jar files I was trying to set up as a library. Now that I changed it and made sure my dependencies were all aligned according to the previous answer you shared, my test is running without those dependency errors! Thank you again for this answer! – Cora Coleman Jul 12 '16 at 16:15