Skip to content Skip to sidebar Skip to footer

In Android Studio Refer To .apk Classes From Other Module

This question stems from the fact that I am not a Gradle expert and I come from Eclipse + Maven background. In Maven, I was able to refer to my apk project from another one (a Robo

Solution 1:

The solution in my edits actually works well. I report it as solution here. Watch out, it hard-codes the path for the class files, I wasn't able to find out how to use the $buildType in it (is there a way?)

def variantName = "debug"// init to debug

apply plugin: 'android'

android {
    ...
    applicationVariants.all { variant ->
        variantName = variant.name
        buildDebugJar.dependsOn variant.packageApplication
    }
}

// Builds the jar containing compiled .java files only (no resources).
task buildJar(type: Jar) {
    description 'Generates the jar file along with the apk.'fromnewFile("$project.buildDir/classes/$variantName")
}

configurations {
    jarOfApk
    transitive = false
}

artifacts {
    jarOfApk buildJar
}

And the referring module(s), will declare a new dependency this way:

compileproject(path: ':app', configuration: 'jarOfApk')

Post a Comment for "In Android Studio Refer To .apk Classes From Other Module"