1

The reason I need this is because I'm trying to work around what I'm told is a bug with Xamarin not always closing streams and thus not writing to some content providers. The technique is to create a jar and then run a script to C#ifiy it and export it to a dll. That's why I need a jar.

I initially tried this by creating a Java Library but that didn't work because I need access to various android packages (for example, android.Net). So while I did manage to create a jar for a Java Library following these instructions (Abhinav Tyagi's answer) I can't seem to get it to work for an Android Library. For an Android Library it says it ran the Create Jar script but I don't see it.

To be clear, this is what I would like to turn into a jar:

enter image description here enter image description here

user875234
  • 2,399
  • 7
  • 31
  • 49

1 Answers1

0

Export jar file using Android Studio

Check out the library source code from the repository.

Import checkout library in your android studio.

Modify your build.gradle

If your current module is a library project then you need to properly recognize ‘android-library’ plugin as mention below.

apply plugin: 'com.android.library'
android {
    compileSdkVersion 'Google Inc.:Google APIs:16'
    buildToolsVersion "23.0.0"
    defaultConfig {
        minSdkVersion 13
        targetSdkVersion 23
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile 'com.android.support:support-v13:23.0.0'
}
task makeJar(type: Copy) {
    from('build/intermediates/bundles/release/')
    into('build/outputs/')
    include('classes.jar')
    rename ('classes.jar', 'myLib.jar')
    into('release/') //you can change this directory where you want to copy your .jar
}
task clearJar(type: Delete) {
    delete 'build/libs/myLib.jar'
}



apply plugin: 'com.android.library'
android {
    compileSdkVersion 'Google Inc.:Google APIs:16'
    buildToolsVersion "23.0.0"
    defaultConfig {
        minSdkVersion 13
        targetSdkVersion 23
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile 'com.android.support:support-v13:23.0.0'
}
task makeJar(type: Copy) {
    from('build/intermediates/bundles/release/')
    into('build/outputs/')
    include('classes.jar')
    rename ('classes.jar', 'myLib.jar')
    into('release/') //you can change this directory where you want to copy your .jar
}
task clearJar(type: Delete) {
    delete 'build/libs/myLib.jar'
}

Run gradlew to make jar. For generating .jar, follow below steps,

Open the terminal.

Move to your project root directory.

Call makejar function which you have added in build.gradle

Example :-> D:\Users\MyWorkspace\project > gradlew makejar

After following all above steps you will find “myLib.jar” under release folder.