Bob Woodley
Bob Woodley

Reputation: 1284

include jar in apk, android studio

I'm trying something very simple that is well documented, but I can't get it to work.

I am using AndroidStudio 0.6.0 with build tools version 19.1.0. Running on OSX.

  1. I create an new project with a blank activity. Lets call it MyApp.

  2. I put a jar file in MyApp/app/libs.

  3. I right-click on the jar and select 'Add As Library'.

  4. I run 'gradlew clean' and 'gradlew assemble'.

At this point, I expect the jar to be in the apk file but it is not. My gradle dependencies section looks like this:

apply plugin: 'android'

android {
compileSdkVersion 19
buildToolsVersion "19.1.0"

defaultConfig {
    applicationId "com.bob.myapplication6.app"
    minSdkVersion 9
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
    runProguard false
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile files('libs/openCVLibrary249.jar')
}

I tried adding the apk dependency, i.e.:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile files('libs/openCVLibrary249.jar')
    apk files('libs/openCVLibrary249.jar')
}

But still no jar in the apk file. What do I have to do to get the jar in the apk file?

Thank you.

Upvotes: 3

Views: 3927

Answers (1)

Bob Woodley
Bob Woodley

Reputation: 1284

After seeing this answer to a similar question I figured out what was going on: https://stackoverflow.com/a/16013512/2195930

The classes from the jar file are indeed included in the APK, but the jar itself is not. All the classes are present in a file called classes.dex. The dex2jar utility allows you to inspect its contents.

Upvotes: 4

Related Questions