spierce7
spierce7

Reputation: 15766

Using Android Project Files in Separate Java Module?

I have an Android project that uses ORMLite to access a database. For ORMLite I use POJO's to define the database schema.

I also have a Java project that I run to create a sqlite database that is used in the Android project. It'd be nice if the Java project could reference the same ORMLite POJOs in the Android project instead of having to copy them over. This would eliminate the possibility that the copy could get out of sync.

I'm using Gradle and Android Studio. I seem to be having some difficulty getting the android projects source files on the java projects class path. What am I doing wrong?

apply plugin: 'java'

task(createDB, dependsOn: 'classes', type: JavaExec) {
    main = 'com.example.java.Main'
    classpath = sourceSets.main.runtimeClasspath
}

dependencies {
    compile project(':AndroidProject')

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

    compile "com.j256.ormlite:ormlite-jdbc:${ORMLITE_VERSION}"   
    compile 'org.jsoup:jsoup:1.7.3'
    compile 'org.apache.commons:commons-io:1.3.2'
}

Upvotes: 0

Views: 185

Answers (1)

Xavier Ducrohet
Xavier Ducrohet

Reputation: 28549

The best way to do this really is to create another small project with only these POJOs and have it be a dependency of both the Android project and your other Java project.

Upvotes: 2

Related Questions