how to create a jar file from android studio

前端 未结 5 1083

I have a fairly latest version of android studio, I have created a module under a project which is basically supposed to be a library, when I build it, it creates an \".aar\

相关标签:
5条回答
  • 2021-01-04 20:43

    I found a way to achieve this, plain simple, using Gradle 2.2.1:

    task jar(type: Jar, dependsOn: 'assembleRelease') {
        from fileTree(dir: 'build/intermediates/classes/release')
    }
    

    Place this in your library module. It will compile it as release and produce a JAR file in: build/libs.

    bash gradlew jar or use your IDE to target that jar Gradle task.

    0 讨论(0)
  • 2021-01-04 20:47

    aar is not related to AS or eclipse but is an AndroidARchive for Android applications like JavaARchives are for java applications. Because Android is java based, jars can be used. But to take android specialities into account, like resource bundles, an aar is the right thing to use.

    0 讨论(0)
  • 2021-01-04 20:47

    Add this in your library's gradle file:

    task deleteJar(type: Delete) {
        delete 'libs/traylib.jar'
    }
    
    task createJar(type: Copy) {
        from('build/intermediates/packaged-classes/release/')
        into('libs/')
        include('classes.jar')
        rename('classes.jar', 'traylib.jar')
    }
    
    createJar.dependsOn(deleteJar, build)
    

    You need to check path of your generated classes.jar: build/intermediates/packaged-classes/release/

    Create lib folder in your lib's root folder if it is not there

    Go to gradle build: Android Studio --> View --> Toll Windows --> Gradle

    Select your module(:library) --> Tasks --> other --> Double click on createJar task

    0 讨论(0)
  • 2021-01-04 20:50

    You can just simply unzip the aar file to get the separated pieces of files.

    0 讨论(0)
  • 2021-01-04 20:51

    Currently gradle based builds doesnt seems to be allowing to create jar with android studio, I decided to go for Intelij it has necessary option and does what i want , i can use community edition.

    ***Update**** Even the jar produced by Intelij with resources don't work , obviously its not easy to have a jar with resource , so decided to opt for .aar and hoping that Eclipse also gets support for .aar when gradle supports lands there, as that was my main concern.

    0 讨论(0)
提交回复
热议问题