javaandroidopenimaj

Android Studio and openimaj


I am currently trying to build an android studio project using a dependency from the openimaj Java library.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.mapinguari.myapplication"
        minSdkVersion 15
        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.2.0'
    compile 'org.openimaj:openimaj:1.3.1'
}

Is my module build file. It reports no errors when syncing to the IDE.

However when I try to construct any of the classes in one of the source files the Android Studio does not recognize any of the classes from the openimaj dependency.

Any Help much appreciated.

Thank you!


Solution

  • I think it might be because you've specified a non-jar OpenIMAJ dependency (specifically you've told it to link against the OpenIMAJ master pom file, which only contains references to the different sub-modules). You probably need to actually choose the specific modules that you want - for example if your application is doing image processing, then add the dependency org.openimaj:image-processing:1.3.1.

    Edit: It seems that the batik svg libraries have a circular dependency somewhere that breaks Gradle (see https://issues.apache.org/jira/browse/BATIK-1098). This is what causes an eventual StackOverflowError. Additionally, something is pulling in xml-apis which will conflict with Android. Assuming you don't mind not have SVG image support, then the following should work:

    repositories {
        mavenCentral()
        maven {
            url "http://maven.openimaj.org"
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:18.+'
        compile('org.openimaj:image-processing:1.3.1') {
            exclude group: 'org.apache.xmlgraphics'
            exclude group: 'xml-apis'
        }
    }
    

    You might also want to add additional exclusions for dependencies that are not needed in your app - it seems that just including org.openimaj:image-processing pulls in lots of things that are almost certainly not going to be needed (I've created an issue for that here: https://github.com/openimaj/openimaj/issues/97).